When you post code please use the CODE button (Alt-S)!
Thank you.
there is no "OpenOrder" function, and you are missing semicolon & closing braces on this part to close the else if:
else if (shortCond) { if (PositionsTotal() == 0 || (PositionSelect(Symbol()) && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)) { CloseAllPositions(); double sl = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, 5, 2)); double tp = closePrice - (sl - closePrice); // Example TP, you can set your own logic double lotSize = CalculateLotSize(closePrice, sl); if (lotSize > 0.01) { OpenOrder(ORDER_TYPE_SELL, lotSize, closePrice, sl, tp); SendNotification("Sell position opened for XAUUSD") }
Do never ever ever ever use multiple statements on a single line. Even though the language allows it, it makes more difficult to debug your code.
This is bad:
else if (shortCond) { if (PositionsTotal() == 0 || (PositionSelect(Symbol()) && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)) { CloseAllPositions(); double sl = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, 5, 2)); double tp = closePrice - (sl - closePrice); // Example TP, you can set your own logic double lotSize = CalculateLotSize(closePrice, sl); if (lotSize > 0.01) { OpenOrder(ORDER_TYPE_SELL, lotSize, closePrice, sl, tp); SendNotification("Sell position opened for XAUUSD") } // → THIS IS A BAD PRACTICE, you're missing a semicolon and a brace here
This is good:
else if (shortCond) { if (PositionsTotal() == 0 || (PositionSelect(Symbol()) && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)) { CloseAllPositions(); double sl = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, 5, 2)); double tp = closePrice - (sl - closePrice); // Example TP, you can set your own logic double lotSize = CalculateLotSize(closePrice, sl); if (lotSize > 0.01) { OpenOrder(ORDER_TYPE_SELL, lotSize, closePrice, sl, tp); SendNotification("Sell position opened for XAUUSD"); // fixed a semicolon missing here } // now you see there's a brace missing here aswell }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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 have ben trying to fix the issue for some hours and it is not yielding, please help