|
MA交差で矢印を出せるようになった構文です。
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
#property indicator_style1 STYLE_SOLID
#property indicator_style2 STYLE_SOLID
#property indicator_style3 SYMBOL_ARROWUP
#property indicator_style4 SYMBOL_ARROWDOWN
// カスタム指標に名前をつける
double Buf0[];
double Buf1[];
double CrossUp[];
double CrossDown[];
extern int MA1Period = 20;
extern int MA2Period = 62;
extern int UpArrow = 233;
extern int DnArrow = 234;
extern double ArrowDistance=1;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//---- indicators
// 指標バッファの割り当て
SetIndexBuffer(0, Buf0);
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID);
SetIndexBuffer(1, Buf1);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID);
SetIndexStyle(2, DRAW_ARROW, EMPTY);
SetIndexArrow(2, 233);
SetIndexBuffer(2, CrossUp);
SetIndexStyle(3, DRAW_ARROW, EMPTY);
SetIndexArrow(3, 234);
SetIndexBuffer(3, CrossDown);
//----表示ラベルに線名を設定
SetIndexLabel(0, "EMA62");
SetIndexLabel(1, "EMA144");
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int limit, i, counter;
double fasterMAnow, slowerMAnow, fasterMAprevious, slowerMAprevious, fasterMAafter, slowerMAafter;
double Range, AvgRange;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit = Bars-counted_bars;
// for(int i=limit-1; i>=0; i--)
for(i = 0; i <= limit; i++) {
counter=i;
Range=0;
AvgRange=0;
for (counter=i ;counter<=i+9;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/10;
fasterMAnow = iMA(NULL, 0, MA1Period, 0, MODE_EMA, PRICE_CLOSE, i);
fasterMAprevious = iMA(NULL, 0, MA1Period, 0, MODE_EMA, PRICE_CLOSE, i+1);
fasterMAafter = iMA(NULL, 0, MA1Period, 0, MODE_EMA, PRICE_CLOSE, i-1);
slowerMAnow = iMA(NULL, 0, MA2Period, 0, MODE_EMA, PRICE_CLOSE, i);
slowerMAprevious = iMA(NULL, 0, MA2Period, 0, MODE_EMA, PRICE_CLOSE, i+1);
slowerMAafter = iMA(NULL, 0, MA2Period, 0, MODE_EMA, PRICE_CLOSE, i-1);
if ((fasterMAnow > slowerMAnow) && (fasterMAprevious < slowerMAprevious) && (fasterMAafter > slowerMAafter)) {
CrossUp[i] = fasterMAnow - Range*ArrowDistance;
}
else if ((fasterMAnow < slowerMAnow) && (fasterMAprevious > slowerMAprevious) && (fasterMAafter < slowerMAafter)) {
CrossDown[i] = fasterMAnow + Range*ArrowDistance;
}
Buf0[i] = iMA(NULL, 0, MA1Period, 0, MODE_EMA, PRICE_CLOSE, i);
Buf1[i] = iMA(NULL, 0, MA2Period, 0, MODE_EMA, PRICE_CLOSE, i);
}
//----
return(0);
}
|
|