magicNumber
in your code??
;)
Hi,
I recently ran into a issue with MT5 where my EA does not seem to be setting the magic number or know that it opened a position.
There are a few obvious issues with the way you're attempting to use the CTrade class. I'd suggest you use the debugger to dig into the code and diagnose why this isn't working for you.
Well, where is the initialization of the variable
in your code??
;)
There are a few obvious issues with the way you're attempting to use the CTrade class. I'd suggest you use the debugger to dig into the code and diagnose why this isn't working for you.
Could you please tell me what are the obvious issues?
This was merely a code snippet
Could you please tell me what are the obvious issues?
cTrade.RequestMagic()
Returns the magic number assigned to a request. You haven't used CTrade to formulate a request and thus will not return a magic number.
int ticket = cTrade.RequestOrder(); // returns 0 even if trade is open
Again, this is for a formulated request. You are looking for CPositionInfo not CTrade for this.
So what you really need is:
bool can_trade() { CPositionInfo pi; return !pi.SelectByMagic(_Symbol, magicNumber); }
Returns the magic number assigned to a request. You haven't used CTrade to formulate a request and thus will not return a magic number.
Again, this is for a formulated request. You are looking for CPositionInfo not CTrade for this.
So what you really need is:
Interesting Topic, sorry to drag this up.
Clarification needed: Is this (code below) , a wrong way to initialize an EAs I.D ? I do know we must also set magic numbers, just before we submit a trade.
Is it okay to declare the Expert Magic Number OnInit(), I see no examples in the MQL5 documentation.
I have several instances (7) of the same name EA , on different chart Symbols and TimeFrames, all on 1 MT5 Terminal.
How does Each EA, know it is different to another, if we only set the Expert Magic Number a millisecond before we send the Buy Market order for example.
Should we (EA coders) declare the Experts I.D OnInit(), well before a trade has been submitted?
Or does MT5 know which EA instructions belong to which chart Symbol, TimeFrame from the same name EA? I hope I have made sense.
#include<Trade\Trade.mqh> CTrade cTrade; ulong magicNumber = 123456; void OnInit() { cTrade.SetExpertMagicNumber(magicNumber); }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- 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,
I recently ran into a issue with MT5 where my EA does not seem to be setting the magic number or know that it opened a position.