Magicnumber loop?

 

I hope someone can elaborate or offer some help on this. I did try searching the forum for this topic. I use a Magicnumber for each EA I use, however, I don't have a piece of code that will automatically change the magicnumber once it has been used. I usually set up the EA daily so I manually change the number in the code, and then recompile it before adding it to my chart for trading.

extern int MagicNumber100=100000;
extern int MagicNumber101=100001;

How can I have the code automatically change the magicnumber after the EA places trades? Any help would be greatly appreciated! Thank you Forum!

Daniel

THE CODE BELOW IS HOW I REMOVE ORDERS ONCE TRADES ARE PLACED.

else
bool found = false;
for(int k=OrdersHistoryTotal()-1;k>=0;k--)
{
if((OrderSelect(k,SELECT_BY_POS,MODE_HISTORY))&&(OrderMagicNumber()==MagicNumber100))
{
found = true;
break;
}
}
if(found == true)
{
for(k=OrdersTotal()-1;k>=0;k--)
{
if((OrderSelect(k,SELECT_BY_POS,MODE_TRADES))&&(OrderMagicNumber()==MagicNumber101))
{
OrderDelete(OrderTicket());
}
}
}

 

I found this thread helpful.

https://www.mql5.com/en/forum/120034

 
forexman05:

I hope someone can elaborate or offer some help on this. I did try searching the forum for this topic. I use a Magicnumber for each EA I use, however, I don't have a piece of code that will automatically change the magicnumber once it has been used. I usually set up the EA daily so I manually change the number in the code, and then recompile it before adding it to my chart for trading.

extern int MagicNumber100=100000;
extern int MagicNumber101=100001;

How can I have the code automatically change the magicnumber after the EA places trades? Any help would be greatly appreciated! Thank you Forum!

Personally I think the magic number is too important and I prefer to set it manually, however I don't understand why you u have a separate extern variable for each magic number u use. Why not just have one extern variable for magic number and change it when u attach the expert to the chart (via the properties)?

 
joetrader:

I found this thread helpful.

https://www.mql5.com/en/forum/120034

forexman, if u prefer the automatic method, then indeed that's an excellent thread joetrader mentioned. Lot's of ideas.

 
How about using magicNumber + day%1
 
WHRoeder:
How about using magicNumber + day%1

U mean time%1... (day%1 = 0 for all days). That is likely to give a unique magic, but it won't persist over MT4 restarts, which is what is discussed in the mentioned thread (https://www.mql5.com/en/forum/120034).

Reason: