- help with my code i want it to run once per bar/candle but keeps placing multiple trades at the same time and i dont have a clue why? can anyone help me out
- Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6.
- Broken CLOSE ALL function
I don't know much about Mql4 EA writing... but I think this will be an issue due to the fact that volatility makes the price jump up and down and maybe that's why it's closing too soon
// Exit conditions for (int i = OrdersTotal() - 1; i >= 0; i--) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderType() == OP_BUY && Close[1] < MA_A_Current) CloseOrder(); if (OrderType() == OP_SELL && Close[1] > MA_A_Current) CloseOrder(); } }
maybe you have to add more to the exit condition, such as this:
// Exit conditions for (int i = OrdersTotal() - 1; i >= 0; i--) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderType() == OP_BUY && Close[1] < MA_A_Current && (current_price - open_price) > 50 * Point) CloseOrder(); if (OrderType() == OP_SELL && Close[1] > MA_A_Current && (open_price - current_price) > 50 * Point) CloseOrder(); } }
For buy positions the current price is desired to be above open price, for sell positions the current price is desired to be below open price, that's why I write it that way (you seek a positive number to indicate that the position is in profit)
Use bid or ask to get the current price and use this for obtaining the open price https://docs.mql4.com/trading/orderopenprice
- docs.mql4.com
Hi
Here the problem would not be probably connected with open/close function but with the logic of the EA (algorithm). You need to show us the code where the CloseAllOrders function is called or where those exit conditions are checked? There is probably some problem with update of MA_A_Current value and it gives you always “true” condition for closing trade. The problem is somewhere within the algorithm, not here.
Best regards
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use