Problem with multiple positions

Back to topics list To post a new topic, please log in or register
avatar
7
Aramis3 2016.02.11 20:59
 

Hi guys, so my  problem is that when i backtest in strategy tester everything goes ok, when i drop this ea in my demo account in a ecn broker it apparently execute both orders the first tp and the second, but when i drop in my demo account in the fxpro that was provided by metaquotes with their terminal it doesnt executes both orders, only the first tp... 

Sorry about my poor english, my code is bellow, thanks in advance. 

avatar
7
Aramis3 2016.02.11 21:03 #
 
void CheckForSignal()
  {
   static datetime candletime=0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   if(candletime!=Time[0])
     {
      
      if(Close[1]>Close[2])
        {
         exitsells();
         exitsells2();
            if(TotalOpenOrders()<1)
              {

               EnterTrade(OP_BUY);
               EnterTrade2(OP_BUY);
              }
           
        }

      if(Close[1]<Close[2])
        {
         exitbuy();
         exitbuy2();
         
            if(TotalOpenOrders()<1)
              {
               EnterTrade(OP_SELL);
               EnterTrade2(OP_SELL);
              }

           
        }

      candletime=Time[0];
     }
  }
//+------------------------------------------------------------------+
//|     TRADE PLACING FUNCTION                                                             |
//+------------------------------------------------------------------+
void EnterTrade(int type)
  {

   int err=0;
   double price=Bid,sl=0,tp=0;
   if(type==OP_BUY)
      price=Ask;
//----
   int ticket=OrderSend(Symbol(),type,LotSize,price,Slippage,0,0,"MAEA Trade",magic,0,Magenta);
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   if(ticket>0)
     {
      if(OrderSelect(ticket,SELECT_BY_TICKET))
        {
         sl=OrderOpenPrice()+(atx*atval);

         tp=OrderOpenPrice()-(atx*atval);
         if(OrderType()==OP_BUY)
           {
            sl=OrderOpenPrice()-(atx*atval);

            tp=OrderOpenPrice()+(atx*atval);
           }
         if(!OrderModify(ticket,price,sl,tp,0,Magenta))
           {
            err=GetLastError();
            Print("Encountered an error during modification!"+(string)err+" "+ErrorDescription(err));
           }
        }
      else
        {//in case it fails to select the order for some reason 
         Print("Failed to Select Order ",ticket);
         err=GetLastError();
         Print("Encountered an error while seleting order "+(string)ticket+" error number "+(string)err+" "+ErrorDescription(err));
        }
     }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   else
     {//in case it fails to place the order and send us back a ticket number.
      err=GetLastError();
      Print("Encountered an error during order placement!"+(string)err+" "+ErrorDescription(err));
      if(err==ERR_TRADE_NOT_ALLOWED)MessageBox("You can not place a trade because \"Allow Live Trading\" is not checked in your options. Please check the \"Allow Live Trading\" Box!","Check Your Settings!");
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int MagicNumberGenerator()
  {
   string mySymbol=StringSubstr(_Symbol,0,6);
   int pairNumber=0;
   int GeneratedNumber=0;
   if(mySymbol=="AUDCAD") pairNumber=1;
   else if(mySymbol == "AUDCHF")    pairNumber=2;
   else if(mySymbol == "AUDJPY")    pairNumber=3;
   else if(mySymbol == "AUDNZD")    pairNumber=4;
   else if(mySymbol == "AUDUSD")    pairNumber=5;
   else if(mySymbol == "CADCHF")    pairNumber=6;
   else if(mySymbol == "CADJPY")    pairNumber=7;
   else if(mySymbol == "CHFJPY")    pairNumber=8;
   else if(mySymbol == "EURAUD")    pairNumber=9;
   else if(mySymbol == "EURCAD")    pairNumber=10;
   else if(mySymbol == "EURCHF")    pairNumber=11;
   else if(mySymbol == "EURGBP")    pairNumber=12;
   else if(mySymbol == "EURJPY")    pairNumber=13;
   else if(mySymbol == "EURNZD")    pairNumber=14;
   else if(mySymbol == "EURUSD")    pairNumber=15;
   else if(mySymbol == "GBPAUD")    pairNumber=16;
   else if(mySymbol == "GBPCAD")    pairNumber=17;
   else if(mySymbol == "GBPCHF")    pairNumber=18;
   else if(mySymbol == "GBPJPY")    pairNumber=19;
   else if(mySymbol == "GBPNZD")    pairNumber=20;
   else if(mySymbol == "GBPUSD")    pairNumber=21;
   else if(mySymbol == "NZDCAD")    pairNumber=22;
   else if(mySymbol == "NZDJPY")    pairNumber=23;
   else if(mySymbol == "NZDCHF")    pairNumber=24;
   else if(mySymbol == "NZDUSD")    pairNumber=25;
   else if(mySymbol == "USDCAD")    pairNumber=26;
   else if(mySymbol == "USDCHF")    pairNumber=27;
   else if(mySymbol == "USDJPY")   pairNumber=28;
   GeneratedNumber=MagicSeed+(pairNumber*55555)+_Period;
   return(GeneratedNumber);
  }

avatar
7
Aramis3 2016.02.11 21:04 #
 
void EnterTrade2(int type)
  {

   int err=0;
   double price=Bid,sl=0,tp=0;
   if(type==OP_BUY)
      price=Ask;
//----
   int ticket=OrderSend(Symbol(),type,LotSize2,price,Slippage,0,0,"MAEA Trade",magic2,0,Magenta);
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   if(ticket>0)
     {
      if(OrderSelect(ticket,SELECT_BY_TICKET))
        {
         sl=OrderOpenPrice()+(atx*atval);

         tp=OrderOpenPrice()-2*(atx*atval);
         if(OrderType()==OP_BUY)
           {
            sl=OrderOpenPrice()-(atx*atval);

            tp=OrderOpenPrice()+2*(atx*atval);
           }
         if(!OrderModify(ticket,price,sl,tp,0,Magenta))
           {
            err=GetLastError();
            Print("Encountered an error during modification!"+(string)err+" "+ErrorDescription(err));
           }
        }
      else
        {//in case it fails to select the order for some reason 
         Print("Failed to Select Order ",ticket);
         err=GetLastError();
         Print("Encountered an error while seleting order "+(string)ticket+" error number "+(string)err+" "+ErrorDescription(err));
        }
     }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
   else
     {//in case it fails to place the order and send us back a ticket number.
      err=GetLastError();
      Print("Encountered an error during order placement!"+(string)err+" "+ErrorDescription(err));
      if(err==ERR_TRADE_NOT_ALLOWED)MessageBox("You can not place a trade because \"Allow Live Trading\" is not checked in your options. Please check the \"Allow Live Trading\" Box!","Check Your Settings!");
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int MagicNumberGenerator2()
  {
   string mySymbol=StringSubstr(_Symbol,0,6);
   int pairNumber=0;
   int GeneratedNumber=0;
   if(mySymbol=="AUDCAD") pairNumber=1;
   else if(mySymbol == "AUDCHF")    pairNumber=2;
   else if(mySymbol == "AUDJPY")    pairNumber=3;
   else if(mySymbol == "AUDNZD")    pairNumber=4;
   else if(mySymbol == "AUDUSD")    pairNumber=5;
   else if(mySymbol == "CADCHF")    pairNumber=6;
   else if(mySymbol == "CADJPY")    pairNumber=7;
   else if(mySymbol == "CHFJPY")    pairNumber=8;
   else if(mySymbol == "EURAUD")    pairNumber=9;
   else if(mySymbol == "EURCAD")    pairNumber=10;
   else if(mySymbol == "EURCHF")    pairNumber=11;
   else if(mySymbol == "EURGBP")    pairNumber=12;
   else if(mySymbol == "EURJPY")    pairNumber=13;
   else if(mySymbol == "EURNZD")    pairNumber=14;
   else if(mySymbol == "EURUSD")    pairNumber=15;
   else if(mySymbol == "GBPAUD")    pairNumber=16;
   else if(mySymbol == "GBPCAD")    pairNumber=17;
   else if(mySymbol == "GBPCHF")    pairNumber=18;
   else if(mySymbol == "GBPJPY")    pairNumber=19;
   else if(mySymbol == "GBPNZD")    pairNumber=20;
   else if(mySymbol == "GBPUSD")    pairNumber=21;
   else if(mySymbol == "NZDCAD")    pairNumber=22;
   else if(mySymbol == "NZDJPY")    pairNumber=23;
   else if(mySymbol == "NZDCHF")    pairNumber=24;
   else if(mySymbol == "NZDUSD")    pairNumber=25;
   else if(mySymbol == "USDCAD")    pairNumber=26;
   else if(mySymbol == "USDCHF")    pairNumber=27;
   else if(mySymbol == "USDJPY")   pairNumber=28;
   GeneratedNumber=MagicSeed+(pairNumber*6666)+_Period;
   return(GeneratedNumber);
  }

avatar
7
Aramis3 2016.02.11 21:05 #
 
my text was too long to post the whole code.. but i think you can have an ideia, if needed i add the other part
avatar
1109
Ovo 2016.02.12 08:29 #
 
I did not study your code, but I would guess the American FIFO nonsense was in action. FxPro is Cyprus based, they won't apply it.
avatar
7
Aramis3 2016.02.12 14:59 #
 
Thansk for your answer, that makes sense, because today i took a feel trades forward testing it and was ok in other brokers.
Back to topics list  

To add comments, please log in or register