MT5で使えるマルチタイムフレームボリンジャーバンドを作りました!
先日マルチタイムフレームRSIを紹介しました。 マルチタイムフレーム対応のインジケーターの基本部分は同じですので、仕組みについてはRSIのほうを見ていただけたらと思います。
ここではソースコードだけ公開します。
ソースコード
#property copyright "© shanch, 2020"
#property link "shanch2@gmail.com"
#property description "MTFBB"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_plots 7
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_type3 DRAW_LINE
#property indicator_type4 DRAW_LINE
#property indicator_type5 DRAW_LINE
#property indicator_type6 DRAW_LINE
#property indicator_type7 DRAW_LINE
#property indicator_color1 clrViolet
#property indicator_color2 clrViolet
#property indicator_color3 clrViolet
#property indicator_color4 clrViolet
#property indicator_color5 clrViolet
#property indicator_color6 clrViolet
#property indicator_color7 clrViolet
#property indicator_width1 3
#property indicator_width2 1
#property indicator_width3 2
#property indicator_width4 3
#property indicator_width5 1
#property indicator_width6 2
#property indicator_width7 3
#property indicator_style2 STYLE_DOT
#property indicator_style5 STYLE_DOT
input ENUM_TIMEFRAMES TimeFrame = PERIOD_H1;
input int Period = 20;
int hBB1;
int hBB2;
int hBB3;
double Buf[];
double BufH1[];
double BufH2[];
double BufH3[];
double BufL1[];
double BufL2[];
double BufL3[];
double BufTemp[];
int OnInit()
{
SetIndexBuffer(0, Buf, INDICATOR_DATA);
SetIndexBuffer(1, BufH1, INDICATOR_DATA);
SetIndexBuffer(2, BufH2, INDICATOR_DATA);
SetIndexBuffer(3, BufH3, INDICATOR_DATA);
SetIndexBuffer(4, BufL1, INDICATOR_DATA);
SetIndexBuffer(5, BufL2, INDICATOR_DATA);
SetIndexBuffer(6, BufL3, INDICATOR_DATA);
ArraySetAsSeries(Buf, true);
ArraySetAsSeries(BufH1, true);
ArraySetAsSeries(BufH2, true);
ArraySetAsSeries(BufH3, true);
ArraySetAsSeries(BufL1, true);
ArraySetAsSeries(BufL2, true);
ArraySetAsSeries(BufL3, true);
hBB1 = iBands(NULL, TimeFrame,Period, 0, 1, PRICE_CLOSE);
hBB2 = iBands(NULL, TimeFrame,Period, 0, 2, PRICE_CLOSE);
hBB3 = iBands(NULL, TimeFrame,Period, 0, 3, PRICE_CLOSE);
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
IndicatorRelease(hBB1);
IndicatorRelease(hBB2);
IndicatorRelease(hBB3);
}
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
ArraySetAsSeries(time,true);
int limit = rates_total - prev_calculated;
if(limit == 0) limit= 1;
int s = 0;
for(int i=0; i<limit; i++)
{
s=iBarShift(_Symbol,TimeFrame,time[i]);
if(CopyBuffer(hBB1, 0, s, 1, BufTemp) <= 0)
{
Print("Getting iBand failed! Error",GetLastError());
return(0);
}
else
{
Buf[i]=BufTemp[0];
}
if(CopyBuffer(hBB1, 1, s, 1, BufTemp) <= 0)
{
Print("Getting iBand failed! Error",GetLastError());
return(0);
}
else
{
BufH1[i]=BufTemp[0];
}
if(CopyBuffer(hBB1, 2, s, 1, BufTemp) <= 0)
{
Print("Getting iBand failed! Error",GetLastError());
return(0);
}
else
{
BufL1[i]=BufTemp[0];
}
if(CopyBuffer(hBB2, 1, s, 1, BufTemp) <= 0)
{
Print("Getting iBand failed! Error",GetLastError());
return(0);
}
else
{
BufH2[i]=BufTemp[0];
}
if(CopyBuffer(hBB2, 2, s, 1, BufTemp) <= 0)
{
Print("Getting iBand failed! Error",GetLastError());
return(0);
}
else
{
BufL2[i]=BufTemp[0];
}
if(CopyBuffer(hBB3, 1, s, 1, BufTemp) <= 0)
{
Print("Getting iBand failed! Error",GetLastError());
return(0);
}
else
{
BufH3[i]=BufTemp[0];
}
if(CopyBuffer(hBB3, 2, s, 1, BufTemp) <= 0)
{
Print("Getting iBand failed! Error",GetLastError());
return(0);
}
else
{
BufL3[i]=BufTemp[0];
}
}
for(int i=1; i<rates_total; i++)
{
if(iBarShift(NULL, TimeFrame, time[i]) > 0) break;
Buf[i]=Buf[0];
BufH1[i]=BufH1[0];
BufH2[i]=BufH2[0];
BufH3[i]=BufH3[0];
BufL1[i]=BufL1[0];
BufL2[i]=BufL2[0];
BufL3[i]=BufL3[0];
}
return(rates_total);
}