- Opening and Closing Positions - Trade - MetaTrader 5 for iPhone
- Opening and Closing Positions - Trade - MetaTrader 5 for Android
- Exchange Execution - Opening and Closing Positions - Trade - MetaTrader 5 for Android
You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
No free help (2017)
Or pay someone. Top of every page is the link Freelance.
Hiring to write script - General - MQL5 programming forum (2018)
We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
No free help (2017)
William thanks,
I never use this forum so I didn't know the rules. This is what I tried to do, but it doesn't do what I intended.
// Funzione per cancellare tutti gli ordini pendenti void CancelPendingOrders() { for (int i = OrdersTotal() - 1; i >= 0; i--) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT) { OrderDelete(OrderTicket()); } } } } // Funzione OnTick void OnTick() { // Verifica se non ci sono altri trade normali aperti if (!AreThereOpenNormalTrades()) { double openPrice = Ask; // Prezzo Ask come prezzo di apertura // Apri il trade normale OpenNormalTrade(openPrice); // Apri il trade buy limit OpenBuyLimitTrade(openPrice); } // Verifica se un trade ha chiuso per TP e cancella tutti gli ordini pendenti for (int i = OrdersTotal() - 1; i >= 0; i--) { if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) { if (OrderType() == OP_BUY || OrderType() == OP_SELL) { if (OrderClosePrice() != 0.0) { CancelPendingOrders(); break; } } } } }
- On a buy/sell, OrderClosePrice() is always non-zero (just Bid/Ask).
- Why are you deleting pending orders, when you have any open order? That isn't what you originally wanted.
-
Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number/symbol filtering on your OrderSelect / Position 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)
PositionClose is not working - MQL5 programming forum (2020)
MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles (2011)
Limit one open buy/sell position at a time - General - MQL5 programming forum (2022)You need one Magic Number for each symbol/timeframe/strategy.
Trade current timeframe, one strategy, and filter by symbol requires one MN.
If trading multiple timeframes, and filter by symbol requires use a range of MN (base plus timeframe).
Why are MT5 ENUM_TIMEFRAMES strange? - General - MQL5 programming forum - Page 2 #11 (2020)

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use