or copy Trade.mqh and re-name it e.g. JustinTrade.mqh (otherwise the next build will probably overwrite all your changes) and amend the methods that create the orders so that you have to hand over even the Magic number.
Either call the method trade.SetExpertMagicNumber(Magic); with the Magic no. you want again in OnTick()
or copy Trade.mqh and re-name it e.g. JustinTrade.mqh (otherwise the next build will probably overwrite all your changes) and amend the methods that create the orders so that you have to hand over even the Magic number.
Thanks, but if i call again as per this, will that apply the magic number to only buy limit or sell limit orders only " all the method trade.SetExpertMagicNumber(Magic); with the Magic no. you want again in OnTick()"
Sathish Justin:
In my EA, i have set the magic number in initialization function as: trade.SetExpertMagicNumber(Magic)
Now in the same EA, I want to give another one magic number for Buy Limit & Sell Limit orders as "Magic1" How to do that?
-
Ctrade trade; Ctrade trade1; ⋮ trade.SetExpertMagicNumber(Magic); trade1.SetExpertMagicNumber(Magic1);
-
Why do you need a second MN? Are you doing something different when it opens?
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.
You can't use both!
- Make a copy,
- load your copy: #include "Trade\ JustinTrade .mqh" (or where ever it is located),
- start amending carefully and stepwise your copy and compile after each step.
- Then run your EA in the debugger and control the behaviour in the debugger:
https://www.metatrader5.com/en/metaeditor/help/development/debug // Code debugging
https://www.mql5.com/en/articles/2041 // Error Handling and Logging in MQL5
https://www.mql5.com/en/articles/272 // Tracing, Debugging and Structural Analysis of Source Code
https://www.mql5.com/en/articles/35 // scrol down to: "Launching and Debuggin"

- www.metatrader5.com

- 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,
In my EA, i have set the magic number in initialization function as below
trade.SetExpertMagicNumber(Magic);
This magic number will be used for the Buy & Sell trades
Now in the same EA, I want to give another one magic number for Buy Limit & Sell Limit orders as "Magic1"
How to do that? Someone help plz