double HighOfLast4Bars = iHigh(Symbol(), 0, iHighest(Symbol(), NULL, MODE_HIGH, 3, 0)); double LowOfLast4Bars = iLow(Symbol(), 0, iLowest(Symbol(), NULL, MODE_LOW, 3, 0)); double HighOfLast2Bars = iHigh(Symbol(), 0, iHighest(Symbol(), NULL, MODE_HIGH, 2, 0)); double LowOfLast2Bars = iLow(Symbol(), 0, iLowest(Symbol(), NULL, MODE_LOW, 2, 0)); double NewVolumeHigh= iVolume(Symbol(), 0, iHighest(Symbol(), NULL, MODE_VOLUME, 2, 0)); double NewHigh=Ask>HighOfLast4Bars; double CloseLong=Ask> LowOfLast2Bars; double NewLow=Bid< LowOfLast4Bars; double CloseShort=Bid< HighOfLast2Bars;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.
external static variable - Inflation - MQL4 programming forum
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 tying to make an EA with simple rules:
on H1
Buy Long if Ask>HighOfLast4Bars + Volume[0]>NewVolumeHigh
Close Long if Ask<Low[1]
Sell Short if Bid< LowOfLast4Bars + Volume[0]>NewVolumeHigh
CLose Short if Bid > High[1]
Here's what I've got, no errors in the code but no action either...