■超直感!MT4プログラミング講座■ 第22回 ボリンジャーバンドのおさらい

スポンサーリンク

こんばんは!キリンです。
お酒を飲んでからの講義は難しいですね。
何か対策を考えなければっ!
頑張って書いていきます。


第22回 ボリンジャーバンドのおさらい

今までで作成したボリンジャーバンドのプログラムを組み合わせると、
このようになります。

//+------------------------------------------------------------------+
//| KumikomiBB.mq4 |
//| Copyright (c) 2009, Toyolab FX |
//| http://forex.toyolab.com |
//+------------------------------------------------------------------+
#property copyright “Copyright (c) 2009, Toyolab FX”
#property link “http://forex.toyolab.com”
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 LightBlue
#property indicator_color2 Blue
#property indicator_color3 Blue
// 指標バッファ
double BufMain[];
double BufUpper[];
double BufLower[];
// 外部パラメータ
extern int BandsPeriod = 20;
extern int BandsDeviation = 2;
// 初期化関数
int init()
{
// 指標バッファの割り当て
SetIndexBuffer(0, BufMain);
SetIndexBuffer(1, BufUpper);
SetIndexBuffer(2, BufLower);
// 指標ラベルの設定
SetIndexLabel(0, “BB(“+BandsPeriod+”)”);
SetIndexLabel(1, “Upper(“+BandsDeviation+”)”);
SetIndexLabel(2, “Lower(“+BandsDeviation+”)”);
return(0);
}
// スタート関数
int start()
{
int limit = Bars-IndicatorCounted();
for(int i=limit-1; i>=0; i–)
{
BufMain[i] = iBands(NULL, 0, BandsPeriod, BandsDeviation, 0, PRICE_CLOSE, MODE_MAIN, i);
BufUpper[i] = iBands(NULL, 0, BandsPeriod, BandsDeviation, 0, PRICE_CLOSE, MODE_UPPER, i);
BufLower[i] = iBands(NULL, 0, BandsPeriod, BandsDeviation, 0, PRICE_CLOSE, MODE_LOWER, i);
}
return(0);
}

上記の中身をしっかりと理解していただければと思います。
19, 20 ,21回に説明を書いていますので、わからないところがあれば戻ってみてくださいね。
では、これと最初に作成したiMAと比較してみましょう。

//+------------------------------------------------------------------+
//| MA Kirin.mq4 |
//| Copyright Kirin 2010, Forex Trading Laboratory. |
//| http://ameblo.jp/ftlabo-kirin/ |
//+------------------------------------------------------------------+
#property copyright “Copyright Kirin 2010, MetaQuotes Software Corp.”
#property link “http://ameblo.jp/ftlabo-kirin/”
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_level1 0
// 指標バッファ
double Buf[];
// 外部パラメータ
extern int MAPeriod = 13;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//—- indicators
// 指標バッファの割り当て
SetIndexBuffer(0, Buf);
// 指標ラベルの設定
string label = “MA(“+MAPeriod+”)”;
IndicatorShortName(label);
SetIndexLabel(0, label);
//—-
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//—-
//—-
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//—-
int limit = Bars-IndicatorCounted();
for(int i=limit-1; i>=0; i–)
{
Buf[i] = iMA(NULL, 0, MAPeriod, 0, MODE_SMA, PRICE_CLOSE, i);
}
//—-
return(0);
}
//+------------------------------------------------------------------+

MA用のプログラムとボリンジャーバンド用のプログラムのどこが違うのでしょうか?
一番大事なところをリストアップします。
・表示するインディケーターの数
・ini()で設定するインディケーターバッファの数
・iMAとiBandsの扱い方
といったところですね。
今回は上記3つの理解を確認させていただきたいので、
3つは具体的にどこが違うのかを宿題しにしてみたいと思います。
よろしければご回答いただければとっ!
明日回答を載せますね。
最後までお読みいただきまして、ありがとうございます!

コメント

タイトルとURLをコピーしました