I wrote this code and it is working, the problem is that it only trade one at a time, even though i have attached it on several pairs. Is it possible to make it trade on other pairs if those pairs reaches the criteria? Thank you.
- Can we make EA's trade multiple pairs if criterias are met by those pairs?
- Thoughts on some of the absurdity of multi-currency analysis.
- [ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3.
Search forum for "semaphore" and see example
//+------------------------------------------------------------------+
//| trade.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#include <stderror.mqh>
#include <stdlib.mqh>
extern int ExtStopLoss=20;
extern int ExtTakeProfit=50;
string ExtTradeSemaphore="trade_semaphore";
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void init()
{
//---- check for our semaphore
if(GlobalVariableCheck(ExtTradeSemaphore))
{
int day_checked=GlobalVariableGet(ExtTradeSemaphore);
if(day_checked!=0)
{
int semaphore_check=Day();
//---- it may be wrong value in the our semaphore
if(day_checked<semaphore_check-1 || day_checked>semaphore_check)
GlobalVariableSet(ExtTradeSemaphore,0);
}
}
else GlobalVariableSet(ExtTradeSemaphore,0); // semaphore created with "free" state
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
bool semaphored=false;
int ticket,error;
//----
while(!IsStopped() && !IsTesting())
{
//---- check for zero value (free state) and occupate our semaphore with day number
if(!GlobalVariableSetOnCondition(ExtTradeSemaphore,Day(),0))
{
if(GetLastError()==ERR_GLOBAL_VARIABLE_NOT_FOUND)
{
//---- create with "busy" state
GlobalVariableSet(ExtTradeSemaphore,Day());
semaphored=true;
break;
}
//---- wait for half-second and check again
else Sleep(500);
}
else { semaphored=true; break; }
}
//----
while(!IsStopped() && IsTradeAllowed())
{
//---- ask price may be changed when waiting
RefreshRates();
ticket=OrderSend(Symbol(),OP_BUY,1.0,Ask,3,Bid-ExtStopLoss*Point,Bid+ExtTakeProfit*Point);
if(ticket<=0)
{
error=GetLastError();
Print("Error = ",ErrorDescription(error));
if(error==133) break; // trade is disabled
if(error==134) break; // not enough money
}
else break;
//---- 10 seconds wait
Sleep(10000);
}
//---- free our semaphore
if(semaphored) GlobalVariableSet(ExtTradeSemaphore,0);
return(0);
}
//+------------------------------------------------------------------+
thank you so much for the feedback.
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