Tim:
void OnTick()
{
// Check if running in backtest mode
bool isBacktest = MQLInfoInteger(MQL_TESTER) == 1;
// Check if the account is a demo account
bool isDemoAccount = AccountInfoInteger(ACCOUNT_TRADE_MODE) == ACCOUNT_TRADE_MODE_DEMO;
// If not in backtest mode and not a demo account, stop execution
if (!isBacktest && !isDemoAccount)
{
Print("Demo version: This EA only runs on demo accounts or backtesting.");
return;
}
void OnTick()
{
// Check if running in backtest mode
bool isBacktest = MQLInfoInteger(MQL_TESTER) == 1;
// Check if the account is a demo account
bool isDemoAccount = AccountInfoInteger(ACCOUNT_TRADE_MODE) == ACCOUNT_TRADE_MODE_DEMO;
// If not in backtest mode and not a demo account, stop execution
if (!isBacktest && !isDemoAccount)
{
Print("Demo version: This EA only runs on demo accounts or backtesting.");
return;
}
you need an or check , if its not backtest or if its not demo account
Tim #:
Hello I have already write if (!isBacktest), can you spoil what wrong with the script or what else have to be added. Thanks so much
Hello I have already write if (!isBacktest), can you spoil what wrong with the script or what else have to be added. Thanks so much
yeah , call ExpertRemove too on the non init functions
#define ISDEMO (bool)(AccountInfoInteger(ACCOUNT_TRADE_MODE)==ACCOUNT_TRADE_MODE_DEMO) #define ISBACKTEST (bool)(MQLInfoInteger(MQL_TESTER)) int OnInit() { if(!ISDEMO||!ISBACKTEST){return(INIT_FAILED);} return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } void OnTick() { if(!ISDEMO||!ISBACKTEST){ExpertRemove();return;} } void OnTimer() { if(!ISDEMO||!ISBACKTEST){ExpertRemove();return;} } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(!ISDEMO||!ISBACKTEST){ExpertRemove();return;} }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello community,
I am writing a new EA and want to allow it running on Demo and Tester only. I have tried the script:
But it still running trades on live account. Does someone know how to overcome this issue please help me. Thank you.
Tim.