I am new to MQL4 programming, and am trying to take lots of little steps to get acquainted with the syntax and different types of programs. I tried to program a simple moving average crossover indicator, but the lines drawn by the indicator do not have the same values for identical MA's created with the Moving Averages indicator that comes with MetaTrader 4. I am sure there is a simple solution for this, but any feedback is appreciated. Here is a copy of the code, preceded with a picture illustrating the issue. The arrow points to the custom indicator, which draws the blue and red moving averages. The lines above the blue and red are standard Moving Average indicators with a short EMA with P=50 and a long SMA with P=100:
Thanks for any help!
//+------------------------------------------------------------------+//| MAs.mq4 |//| Erik |//| |//+------------------------------------------------------------------+#property copyright "Erik"#property link ""#property indicator_chart_window#property indicator_buffers 2#property indicator_color1 Red#property indicator_color2 DarkBlue//---- input parametersexternint Short=50;externint Long=100;//---- buffersdouble ExtMapBuffer1[];double ExtMapBuffer2[];//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+int init(){//---- indicatorsSetIndexStyle(0,DRAW_LINE);SetIndexBuffer(0,ExtMapBuffer1);SetIndexStyle(1,DRAW_LINE);SetIndexBuffer(1,ExtMapBuffer2);IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));//----return(0);}//+------------------------------------------------------------------+//| Custom indicator deinitialization function |//+------------------------------------------------------------------+int deinit(){//----Alert("Indicator detached!");//----return(0);}//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+int start(){int counted_bars=IndicatorCounted();//----for(int i=0; i <Bars; i++){
ExtMapBuffer1[i]=iMA(Symbol(),0,Short,0,MODE_EMA,MODE_CLOSE, i);
ExtMapBuffer2[i]=iMA(Symbol(),0,Long,0,MODE_SMA,MODE_CLOSE,i);}//----return(0);}//+------------------------------------------------------------------+
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 new to MQL4 programming, and am trying to take lots of little steps to get acquainted with the syntax and different types of programs. I tried to program a simple moving average crossover indicator, but the lines drawn by the indicator do not have the same values for identical MA's created with the Moving Averages indicator that comes with MetaTrader 4. I am sure there is a simple solution for this, but any feedback is appreciated. Here is a copy of the code, preceded with a picture illustrating the issue. The arrow points to the custom indicator, which draws the blue and red moving averages. The lines above the blue and red are standard Moving Average indicators with a short EMA with P=50 and a long SMA with P=100:
Thanks for any help!