How to limit ea only in one pair?

To add comments, please log in or register
Donald Reeves Sihombing
11353
Donald Reeves Sihombing  

Dear friends, need your help.

If EA already run in one pair, then how to avoid EA run in the other pair?

So EA only run in one pair.

Thank you.

Yohana Parmi
4951
Yohana Parmi  
Donald Reeves Sihombing:

Dear friends, need your help.

If EA already run in one pair, then how to avoid EA run in the other pair?

So EA only run in one pair.

Thank you.


Hi,

You can use this https://docs.mql4.com/globals
to read and write EA's status.

Good luck.

Global Variables of the Terminal - MQL4 Reference
Global Variables of the Terminal - MQL4 Reference
  • docs.mql4.com
Global Variables of the Terminal - MQL4 Reference
Donald Reeves Sihombing
11353
Donald Reeves Sihombing  
Yohana Parmi:

Hi,

You can use this https://docs.mql4.com/globals
to read and write EA's status.

Good luck.


I am sorry, still don't get your point..

whroeder1
17943
whroeder1  
Donald Reeves Sihombing: If EA already run in one pair, then how to avoid EA run in the other pair? So EA only run in one pair.

Check if there is already order(s) open.

Yohana Parmi
4951
Yohana Parmi  
Donald Reeves Sihombing:

I am sorry, still don't get your point..


please read there for more detail :)

Fernando Carreiro
4335
Fernando Carreiro  
Donald Reeves Sihombing: Dear friends, need your help. If EA already run in one pair, then how to avoid EA run in the other pair? So EA only run in one pair.

Do you perhaps mean that you want to "protect" your EA so that your customer cannot run it on another symbol?

If yes, then read the following post that contains source code for restricting an EA and includes a section for the allowable currency pairs.

Forum on trading, automated trading systems and testing trading strategies

EA limit code

Fernando Carreiro, 2017.09.10 22:17

Here is a sample of my own code that I use, but it is up to you to implement properly. I'm not offering any support on it. It is up to you to do the necessary research and learning.

//+------------------------------------------------------------------------------------+
// Initialisation Event Function
//+------------------------------------------------------------------------------------+
int OnInit()
{
   // Check Licensing Restrictions
   if( boolRestrictOnInit() ) return( INIT_FAILED );

   // ...

   return( INIT_SUCCEEDED );  // Initialisation complete
}
//+------------------------------------------------------------------------------------+
// Tick Event Function
//+------------------------------------------------------------------------------------+
void OnTick()
{
   // Check Licensing Restrictions
   if( boolRestrictOnTick() ) return;
   
   /// ...
}
//+------------------------------------------------------------------------------------+
// Function to Test Restrictions during Initialisation
//+------------------------------------------------------------------------------------+
bool boolRestrictOnInit()
{
   boolRestrictions =
      boolRestrictExpiration     ||
      boolRestrictAccountNumber  ||
      boolRestrictAccountName    ||
      boolRestrictAccountServer  ||
      boolRestrictAccountCompany ||
      boolRestrictDemoAccount    ||
      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( boolRestrictAccountName )
               { if( AccountInfoString( ACCOUNT_NAME )        != strRestrictAccountName    )
                  { return( boolRestrictAlert() ); } }
            if( boolRestrictAccountServer )
               { if( AccountInfoString( ACCOUNT_SERVER )      != strRestrictAccountServer  )
                  { return( boolRestrictAlert() ); } }
            if( boolRestrictAccountCompany )
               { if( AccountInfoString( ACCOUNT_COMPANY )     != strRestrictAccountCompany )
                  { return( boolRestrictAlert() ); } }
            if( boolRestrictDemoAccount )
               { if( AccountInfoInteger( ACCOUNT_TRADE_MODE ) != ACCOUNT_TRADE_MODE_DEMO   )
                  { 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
   boolRestrictExpiration     = false, // Set to true, to use an Experation Date
   boolRestrictAccountNumber  = false, // Set to true for Restricting by Account Number
   boolRestrictAccountName    = false, // Set to true for Restricting by Account Name
   boolRestrictAccountServer  = false, // Set to true for Restricting by Account Server
   boolRestrictAccountCompany = false, // Set to true for Restricting by Account Company
   boolRestrictDemoAccount    = false, // Set to true, to only allow Demo Accounts
   boolRestrictSymbols        = false, // 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!
datetime
   dtRestrictExpiration       = D'2017.03.31';  // Restricted by Expration Date
long
   longRestrictAccountNumber  = 123456789;      // Restricted by Account Number
string
   strRestrictAccountName     = "Client Name",  // Restricted by Account Name
   strRestrictAccountServer   = "Server Name",  // Restricted by Account Server
   strRestrictAccountCompany  = "Company Name", // Restricted by Account Company
   strRestrictSymbols[]       = { "EURUSD", "GBPJPY", "NZDCAD" }, // 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
//+------------------------------------------------------------------------------------+

Donald Reeves Sihombing
11353
Donald Reeves Sihombing  

Thank you for your comments.

But it is not what I mean..

What if the EA already run in a pair, but it still has no order? at the same time the EA can run in another pair.. So I can not use this way.


And thank to you Fernando Carreiro, but I don want to protect the EA from a particular pair. I just avoid the EA run in more than one pair. No matter what the pair is..

If it already run in one pair, then it can not run in the next pair.


Fernando Carreiro
4335
Fernando Carreiro  
Donald Reeves Sihombing:

Thank you for your comments.

But it is not what I mean..

What if the EA already run in a pair, but it still has no order? at the same time the EA can run in another pair.. So I can not use this way.

And thank to you Fernando Carreiro, but I don want to protect the EA from a particular pair. I just avoid the EA run in more than one pair. No matter what the pair is..

If it already run in one pair, then it can not run in the next pair.

Okay, I will try.

I assume that by "pair", you mean the symbol (eg. a currency pair). If you want your EA to work on different charts but not interfere with each other, you use two things in your code:

  1. You must check the Order's Symbol to see that it is the same one as the chart's (namely "_Symbol") and only respond to those orders.
  2. You must use a unique "magic number" on the orders and check for it, in order to be able to use the EA on multiple charts, even if on the same symbol.

PS! It might be best for you to show some code in order to explain what the problem is on a more object way! Otherwise we don't really know what you want and we are constantly trying to guess!

Yohana Parmi
4951
Yohana Parmi  
Donald Reeves Sihombing:

Dear friends, need your help.

If EA already run in one pair, then how to avoid EA run in the other pair?
So EA only run in one pair.

Thank you.

Fernando Carreiro:

I assume that by "pair", you mean the symbol (eg. a currency pair). If you want your EA to work on different charts but not interfere with each other, you use two things in your code:

  1. You must check the Order's Symbol to see that it is the same one as the chart's (namely "_Symbol") and only respond to those orders.
  2. You must use a unique "magic number" on the orders and check for it, in order to be able to use the EA on multiple charts, even if on the same symbol.

PS! It might be best for you to show some code in order to explain what the problem is on a more object way! Otherwise we don't really know what you want and we are constantly trying to guess!


Hi, Fernando

Yes, you're right. @Donald Reeves Sihombing should change word "pair" to "chart" :))


I assumed that what he wants is when the EA is already used on a chart,
then other charts should not run the EA.

I hope @whroeder1 have same assumption with me.
and I am sure it could be done as described at https://docs.mql4.com/globals
or otherwise at freelance.

:)

Global Variables of the Terminal - MQL4 Reference
Global Variables of the Terminal - MQL4 Reference
  • docs.mql4.com
Global Variables of the Terminal - MQL4 Reference
MT4 Trading
228
MT4 Trading  
Donald Reeves Sihombing:

Dear friends, need your help.

If EA already run in one pair, then how to avoid EA run in the other pair?

So EA only run in one pair.

Thank you.

You need to add this first:

string   Pair                 = "EURUSD";


Then add this under int start()

if(Symbol()!=Pair)
    {
      Comment("Wrong Pair. Please use EURUSD Only");
      return(0);
    }


It will only trade EURUSD Only


Hope it helps

Fernando Carreiro
4335
Fernando Carreiro  
Yohana Parmi: Yes, you're right. @Donald Reeves Sihombing should change word "pair" to "chart" :))

I assumed that what he wants is when the EA is already used on a chart,
then other charts should not run the EA.

I hope @whroeder1 have same assumption with me.
and I am sure it could be done as described at https://docs.mql4.com/globals
or otherwise at freelance.

At this point it is very unclear what the OP wants and between all the posts we have already covered 3 possibilities:

  1. Preventing EA from running on other charts (by using Terminal Global Variables).
  2. Preventing interference of code on other EA's and/or Symbols (by using a "magic number" and checking for the same "_Symbol).
  3. Protecting or limiting EA by restricting the allowable Currency Pairs.

So now it is up to the OP to properly detail what he wants with some code examples.

12
To add comments, please log in or register