コードをすぐに無くしちゃうのでブログに保存。
こいつをもう少しフィルタしてEAに組み込む。
//+------------------------------------------------------------------+
//| DevBandsSign.mq4 |
//| Copyright 2021, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
double BUY[];
double SEL[];
double MID_BUY[];
double MID_SEL[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0,BUY);
SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 2, RoyalBlue);
SetIndexBuffer(1,SEL);
SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 2, Crimson);
SetIndexBuffer(2,MID_BUY);
SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 2, RoyalBlue);
SetIndexBuffer(3,MID_SEL);
SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID, 2, Crimson);
SetIndexArrow(0 ,228);
SetIndexArrow(1 ,230);
SetIndexArrow(2 ,159);
SetIndexArrow(3 ,159);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
int limit = Bars - prev_calculated;
for(int i=0; i<limit-1; i++)
{
double u1 = iBands(NULL,0,20,1,0,PRICE_CLOSE,MODE_UPPER,i+1);
double m1 = iBands(NULL,0,20,1,0,PRICE_CLOSE,MODE_MAIN,i+1);
double l1 = iBands(NULL,0,20,1,0,PRICE_CLOSE,MODE_LOWER,i+1);
double u2 = iBands(NULL,0,20,1,0,PRICE_CLOSE,MODE_UPPER,i+2);
double m2 = iBands(NULL,0,20,1,0,PRICE_CLOSE,MODE_MAIN,i+2);
double l2 = iBands(NULL,0,20,1,0,PRICE_CLOSE,MODE_LOWER,i+2);
double macd = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i+1);
if(macd>0)
{
MID_BUY[i+1]=m1;
}
else if(macd<0)
{
MID_SEL[i+1]=m1;
}
if(Open[i+1]>u1
&& macd>0)
{
BUY[i+1]=u1;
}
else if(Open[i+1]<l1
&& macd<0)
{
SEL[i+1]=l1;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+