What does the error message say? As there's likely a typo on a line somewhere.
Other than that, the obvious issue (which it would compile either way) is the way you calculate lot size. You can, but it's highly recommended that you don't, use point * 10 as that's not going to work for all pairs. Ex: EUR/USD has 5 decimal points and USD/JPY has 3 which would screw up your calculations. The better way to do the calculation would be:
double CalculateLotSize() { if (StopLoss == 0) return 0.0; // avoid division by zero double risk = AccountBalance() * RiskPercent / 100.0; double slPoints = StopLoss * MarketInfo(Symbol(), MODE_POINT); double tickValue = MarketInfo(Symbol(), MODE_TICKVALUE); double lot = risk / (slPoints * tickValue / MarketInfo(Symbol(), MODE_TICKSIZE)); return MathMax(MarketInfo(Symbol(), MODE_MINLOT), MathMin(lot, MarketInfo(Symbol(), MODE_MAXLOT))); }
Compiling as you've given would, on quick glance (I didn't go line by line as you should have an error message indicating the line with a problem), work but it wouldn't work well.
-
Show the code, the error messages, and point to the specific lines.
- benedictwellstood: for some reason, my MT4 is not compiling.
Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. I have moved this thread. -
double slPoints = StopLoss * Point * 10;
There is no predefined variable Point in MT4 or MT5. Use the real variable or call the function.
-
if (OrderSelect(0, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber() == MagicNumber) {
No select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum (2013)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi - for some reason, my MT4 is not compiling. I'd be super grateful if someone could help compile this into an ex4.
Any help very gratefully received, thank you.
Love and Light