How to NOT to run EA on certain symbol.

 

Dear all.

How do I code if I don't want to make EA run on certain symbol?

I took the code from other topic.

Thanks in advanced.


int OnInit()

{
   // Check Licensing Restrictions
   if( boolRestrictOnInit() ) return( INIT_FAILED );

   // ...

   return( INIT_SUCCEEDED );  // Initialisation complete
}

void OnDeinit(const int reason){
ObjectDelete(NULL,"close_all");
   }

void OnTimer(){
   onTimer();
   }

void OnTick()
{

   if(IsTesting())
      
      (onTimer()) return;
      
   // Check Licensing Restrictions
   if( boolRestrictOnTick() ) return;
   
   /// ..
}

//+------------------------------------------------------------------------------------+
// Function to Test Restrictions during Initialisation
//+------------------------------------------------------------------------------------+
bool boolRestrictOnInit()
{
   boolRestrictions =
      boolRestrictAccountNumber  ||
      boolRestrictSymbols

   if( boolRestrictions )
   {
      boolRestrictionsUnverified = true;

      if( (bool) TerminalInfoInteger( TERMINAL_CONNECTED ) )
      {
         long longAccountNumber = AccountInfoInteger( ACCOUNT_LOGIN );
         if( longAccountNumber > 0 )
         {
            if( boolRestrictAccountNumber )
               { if( longAccountNumber                        != longRestrictAccountNumber )
                  { return( boolRestrictAlert() ); } }
            if( boolRestrictSymbols() )
               { return( boolRestrictAlert() ); }

            boolRestrictionsUnverified = false;
         }
      }
   }
   return( false );
}
//+------------------------------------------------------------------------------------+
// Function to Test Variations of Restricted Symbols
//+------------------------------------------------------------------------------------+
bool boolRestrictSymbols()
{
   if( boolRestrictSymbols )
   {
      int intSymbolCount = ArraySize( strRestrictSymbols );
      if( intSymbolCount == 0 ) return( false );
      for( int i = 0; i < intSymbolCount; i++ )
      {
         if( StringFind( _Symbol, strRestrictSymbols[i] ) != WRONG_VALUE ) return( false );
         int
            intLen  = StringLen( strRestrictSymbols[i] ),
            intHalf = intLen / 2;
         string
            strLeft  = StringSubstr( strRestrictSymbols[i], 0, intHalf ),
            strRight = StringSubstr( strRestrictSymbols[i], intHalf, intLen - intHalf );
         if( ( StringFind( _Symbol, strLeft  ) != WRONG_VALUE ) &&
             ( StringFind( _Symbol, strRight ) != WRONG_VALUE )    )
            return( false );
      }
      return( true );
   }
   return( false );
}
//+------------------------------------------------------------------------------------+
// Function to Test Expiration during Tick Events
//+------------------------------------------------------------------------------------+
bool boolRestrictOnTick()
{
   if( boolRestrictions )
   {
      if( boolRestrictionsUnverified )
         return( boolRestrictOnInit() );
      if( boolRestrictExpiration && ( TimeCurrent() >= dtRestrictExpiration ) )
         return( boolRestrictAlert()  );
   }
   return( false );
}
// Function to Alert User of Licensing Restrictions and Remove Code from Execution
bool boolRestrictAlert()
{
   if( boolRestrictAlert )
      MessageBox( strRestrictAlertMessage, strRestrictAlertCaption, MB_ICONERROR );
   ExpertRemove();
   return( true );
}
//+------------------------------------------------------------------------------------+
//      Variables for Handling of Licensing Restrictions
//+------------------------------------------------------------------------------------+
bool
   boolRestrictAccountNumber  = true, // Set to true for Restricting by Account Number
   boolRestrictSymbols        = true, // Set to true, to only allow certain Symbols
   boolRestrictAlert          = true,  // Display Alert Message when Restrictions apply
   boolRestrictionsUnverified = false, // DO NOT CHANGE. For internal use only!
   boolRestrictions           = false; // DO NOT CHANGE. For internal use only!
long
   longRestrictAccountNumber  = 123456789;      // Restricted by Account Number
string
   
   strRestrictSymbols[]       = { "EURJPY", "EURJPY.r", "GBPJPY" }, // Restricted Symbols
   strRestrictAlertCaption    = "Restrictions", // Alert Message Box Caption
   strRestrictAlertMessage    =
      "ATTENTION! Due to Licensing Restrictions, code execution has been blocked!";
      // Message to be used when Restrictions have been detected
//+------------------------------------------------------------------------------------+
 
Forexalpha777:

Dear all.

How do I code if I don't want to make EA run on certain symbol?

I took the code from other topic.

Thanks in advanced.


Figure it  out!

 
Do not post code that will not even compile.
   boolRestrictions =
      boolRestrictAccountNumber  ||
      boolRestrictSymbols
The latter is a function.
 

Before opening an order just write this:

if(_Symbol != "EURUSD")

And this "if" makes sure that the symbol isn't  EURUSD

 
what is this function for though? you can simply choose not to run the EA in that particular chart?
 
Thanks to all
 
You may also want to une the StringSubstr() Function to Filter out broker added Letters to different Pairs/Symbols. (Ex: EURUSDecn could be reduced to EURUSD)