double macurrent = iCustom(NULL, 0, "NonLagMA_v7.1",Price,Length,Displace, PctFilter, Color, ColorBarBack, Deviation, AlertMode, WarningMode, 0,Shift); double maprevious = iCustom(NULL, 0, "NonLagMA_v7.1",Price,Length,Displace, PctFilter, Color, ColorBarBack, Deviation, AlertMode, WarningMode, 0,Shift+1); double close_current = iClose (NULL,0,Shift); double close_previous = iClose (NULL,0,Shift+1);Those are not assignments; it's 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 server related functions in OnInit (or on load,) 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
@William Roeder
Thanks for the info. I see that it's basic logic I'm lacking.
I am also working to the same kind of EA. Have you got solution for that? If, will then you provide the code.
Thanks
Please I am coding an EA that buys and sell as the moving average crosses... I use the EA on different markets like (synthetic indices e.g Boom 500 and Crash 500) but when one position is opened in a market another one does not open ... I want it to run as ... It should open only one position for each market every time the crossing happens even if one position is opened in crash 500 .. It should still open for a crossing on boom 500... Please help me and share the code here
Kelvinprinz:
Do not double/triple post!
I have deleted your duplicated posts!
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I'm trying to test my EA with a MA line. If it crosses to the upside it's a buy and if it crosses to the downside it's a sell.
I'm testing if this works before going on by letting it comment buy or sell. It's not working so far.
When using strategy tester, it's only giving me the comment ERROR. Hope someone can help or push me in the right direction.