-
double a = 2 / (1 + InpFastEMA); double b = 1 - a; double c = 2 / (1 + InpSlowEMA); double d = 1 - c; double e = 2 / (1 + InpSignalEMA); double f = 1 - e;
Those are not assignments; they are initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.
-
They are initialized once on program load.
-
They don't update unless you assign to them.
-
In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and
Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
-
Unlike indicators, EAs are not reloaded on chart change, so you must reinitialize them, if necessary.
external static variable - MQL4 programming forum #2 (2013)
-
-
result=price[position]*pr+prev_value*(1-pr);
That form increases rounding errors. Simplify:
result=prev_value + (price[position]-prev_value)*pr;
-
#property indicator_buffers 5 #property indicator_plots 1 PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,(int)InpSignalEMA-1); //--- indicator buffers mapping SetIndexBuffer(2,ExtSignalBuffer);
You have one plot and five budffers. Their indexes are zero onwards.
-
Those are not assignments; they are initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.
-
They are initialized once on program load.
-
They don't update unless you assign to them.
-
In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and
Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
-
Unlike indicators, EAs are not reloaded on chart change, so you must reinitialize them, if necessary.
external static variable - MQL4 programming forum #2 (2013)
-
-
That form increases rounding errors. Simplify:
-
You have one plot and five budffers. Their indexes are zero onwards.
Thank you sir I might try to PM you after I make the suggested changes!

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am a novice programmer. I have cobbled together a MACD predictor line using a custom EMA algorithm to handle floating points, but it is not calculating every tick. I am guessing it's because of my loop. I should see the MACDP buffer changing per the tick as it increases or decreases and when I load it, sometimes it seems like the line is way off depending on the timeline. Pls Help!