I am trying to write a very simple indicator to draw an arrow 20 points below the
low when a fast ma crosses above the slow ma and to draw an arrow 20 point above
the high when the fast ma crosses below the slow ma. The code seems to be doing
exactly opposite of what I want it to do. This seems to be a trivial issue but
has been trobling me for a while. Any help on this will be appreciated.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I am trying to write a very simple indicator to draw an arrow 20 points below the low when a fast ma crosses above the slow ma and to draw an arrow 20 point above the high when the fast ma crosses below the slow ma. The code seems to be doing exactly opposite of what I want it to do. This seems to be a trivial issue but has been trobling me for a while. Any help on this will be appreciated.
Here is the code I have written.
//+------------------------------------------------------------------+
//| Entry. mq4 |
//| Sanju Chand |
//| sanjuchand@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Sanju Chand"
#property link "sanjuchand@yahoo.com"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 SeaGreen
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexBuffer(0,ExtMapBuffer1);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
double min15ma14now, min15ma7now, min15ma14prev, min15ma7prev;
int cross;
int pos=Bars-counted_bars-1;
while(pos>=0)
{
min15ma14now=iMA(Symbol(),PERIOD_M15,14,0,MODE_EMA, PRICE_CLOSE, pos);
min15ma7now=iMA(Symbol(),PERIOD_M15,7,0,MODE_EMA, PRICE_CLOSE, pos);
min15ma14prev=iMA(Symbol(),PERIOD_M15,14,0,MODE_EMA, PRICE_CLOSE, pos-1);
min15ma7prev=iMA(Symbol(),PERIOD_M15,7,0,MODE_EMA, PRICE_CLOSE, pos-1);
cross=0;
if (min15ma7now>min15ma14now && min15ma7prev<min15ma14prev)cross=1;
if (min15ma7now<min15ma14now && min15ma7prev>min15ma14prev)cross=-1;
if (cross==1)ExtMapBuffer1[pos]=Low[pos]-20*Point;
if (cross==-1)ExtMapBuffer1[pos]=High[pos]+20*Point;
pos--;
}
return(0);
}
//+------------------------------------------------------------------+