Can EA detect if it's in Test Strategy?

 

Is there any way to know if the EA is running on Strategy Tester?

My EA uses the symbolInfo.MarginMaintenance() to make some equations to trade but these values are zero in strategy tester. To work around this problem, I created a parameter to set the margin (to use in strategy tester only) and I want to ignore this parameter when the EA runs on demo and real accounts.

Can someone help me to solve this problem?

 
Rafael Caetano Pinto:

Is there any way to know if the EA is running on Strategy Tester?

My EA uses the symbolInfo.MarginMaintenance() to make some equations to trade but these values are zero in strategy tester. To work around this problem, I created a parameter to set the margin (to use in strategy tester only) and I want to ignore this parameter when the EA runs on demo and real accounts.

Can someone help me to solve this problem?

Yes.

if (MqlInfoInteger(MQL_TESTER)) { printf("*** tester"); }

There's also a visual mode property ...

https://www.mql5.com/en/docs/check/mqlinfointeger

Documentation on MQL5: Checkup / MQLInfoInteger
Documentation on MQL5: Checkup / MQLInfoInteger
  • www.mql5.com
Checkup / MQLInfoInteger - Reference on algorithmic/automated trading language for MetaTrader 5
 
Rafael Caetano Pinto:

Is there any way to know if the EA is running on Strategy Tester?

My EA uses the symbolInfo.MarginMaintenance() to make some equations to trade but these values are zero in strategy tester. To work around this problem, I created a parameter to set the margin (to use in strategy tester only) and I want to ignore this parameter when the EA runs on demo and real accounts.

Can someone help me to solve this problem?

And for MT4, it's:

IsTesting()

https://docs.mql4.com/check/istesting

IsTesting - Checkup - MQL4 Reference
IsTesting - Checkup - MQL4 Reference
  • docs.mql4.com
IsTesting - Checkup - MQL4 Reference
 
Thanks a lot! This works like a charm! :)
 

I get this error while compiling !?

'MqlInfoInteger' - undeclared identifier   

 
Sebastian Braun: I get this error while compiling !? 'MqlInfoInteger' - undeclared identifier   

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. We can't see your broken code.

Did you bother to read the documentation?
          Checkup / MQLInfoInteger - Reference on algorithmic/automated trading language for MetaTrader 5
          MQLInfoInteger - MQL4 Reference

 
Anthony Garot: And for MT4, it's: IsTesting()
For MT4
enum termnal_Mode{  MODE_DEBUG, MODE_LIVE, MODE_VISUAL, MODE_OPTIMIZER};
termnal_Mode     get_modus_operandi(void){
   if(IS_DEBUG_MODE)          return MODE_DEBUG;   // Live but debugging.
   if(!IsTesting() )          return MODE_LIVE;
   if( IsVisualMode() )       return MODE_VISUAL;
                              return MODE_OPTIMIZER;
For MT4
 
William Roeder:

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. We can't see your broken code.

Did you bother to read the documentation?
          Checkup / MQLInfoInteger - Reference on algorithmic/automated trading language for MetaTrader 5
          MQLInfoInteger - MQL4 Reference

Yes, I could not see any hint in documenation to import or only use it within a specific scope. So what's the trick?

If I use this line in OnInti() or in any other method I tried, it does not compile.

if (MqlInfoInteger(MQL_TESTER)) { printf("*** tester"); }

Ah, the example above is just wrong!

It is:

if (MQLInfoInteger(MQL_TESTER))