MultiCurrency EA

To add comments, please log in or register
Abubakar Saidu
4659
Abubakar Saidu  

Hello, good day to you all..

am trying to make the code place trades on all selected pairs

eg.

buy signal from XAUUSD place XAUUSD buy,

buy signal from GBPUSD place GBPUSD buy,

etc..

the  code.. its reading signal from selected symbol, but will place trades on first symbol

eg.

EURUSD,GBPUSD,XAUUSD

the EA will reads all buys and sells from other symbols,  but will place trade only on the first Symbol

tried

GBPUSD,EURUSD,XAUUSD

places trades on GBPUSD from GBPUSD signals.. and other selected symbol signals


input string Symbols = "GBPUSD,EURUSD,XAUUSD";

//--- Indicator handles
string SymbolArray[100];
int NumOfSymbols;
ushort comma_sep;

int team_handle[100];
double buy[],sell[];

int trend_handle[100];
double uptrend[],downtrend[];

 int OnInit()
  {
  comma_sep = StringGetCharacter(",",0);       

   string result[];
   NumOfSymbols = StringSplit(Symbols, comma_sep, result);
   for (int SymbolNum = 0; SymbolNum < NumOfSymbols; SymbolNum++)
   {
      StringTrimLeft(result[SymbolNum]);
      StringTrimRight(result[SymbolNum]);
      
      SymbolArray[SymbolNum] = result[SymbolNum];
   }
 for (int SymbolNum = 0; SymbolNum < NumOfSymbols; SymbolNum++)
   {
   string symbol = SymbolArray[SymbolNum];


   team_handle[SymbolNum] = iCustom(symbol, Period(),"Team");
   if(team_handle[SymbolNum]==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code 
      PrintFormat("Failed to create handle of the team_handle indicator for the symbol %s/%s, error code %d",
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early 
      return(INIT_FAILED);
     }
if(Use_Trend_Filter)
{
   trend_handle[SymbolNum] = iCustom(symbol, PERIOD_CURRENT,"Trend");
   if(trend_handle[SymbolNum] < 0)
     {
      Print("The creation of trend_handle has failed: Laser_Sight_handle=", INVALID_HANDLE);
      Print("Runtime error = ", GetLastError());
      return(INIT_FAILED);
     }
}




}
}

void OnTick()
  {
   for (int SymbolNum = 0; SymbolNum < NumOfSymbols; SymbolNum++)
   {
   string symbol = SymbolArray[SymbolNum];

   if(CopyBuffer(team_handle[SymbolNum], 2, 0, 6, buy) <= 0) return;
   ArraySetAsSeries(buy, true);
   if(CopyBuffer(team_handle[SymbolNum], 3, 0, 6, sell) <= 0) return;
   ArraySetAsSeries(sell, true);

if(Use_Trend_Filter)
{
   if(CopyBuffer(trend_handle[SymbolNum], uptrend_Buffer, 0, 200, uptrend) <= 0) return;
   ArraySetAsSeries(uptrend, true);
   if(CopyBuffer(trend_handle[SymbolNum], downtrend_Buffer, 0, 200, downtrend) <= 0) return;
   ArraySetAsSeries(downtrend, true);
}

ulong ticket=0;
 if(buysignal())
     {
      ticket = sendmeorder(symbol,ORDER_TYPE_BUY, price,stoplossB(),Btp1(),lot(ORDER_TYPE_BUY), cmt);

     }
if(sellsignal())
     {
      ticket = sendmeorder(symbol,ORDER_TYPE_SELL, price,stoplossS(),Stp1(),lot(ORDER_TYPE_SELL), cmt); 
     }
  }
}

send me order function

ulong myOrderSend(string symbol,ENUM_ORDER_TYPE type, double price,double stoploss, double takeprofit,double volume, string ordername) //send order, return ticket ("price" is irrelevant for market orders)
  {
   if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) || !MQLInfoInteger(MQL_TRADE_ALLOWED)) return(0);
   int retries = 0;
   int long_trades = TradesCount(ORDER_TYPE_BUY);
   int short_trades = TradesCount(ORDER_TYPE_SELL);
   int long_pending = TradesCount(ORDER_TYPE_BUY_LIMIT) + TradesCount(ORDER_TYPE_BUY_STOP) + TradesCount(ORDER_TYPE_BUY_STOP_LIMIT);
   int short_pending = TradesCount(ORDER_TYPE_SELL_LIMIT) + TradesCount(ORDER_TYPE_SELL_STOP) + TradesCount(ORDER_TYPE_SELL_STOP_LIMIT);
   string ordername_ = ordername;
   if(ordername != "")
      ordername_ = "("+ordername+")";
   //test Hedging
   if(!Hedging && ((type % 2 == 0 && short_trades + short_pending > 0) || (type % 2 == 1 && long_trades + long_pending > 0)))
     {
      myAlert("print", "Order"+ordername_+" not sent, hedging not allowed");
      return(0);
     }
   //test maximum trades
   if((type % 2 == 0 && long_trades >= MaxLongTrades)
   || (type % 2 == 1 && short_trades >= MaxShortTrades)
   || (long_trades + short_trades >= MaxOpenTrades)
   || (type > 1 && long_pending + short_pending >= MaxPendingOrders))
     {
      myAlert("print", "Order"+ordername_+" not sent, maximum reached");
      return(0);
     }
if(MaxSpread > 0 && getAsk() - getBid() > MaxSpread * Point())
     {
      myAlert("order", "Order"+ordername_+" not sent, maximum spread "+DoubleToString(MaxSpread * Point(), Digits())+" exceeded");
      return(-1);
     }
   //prepare to send order
   MqlTick last_tick;
   MqlTradeRequest request;
   ZeroMemory(request);
   request.action = (type <= 1) ? TRADE_ACTION_DEAL : TRADE_ACTION_PENDING;
   
   //set allowed filling type
   int filling = (int)SymbolInfoInteger(symbol,SYMBOL_FILLING_MODE);
   if(request.action == TRADE_ACTION_DEAL && (filling & 1) != 1)
      request.type_filling = ORDER_FILLING_IOC;

   request.magic = MagicNumber;
   request.symbol = symbol;
   request.volume = NormalizeDouble(volume, LotDigits);
   request.sl = stoploss;
   request.tp = takeprofit;
   request.deviation = MaxSlippage_;
   request.type = type;
   request.comment = ordername;

   int expiration=(int)SymbolInfoInteger(symbol, SYMBOL_EXPIRATION_MODE);
   if((expiration & SYMBOL_EXPIRATION_GTC) != SYMBOL_EXPIRATION_GTC)
     {
      request.type_time = ORDER_TIME_DAY;  
      request.type_filling = ORDER_FILLING_RETURN;
     }

   MqlTradeResult result;
   ZeroMemory(result);
   while(!OrderSuccess(result.retcode) && retries < OrderRetry+1)
     {
      //refresh price before sending order
      SymbolInfoTick(symbol, last_tick);
      if(type == ORDER_TYPE_BUY)
         price = last_tick.ask;
      else if(type == ORDER_TYPE_SELL)
         price = last_tick.bid;
      else if(price < 0) //invalid price for pending order
        {
         myAlert("order", "Order"+ordername_+" not sent, invalid price for pending order");
              return(0);
        }
      request.price = NormalizeDouble(price, Digits());     
      if(!OrderSend(request, result) || !OrderSuccess(result.retcode))
        {
         myAlert("print", "OrderSend"+ordername_+" error: "+result.comment);
         Sleep(OrderWait*1000);
        }
      retries++;
     }
   if(!OrderSuccess(result.retcode))
     {
      myAlert("error", "OrderSend"+ordername_+" failed "+IntegerToString(OrderRetry+1)+" times; error: "+result.comment);
      return(0);
     }
   string typestr[8] = {"Buy", "Sell", "Buy Limit", "Sell Limit", "Buy Stop", "Sell Stop", "Buy Stop Limit", "Sell Stop Limit"};
   myAlert("order", "Order sent"+ordername_+": "+typestr[type]+" "+symbol+" Magic #"+IntegerToString(MagicNumber));
   return(result.order);
  }

Documentation on MQL5: Market Info / SymbolSelect
Documentation on MQL5: Market Info / SymbolSelect
  • www.mql5.com
[in] Switch. If the value is false, a symbol should be removed from MarketWatch, otherwise a symbol should be selected in this window. A symbol can't be removed if the symbol chart is open, or there are open positions for this symbol.
Stanislav Ivanov
7067
Stanislav Ivanov  

Hi,

Did you check whether the symbol string input was parsed correctly ? 

Abubakar Saidu
4659
Abubakar Saidu  
Stanislav Ivanov:

Hi,

Did you check whether the symbol string input was parsed correctly ? 

Hello, good day, thanks for your reply..

this are the inputs.. separated using this

comma_sep = StringGetCharacter(",",0);       

   string result[];
   NumOfSymbols = StringSplit(Symbols, comma_sep, result);

it reads both symbol but only place trades on first symbol

i could not find whats wrong with my code

Abubakar Saidu
4659
Abubakar Saidu  

ahh..

this is strange

adding this into my code.. fixed it


         int SignalBarShift = 0;
         ENUM_ORDER_TYPE SignalType=0;
         int i = 1, bars = iBars(symbol, PERIOD_CURRENT);
         while (i < bars) 
         {
               if (team(SymbolNum,ReboundD, i)!=EMPTY_VALUE)
 {SignalBarShift = i; break;}
               if (team(SymbolNum,ReboundU, i)!=EMPTY_VALUE)
 {SignalBarShift = i; break;}
            i++;
         }
         if (SignalBarShift == 0) continue;
         
         

         if (SignalBarShift == 1 
            )
        {
        }



void OnTick()
  {
   for (int SymbolNum = 0; SymbolNum < NumOfSymbols; SymbolNum++)
   {
   string symbol = SymbolArray[SymbolNum];
         int SignalBarShift = 0;
         ENUM_ORDER_TYPE SignalType=0;
         int i = 1, bars = iBars(symbol, PERIOD_CURRENT);
         while (i < bars) 
         {
               if (team(SymbolNum,ReboundD, i)!=EMPTY_VALUE)
 {SignalBarShift = i; break;}
               if (team(SymbolNum,ReboundU, i)!=EMPTY_VALUE)
 {SignalBarShift = i; break;}
            i++;
         }
         if (SignalBarShift == 0) continue;
         
         

         if (SignalBarShift == 1 
            )
        {

   if(CopyBuffer(team_handle[SymbolNum], 2, 0, 6, buy) <= 0) return;
   ArraySetAsSeries(buy, true);
   if(CopyBuffer(team_handle[SymbolNum], 3, 0, 6, sell) <= 0) return;
   ArraySetAsSeries(sell, true);

if(Use_Trend_Filter)
{
   if(CopyBuffer(trend_handle[SymbolNum], uptrend_Buffer, 0, 200, uptrend) <= 0) return;
   ArraySetAsSeries(uptrend, true);
   if(CopyBuffer(trend_handle[SymbolNum], downtrend_Buffer, 0, 200, downtrend) <= 0) return;
   ArraySetAsSeries(downtrend, true);
}

ulong ticket=0;
 if(buysignal())
     {
      ticket = sendmeorder(symbol,ORDER_TYPE_BUY, price,stoplossB(),Btp1(),lot(ORDER_TYPE_BUY), cmt);

     }
if(sellsignal())
     {
      ticket = sendmeorder(symbol,ORDER_TYPE_SELL, price,stoplossS(),Stp1(),lot(ORDER_TYPE_SELL), cmt); 
     }
  }
}  
    }

can someone explain why? undo its fixed and working perfectly. but i want to understand why the code worked!! i need to unscrew this from my brain

To add comments, please log in or register