First, you set Trade to a random magic number. int MagicNumber; ⋮ trade.SetExpertMagicNumber(MagicNumber);
Then in trailing, you use a different selection filter. MagicNumber=(StringGetCharacter(Symbol(),0)*1 +StringGetCharacter(Symbol(),2)*3 +StringGetCharacter(Symbol(),4)*5 +StringGetCharacter(Symbol(),6)*7 +StringGetCharacter(Symbol(),8)*9 +StringGetCharacter(Symbol(),10)*11 +StringGetCharacter(Symbol(),12)*13 +StringGetCharacter(Symbol(),14)*15 +StringGetCharacter(Symbol(),16)*17); ⋮ if(m_position.Symbol()==Symbol()&&m_position.Magic()==MagicNumber)
-
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 2011You need one Magic Number for each symbol/timeframe/strategy. Trade current timeframe, one strategy, and filter by symbol requires one MN.
First, you set Trade to a random magic number. Then in trailing, you use a different selection filter. -
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 2011You need one Magic Number for each symbol/timeframe/strategy. Trade current timeframe, one strategy, and filter by symbol requires one MN.
Thank you William it works perfectly now
Just re-order the statements:
MagicNumber=(StringGetCharacter(Symbol(),0)*1 +StringGetCharacter(Symbol(),2)*3 +StringGetCharacter(Symbol(),4)*5 +StringGetCharacter(Symbol(),6)*7 +StringGetCharacter(Symbol(),8)*9 +StringGetCharacter(Symbol(),10)*11 +StringGetCharacter(Symbol(),12)*13 +StringGetCharacter(Symbol(),14)*15 +StringGetCharacter(Symbol(),16)*17); Print(MagicNumber); trade.SetExpertMagicNumber(MagicNumber); trade.SetMarginMode(); trade.SetTypeFillingBySymbol(m_symbol.Name());

- 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 all, I'm having a problem as to why StringGetCharacter is preventing my ea from trailing.
When I disable the functions:
My ea will trailing again. I would like to add StringGetCharacter functions above & my ea to trail.
Please help with the following.