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.

- docs.mql4.com
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..
I am sorry, still don't get your point..
please read there for more detail :)
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
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 //+------------------------------------------------------------------------------------+
Thank you for your comments.
But it is not what I mean..
Forum on trading, automated trading systems and testing trading strategies
How to limit ea only in one pair?
whroeder1, 2017.09.22 16:17
Check if there is already order(s) open.
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.
Forum on trading, automated trading systems and testing trading strategies
How to limit ea only in one pair?
Yohana Parmi, 2017.09.22 16:22
please read there for more detail :)
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.
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:
- 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.
- 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!
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.
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:
- 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.
- 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.
:)

- docs.mql4.com
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
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:
- Preventing EA from running on other charts (by using Terminal Global Variables).
- Preventing interference of code on other EA's and/or Symbols (by using a "magic number" and checking for the same "_Symbol).
- 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.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.