Magic Number for different chart

 

Hi guys I need advice on what to do with the magic number of my EA. When I start my EA I manually input the magic number that my EA will use, and when I use my EA to a different chart and input the magic number I add +1 to the magic number used on the first chart so the magic number that will be used in the second chart is different from the first on. I want to add codes on my EA that will get the magic number used from the previous chart then add +1 then the answer is will be used on the current chart.

i used this code. But the answer it gives is the magic number that is used where the EA is attach.


for(int i=0; i<OrdersTotal();i++)
{
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
      {
       if(OrderSymbol() == Symbol())
        {     
    
          if(OrderType() == OP_SELL || OrderType() == OP_BUY )
            LastMagicNumberUsed = OrderMagicNumber();               
        }
      }
}
 
mark692:

Hi guys I need advice on what to do with the magic number of my EA. When I start my EA I manually input the magic number that my EA will use, and when I use my EA to a different chart and input the magic number I add +1 to the magic number used on the first chart so the magic number that will be used in the second chart is different from the first on. I want to add codes on my EA that will get the magic number used from the previous chart then add +1 then the answer is will be used on the current chart.

i used this code. But the answer it gives is the magic number that is used where the EA is attach.


//+------------------------------------------------------------------+
//|                                                          xdt.mq4 |
//|                                 Copyright 2019, Haskaya Software |
//|                                   https://www.haskayayazilim.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, Haskaya Software"
#property link      "https://www.haskayayazilim.net"
#property version   "1.00"
#property strict

#include <Arrays\ArrayInt.mqh>
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

class IntegerSet : public CArrayInt
{
   public: bool Add(const int element){
      if(this.SearchLinear(element) < 0)
         return CArrayInt::Add(element);
      return false;
   }
};


int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   MagicNumberBulveGel();
  }
//+------------------------------------------------------------------+

void MagicNumberBulveGel()
  {
   IntegerSet MagicNumberlar;
   // Market Orders
   int total = OrdersTotal();
   for(int ix=total-1; ix>=0; ix--)
     {
      if(OrderSelect(ix,SELECT_BY_POS,MODE_TRADES)==false)
         break;
          if (OrderSymbol() == Symbol()) // Sembol your code
        {     
         MagicNumberlar.Add(OrderMagicNumber());
        } 
     }
  int    LastMagicNumberUsed=MagicNumberlar.Max()+1;
  Print(" New Magic  ",string(LastMagicNumberUsed));
}
 
mark692: I want to add codes on my EA that will get the magic number used from the previous chart then add +1 then the answer is will be used on the current chart.
  1. Why?

    How To Ask Questions The Smart Way. (2004)
              The XY Problem

  2. 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.02.21)
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
              Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles 2011

    You need one Magic Number for each symbol/timeframe/strategy. Trade current timeframe, one strategy, and filter by symbol requires one MN.

 
William Roeder #:
  1. Why?

    How To Ask Questions The Smart Way. (2004)
              The XY Problem

  2. 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.02.21)
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
              Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles 2011

    You need one Magic Number for each symbol/timeframe/strategy. Trade current timeframe, one strategy, and filter by symbol requires one MN.

You mean sir i dont need different magic numbers from the first chart unless my 2nd chart/symbol is the same from the first chart?
 
William Roeder #:
  1. Why?

    How To Ask Questions The Smart Way. (2004)
              The XY Problem

  2. 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.02.21)
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
              Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles 2011

    You need one Magic Number for each symbol/timeframe/strategy. Trade current timeframe, one strategy, and filter by symbol requires one MN.

You mean sir i dont need different magic numbers from the first chart unless my 2nd chart/symbol is the same from the first chart?
 
You better code a magicnumber generator … which will will be unique for Any chart/timeframe/account you put…use chart symbol/ timeframe/ account number… time… plenty of options you can use for generating a unique number… 
 
Daniel Cioca #:
You better code a magicnumber generator … which will will be unique for Any chart/timeframe/account you put…use chart symbol/ timeframe/ account number… time… plenty of options you can use for generating a unique number… 
I think this is better than what im thinking. Thank you sir!