- gcmachado: . I have already studied how OrderSelect , OrderTicket , etc., work,
You have? Where is this OrderTicket in the MT5 documentation?
- gcmachado: I need certain ones to be canceled and others to be modified.
There is no need to create pending orders in code.
-
The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
Don't worry about it unless you're scalping M1 or trading news.
-
Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
Follow that and you have no orders, only positions.
-
If you use Trade library you can use the functions within and yes when you use Ctrade class to send trades it will change magic number for the whole class. So you would have to change magic number each time when you open a trade. You can try to make multiple class of Ctrade each with specific magic number for each type of trade you want to manage differently. Then you use one magic number for trades you want to cancel, and other magic number for trades you want to modify. For example declare those class at the start:
CTrade trade_to_cancel; CTrade trade_to_modify; int OnInit() { //--- trade_to_cancel = new CTrade(); trade_to_cancel.SetExpertMagicNumber(magicNo1); trade_to_modify = new CTrade(); trade_to_modify.SetExpertMagicNumber(magicNo2); return(INIT_SUCCEEDED); }
And then in the EA when you try to open trade to cancel use magicNo1 and trade_to_cancel class and for other trades use other class and other magic no etc.
Have a nice day👍📊
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good evening!
I am a beginner in MQL5 coding and am experiencing a significant problem when trying to identify my orders and positions, as well as making changes or cancellations to them. I have already studied how OrderSelect , OrderTicket , etc., work, but the problem still persists. I am using both the #include "Trade" and #include "OrderInfo" , but my main issue is being able to isolate each type of order and position to manipulate them separately.
Basically, my EA (Expert Advisor) opens different orders in various positions, both buy and sell. As some of these orders are being placed, I need certain ones to be canceled and others to be modified. When I tried to assign a "magic number," it becomes the magic number for the entire EA, so I am unable to individualize each order based on the price at which it is placed, the number of contracts, or any other type of identifier.
Could someone help me with how to do this? How can I "detect" each order separately?