Magic Numbers and Strategy Tester

 

Hello, 

I have an EA with 100 different strategies, each set with a different magic number. I backtest this in MT4 and there are hundreds of trades created. However, I do not see the magic numbers anywhere on the strategy tester - people in the forum have suggested using the print function, but printing does nothing and also there is nothing created under journal or in the list of trades.

Conversely, on a live environment, the magic number is easily viewable. 

It makes no sense at all to make it either so difficult or not possible to see a magic number in strategy backtester - this is the entire point of testing a system to see which strategies and approaches are working. I am now focussing on a system and I need to see the trades and magic numbers linked to what has been created in the simulation. I dont think I should need to pay for a separate script for this - but can someone please help me to answer this question: 

=== > How do I see magic numbers in the backtest? 

If this is possible, can you please give me a really clear explanation of how to do it - I cant believe that there is no topic opened on this forum to ask this, but equally, its really no clear from the software how this works. 


Thank you !! 

 

You can only test one EA with one magic number at a time so what do you want exactly ? 

If you define int EXPERT_MAGIC = 1234; and you do a Print(EXPERT_MAGIC); then it should tell you 1234 or what is the magic number.

 
Marco vd Heijden:

You can only test one EA with one magic number at a time so what do you want exactly ? 

If you define int EXPERT_MAGIC = 1234; and you do a Print(EXPERT_MAGIC); then it should tell you 1234 or what is the magic number.

One EA can run multiple strategies with different magic numbers so it definately would be useful.
 
amfohr:
One EA can run multiple strategies with different magic numbers so it definitely would be useful.

No it would not be useful there are other ways to identify orders, ticket, comment, etc.

Normally its one EA with one magic number. 

So if you use more then one magic number in one EA then you are not using it as it was intended.

That is possible but it defies the purpose of identifying the Expert ID.

https://www.mql5.com/en/docs/standardlibrary/tradeclasses/cpositioninfo/cpositioninfomagic

Basically its non standard usage of a standard function and so there is no reason to try and answer the question as to why it can not be tested in the tester, because the tester assumes standard implementations of standard functions and not some deviation of a standard function.

Of course if you can implement the non standard usage of a function, then you can also implement a non standard solution to the problem and so this is not something the strategy tester needs to solve.
Documentation on MQL5: Standard Library / Trade Classes / CPositionInfo / Magic
Documentation on MQL5: Standard Library / Trade Classes / CPositionInfo / Magic
  • www.mql5.com
Magic - CPositionInfo - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Marco vd Heijden:

No it would not be useful there are other ways to identify orders, ticket, comment, etc.

Normally its one EA with one magic number. 

So if you use more then one magic number in one EA then you are not using it as it was intended.

That is possible but it defies the purpose of identifying the Expert ID.

https://www.mql5.com/en/docs/standardlibrary/tradeclasses/cpositioninfo/cpositioninfomagic

Basically its non standard usage of a standard function and so there is no reason to try and answer the question as to why it can not be tested in the tester, because the tester assumes standard implementations of standard functions and not some deviation of a standard function.

Of course if you can implement the non standard usage of a function, then you can also implement a non standard solution to the problem and so this is not something the strategy tester needs to solve.

I disagree!

It is absolutely no problem for one EA to assign several MagicNumbers to different positions (of course only one for each). I do that!. It can be requested and used in different strategies even in the Strategy Tester! The ONLY  problem is that the list of positions created by the tester after a single test does not include the MagicNumbers for a further analysis. I once suggested that as this would be a quite interesting enhancement and the realisation doesn't seam to be tooooooo difficult: adding just a column.

To make MQ think to change this just add this suggestion as a comment to the recent announcements of a new build of the terminal e.g. this one4: https://www.mql5.com/en/forum/352981.

The more do that the the sooner MQ might think about a change?

New MetaTrader 5 platform build 2650: Background chart loading and MQL5 code profiler improvements
New MetaTrader 5 platform build 2650: Background chart loading and MQL5 code profiler improvements
  • 2020.10.08
  • www.mql5.com
The MetaTrader 5 platform update will be released on Friday, October 9, 2020...
 

Yes, it is complete nonsense that one EA is limited to one magic number. This goes for both MT4 and 5.

Consider using this library https://www.mql5.com/ru/forum/211620 It allows for all kind of reports to be used from the Tester/Optimizer as well as generating real time reports from running EA. The sky is the limit.

Example all magics same EA

Example filtered by magic


Filter Code 

      REPORT_FILTER Filter;

      string FileName = MQLInfoString(MQL_PROGRAM_NAME);
      string s = ReportFilter[FilterSelector];
      
      switch (FilterSelector)
      {
        case 0:

          StringReplace(s,"-","_");
          FileName += "_" + s;
        break;
        case 1:
          Filter.Magic = inResultCode[SystemSelector];
          FileName += "_" + (string)inResultCode[SystemSelector];
        break;
        case 2:
          Filter.StartTime = SessionStart;
          FileName += "_" + TimeToString(SessionStart,TIME_DATE);
        break;
        case 3:
          Filter.Magic = inResultCode[SystemSelector];
          Filter.StartTime = SessionStart;
          FileName += "_" + (string)inResultCode[SystemSelector];
          FileName += "_" + TimeToString(SessionStart,TIME_DATE);
        break;        
      }

      REPORT::ToFile(FileName + ".htm", Filter);
 
Carl Schreiber:

I disagree!

It is absolutely no problem for one EA to assign several MagicNumbers to different positions (of course only one for each). I do that!. It can be requested and used in different strategies even in the Strategy Tester! The ONLY  problem is that the list of positions created by the tester after a single test does not include the MagicNumbers for a further analysis. I once suggested that as this would be a quite interesting enhancement and the realisation doesn't seam to be tooooooo difficult: adding just a column.

To make MQ think to change this just add this suggestion as a comment to the recent announcements of a new build of the terminal e.g. this one4: https://www.mql5.com/en/forum/352981.

The more do that the the sooner MQ might think about a change?

int  OrderMagicNumber();

The identifying (magic) number of the currently selected order.

long  Magic() const

ID of the Expert Advisor that opened the position.

 

Hey guys did anyone find a solution? I'm facing the same problem as my EA contains many different strategies and i need to expose magic number or comment in the report generated by the backtest. I read the code posted by  Enrique Dangeroux but i cannot figure out how to integrate it and have the backtest generated report include the missing magin number column.

Thanks