I want to set the Magic Number in my robots in Metatrader 5 (MQL5). In MQL4 was easy, on OrderSend() I just put the Magic number in order to identify what orders are from each expert advisors (I want to use several different robots, and each robot can only close the positions the same robot open, not other orders),
Please help, I understand a little MQL5 and have made some robots, but I'm not sure how to set the Magic Number.
Thank you!
- www.mql5.com
Thank you. I define the trade object as:
"CTrade trade"
And just after make the trade (for example trade.BUY(XXX)), I set the Magic Number like this:
trade.SetExpertMagicNumber(00001);
Is ok to set the magic this way? I don't have error when compiling but I'm not sure if the program is really doing this. Is there a way to know for sure if is set the magic number?
Since is not the same way as in MQL4, meaning I set the magic number after the trade was send and not while is set as in metatrader 4, I'm dubious if it's ok.
Thanks!
Thank you. I define the trade object as:
"CTrade trade"
And just after make the trade (for example trade.BUY(XXX)), I set the Magic Number like this:
trade.SetExpertMagicNumber(00001);
Is ok to set the magic this way? I don't have error when compiling but I'm not sure if the program is really doing this. Is there a way to know for sure if is set the magic number?
Since is not the same way as in MQL4, meaning I set the magic number after the trade was send and not while is set as in metatrader 4, I'm dubious if it's ok.
Thanks!
You must set the Magic Number BEFORE the trade...
It doesn't make sense doing it AFTER...
You must set the Magic Number BEFORE the trade...
It doesn't make sense doing it AFTER...
Minions Labs, So I just add the same code I have before the trade, like this (sell case)?
trade.SetExpertMagicNumber(00001);
trade.Sell (VOLUME_LOT,NULL,m_symbol.Bid(), (m_symbol.Bid()+STOPLOSS,(m_symbol.Bid()-TAKEPROFIT) ,NULL);
Thanks!
#define EXPERT_MAGIC 123456 // MagicNumber of the expert //+------------------------------------------------------------------+ //| Opening Sell position | //+------------------------------------------------------------------+ void OnStart() { //--- declare and initialize the trade request and result of trade request MqlTradeRequest request={0}; MqlTradeResult result={0}; //--- parameters of request request.action =TRADE_ACTION_DEAL; // type of trade operation request.symbol =Symbol(); // symbol request.volume =0.2; // volume of 0.2 lot request.type =ORDER_TYPE_SELL; // order type request.price =SymbolInfoDouble(Symbol(),SYMBOL_BID); // price for opening request.deviation=5; // allowed deviation from the price request.magic =EXPERT_MAGIC; // MagicNumber of the order //--- send the request if(!OrderSend(request,result)) PrintFormat("OrderSend error %d",GetLastError()); // if unable to send the request, output the error code //--- information about the operation PrintFormat("retcode=%u deal=%I64u order=%I64u",result.retcode,result.deal,result.order); } //+------------------------------------------------------------------+
Just read the documentation it's all there.
- www.mql5.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
I want to set the Magic Number in my robots in Metatrader 5 (MQL5). In MQL4 was easy, on OrderSend() I just put the Magic number in order to identify what orders are from each expert advisors (I want to use several different robots, and each robot can only close the positions the same robot open, not other orders),
Please help, I understand a little MQL5 and have made some robots, but I'm not sure how to set the Magic Number.
Thank you!