Magic Number in EA

 

I need a clarification on the Magic Number in EA.  I have given the Magic Number in all my EA's as below

int Magic=MathRand();

I have parallelly running 4 EA's, whenever a trade is getting executed, each EA executes the trades with a different magic number.  As long as the EA's are not refreshed/not synchronized to the VPS, Individual EA's generate the same magic number for the particular chart trades.  

Assume, I have a open trade from the one EA from one chart, lets say its magic number is 12345.  Now when i change the properties of that particular EA and synchronized again to VPS, that EA was supposed to generate the magic number 12345 but it is generating a different magic number, lets say as 12346.

That EA is not reacting on the already executed open trades.  Should i not to use the MathRand() function, is there any advantages/disadvantages?

 
Magic Number is for identifying the specific EA. When you've other trades than your EA like manually opened trades or opened by another EA then you can identify your specific EA's trades with this magic number. If you are using MathRand() each time when initialize it'll generate a new random number and there is no chance it will match with your old magic number. Use different fixed magic numbers for different EAs. Your EA will never identify old trades after reinitialization. There is no point to use random numbers as magic number.
 
Mahadi Hasan Razu #:
Magic Number is for identifying the specific EA. When you've other trades than your EA like manually opened trades or opened by another EA then you can identify your specific EA's trades with this magic number. If you are using MathRand() each time when initialize it'll generate a new random number and there is no chance it will match with your old magic number. Use different fixed magic numbers for different EAs. Your EA will never identify old trades after reinitialization. There is no point to use random numbers as magic number.

Thank you, understood.

 
Sathish Justin: That EA is not reacting on the already executed open trades.  Should i not to use the MathRand() function, is there any advantages/disadvantages?
  1. Rand will generate the same number (sequence) for different EAs on separate charts. Thus defeating the purpose.

  2. EAs must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover?

    Use a OrderSelect / Position select loop on the first tick, or persistent storage (GV+flush or files) of ticket numbers required.

    Again, defeating the purpose.

Just set the number. I just use the date when I started the specific EA (20210901). Don't complicate things; KISS.

Reason: