double gridstart = iLow(0,PERIOD_MN1,iLowest(0,PERIOD_MN1,MODE_LOW,WHOLE_ARRAY,0)); double gridend = iHigh(0,PERIOD_MN1,iHighest(0,PERIOD_MN1,MODE_LOW,WHOLE_ARRAY,0)); double traderange = (gridend-gridstart)/Point*10; int gridlines = round((gridend-gridstart)/Point*10)/GridStep;Global and static variables 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. Think
symbol/TF change.
external static variable - Inflation - MQL4 programming forum
And don't capitilize "let profit run" (as in your thread title,) as that is a commercial company and you'll confuse people.
Aladdin Abdulkareem:
Do not double post!
I have deleted your duplicate topic.
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
Hello Traders and Coders,
I'd like to share with you this EA which depends on Grid Trading strategy. It's very simple as the EA will open trades when price reaches any of the grid levels which is predefined by the trader with predefined step between each grid level.
The ea will cut the losses (by closing the loosing trades) and keep the winning trades open.
The attached EA is Buy Only, I'm beginner in coding and couldn't combine both Buy and Sell in one EA. If anyone can combine the Buy and Sell in one EA, and add to the code Close All Trades when AccountEquity() reaches above the AccountBalance() by some Profit Factor, I believe this EA will have very good and safe results.
Chirs,