I am trying my 1st indicator and would appreciate some help from seasoned MQL coders.
The script below is derived form the sample MACD script and modified to place an UP arrow when the MACD has crossed the zero line after 3 consecutive bars above the zero line and likewise a DOWN arrow if the MACD crosses below the zero line with 3 consecutive bars below zero.
I am having problems - not getting any arrows showing up at all.
If you can see where I am going astray, this would be a great help.
Thanks
#property copyright "Copyright 2007, Systrader"
#property link "http://www...."
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Red
#property indicator_width1 2
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double Macd[];
double Signal[];
//---- counter
int counter;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_LINE);
SetIndexArrow(2,233);
SetIndexArrow(3,234);
SetIndexDrawBegin(1,SignalSMA);
IndicatorDigits(Digits+1);
//---- indicator buffers mapping
SetIndexBuffer(0,Macd);
SetIndexBuffer(1,Signal);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACDZC("+FastEMA+","+SlowEMA+","+SignalSMA+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
Macd[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
for(i=0; i<limit; i++)
Signal[i]=iMAOnArray(Macd,Bars,SignalSMA,0,MODE_SMA,i);
//---- Count if 3-bars of macd are above or below zero
counter=0;
// start at 3rd bar to allow checking of the 3 bars previous
for(int j=3; j<limit; j++)
{
if (Macd[j] < 0) counter--;
if (Macd[j] > 0) counter++;
}
// count if 3 bars have been seen above zero line
if (counter > 2) {
SetIndexStyle(2,DRAW_ARROW);
ObjectCreate("UpAlert", OBJ_ARROW, 0, High[j],0);
ObjectSet("UpAlert", OBJPROP_ARROWCODE, 74);
}
// count if 3 bars have been seen below zero line
if (counter < -2)
{
SetIndexStyle(3,DRAW_ARROW);
ObjectCreate("DnAlert", OBJ_ARROW, 0, Low[j],0);
ObjectSet("DnAlert", OBJPROP_ARROWCODE, 74);
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
The script below is derived form the sample MACD script and modified to place an UP arrow when the MACD has crossed the zero line after 3 consecutive bars above the zero line and likewise a DOWN arrow if the MACD crosses below the zero line with 3 consecutive bars below zero.
I am having problems - not getting any arrows showing up at all.
If you can see where I am going astray, this would be a great help.
Thanks
#property copyright "Copyright 2007, Systrader"
#property link "http://www...."
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Red
#property indicator_width1 2
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double Macd[];
double Signal[];
//---- counter
int counter;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_LINE);
SetIndexArrow(2,233);
SetIndexArrow(3,234);
SetIndexDrawBegin(1,SignalSMA);
IndicatorDigits(Digits+1);
//---- indicator buffers mapping
SetIndexBuffer(0,Macd);
SetIndexBuffer(1,Signal);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACDZC("+FastEMA+","+SlowEMA+","+SignalSMA+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
Macd[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
for(i=0; i<limit; i++)
Signal[i]=iMAOnArray(Macd,Bars,SignalSMA,0,MODE_SMA,i);
//---- Count if 3-bars of macd are above or below zero
counter=0;
// start at 3rd bar to allow checking of the 3 bars previous
for(int j=3; j<limit; j++)
{
if (Macd[j] < 0) counter--;
if (Macd[j] > 0) counter++;
}
// count if 3 bars have been seen above zero line
if (counter > 2) {
SetIndexStyle(2,DRAW_ARROW);
ObjectCreate("UpAlert", OBJ_ARROW, 0, High[j],0);
ObjectSet("UpAlert", OBJPROP_ARROWCODE, 74);
}
// count if 3 bars have been seen below zero line
if (counter < -2)
{
SetIndexStyle(3,DRAW_ARROW);
ObjectCreate("DnAlert", OBJ_ARROW, 0, Low[j],0);
ObjectSet("DnAlert", OBJPROP_ARROWCODE, 74);
}
//---- done
return(0);
}
//+------------------------------------------------------------------+