Opening orders in different symbols

 

I've just seen that my new multipair advisor is opening and closing orders from another symbols in some tests (EURUSD does not give this problem) and also in the test drive demo account. For example, GBPUSD is opening and closing EURUSD and EURGBP orders and don't actually know why. This is the way I get _Symbol value:

   void OnTick()
     {
      CTrade trade;
      double MyBuffers[];
      ArraySetAsSeries(MyBuffer1, true);
      ArraySetAsSeries(MyBuffer2, true);
      ArraySetAsSeries(MyBuffer3, true);
      for(int s= 0 ; s< SymbolsTotal(true); s++)
        {
         string SName= SymbolName(s, true);
        }
     }

Anybody can help on this matter? Thanks in advance.

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
  • www.mql5.com
, then each symbol positions will be closed in the same order, in which they are opened, starting with the oldest one. In case of an attempt to close positions in a different order, the trader will receive an appropriate error. There are several types of accounts that can be opened on a trade server. The type of account on which an MQL5 program...
 
David Diez :

I've just seen that my new multipair advisor is opening and closing orders from another symbols in some tests (EURUSD does not give this problem) and also in the test drive demo account . For example,  GBPUSD is opening and closing EURUSD and EURGBP orders  and don't actually know why. This is the way I get _Symbol  value:

Anybody can help on this matter? Thanks in advance.

So where is the code?

Please post compileable code - don't try to post chunks of code.

 
Better yet: describe what you want from your advisor and I will guide you through the steps.
 
Vladimir Karputov:
Better yet: describe what you want from your advisor and I will guide you through the steps.

I've just added that Symbols loop and changed _Symbol by SName, and the same for _Point (SPoint). What I need is an advisor to work multisymbol from all of them from the marketwatch but it should manage each one unique.

 
Vladimir Karputov:

So where is the code?

Please post compileable code - don't try to post chunks of code.

Ok I don't know which was the problem I got it working fine now.
Hello World() 
 
David Diez:
Ok I don't know which was the problem I got it working fine now.

You must create the SName variable as an array, to hold and list all symbol names when you loop SymbolsTotal().

Then if you make a transaction, you must loop, checking that the m.symbol.Name() is the same as the symbol name in the SName array.

 
Roberto Jacobs:

You must create the SName variable as an array, to hold and list all symbol names when you loop SymbolsTotal().

Then if you make a transaction, you must loop, checking that the m.symbol.Name() is the same as the symbol name in the SName array.

      double BuyOrders=0,SellOrders=0;
      for(int i=0;i<PositionsTotal();i++){
         ulong iTicket=PositionGetTicket(i);
         if(PositionSelectByTicket(iTicket)&&
         PositionGetString(POSITION_SYMBOL)==SName){
            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY){BuyOrders++;}
            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL){SellOrders++;}
            }
         }
      if(ADX[0]<ADX_Limit&&Spread<MaxSpread){
         if(/*Condition1*/){
            if(/*Condition2*/&&BuyOrders<1){
               if(!trade.PositionOpen(SName,ORDER_TYPE_BUY,LotSize,Ask,SL,TP,CustomComment)){
                  Print("PositionOpen error ",trade.ResultRetcode());
                  return;
                  }
               }
            }
         if(/*Condition1*/){
            if(/*Condition2*/&&SellOrders<1){
               if(!trade.PositionOpen(SName,ORDER_TYPE_SELL,LotSize,Ask,SL,TP,CustomComment)){
                  Print("PositionOpen error ",trade.ResultRetcode());
                  return;
                  }
               }
            }
         }
      double ClosePrice=0;
      for(int i=0;i<PositionsTotal();i++){
         ulong iTicket=PositionGetTicket(i);
         if(PositionSelectByTicket(iTicket)&&
         PositionGetString(POSITION_SYMBOL)==SName){
            if(PositionsTotal()>1){ // Close at reversal
               if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY){ClosePrice=Bid;}
               if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL){ClosePrice=Ask;}
               if(!trade.PositionClose(iTicket,ULONG_MAX)){
                  Print("PositionClose error ",trade.ResultRetcode());
                  return;
                  }
               }
            }
         }

This is the code, orders are opening and closing continuously, this is not happening in the backtests.