3 position Stop Loss moving with difference parameters(BE, SL2, SL3)

 

Hello, 

At the outset, I apologize for my English, most of the work done by google translator. Thank you for your patience with this text :)

Problem description:
I need after the first Target profit were offset any remaining orders to break even

In this code after the first profit Target is moved only order 2, but the order is still 3 initial stop loss.

I need to get to breakeven and 3 order

Modify order 3 -2014.6.17-1:28 , together with order 2. This is missing 

Check screen>

I need modify 3 

Order 1 and 2 is OK, but order 3 missing shift to BE 

#property copyright "Copyright 2015"
#property link      ""
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//|                      GLOBALNE PREMENNE                           |
//+------------------------------------------------------------------+
//Money management and position sizing
extern double Profit_Target1_v_pipoch  = 100; //PT1
extern double Stop_Loss_v_pipoch1      = 100; //SL1
extern double Velkost_pozicie1         = 0.50;//LOT1
//
extern double Profit_Target2_v_pipoch  = 200; //PT2
extern double Stop_Loss_v_pipoch2      = 100; //SL2
extern double Velkost_pozicie2         = 0.30;//LOT2
//
extern double Profit_Target3_v_pipoch  = 350; //PT3
extern double Stop_Loss_v_pipoch3      = 100; //SL3
extern double Velkost_pozicie3         = 0.20;//LOT3
//
extern double Posun_na_BE_v_pipoch     = 100;//
//
//STRATEGY 
extern double SMA_Period               = 24;//
//
//********************************************************************
int start()
  {
//+------------------------------------------------------------------+
//|                 DEFINICIA PREMENNYCH NA STARTE                     |
//+------------------------------------------------------------------+

//------
   int Magic_number1 = 1001;                             //ID strategie
   int ticket1, ticket2, ticket3, q, p, modify;   //Premenna pre zadanie prikazu, Pocitadlo
   double SL1 = Stop_Loss_v_pipoch1 * Point;             
   double SL2 = Stop_Loss_v_pipoch2 * Point;
   double SL3 = Stop_Loss_v_pipoch3 * Point;
   double PT1 = Profit_Target1_v_pipoch * Point; 
   double PT2 = Profit_Target2_v_pipoch * Point;
   double PT3 = Profit_Target3_v_pipoch * Point;
   double BE  = Posun_na_BE_v_pipoch * Point;   
   double SMA = iMA(Symbol(), PERIOD_CURRENT, SMA_Period, 0, MODE_SMA, PRICE_CLOSE, 1);//Hodnota SMA
   double C   = iClose(NULL, PERIOD_CURRENT, 0);  //Zisti hodnotu close aktualnej sviecky
   double H   = iHigh(NULL, PERIOD_CURRENT, 0);   //Zisti hodnotu high aktualnej sviecky
   double L   = iLow(NULL, PERIOD_CURRENT, 0);    //Zisti hodnotu low aktualnej sviecky
   double H1  = iHigh(NULL,PERIOD_CURRENT, 1);
   double L1  = iLow(NULL,PERIOD_CURRENT, 1);
   double Spread = MarketInfo(Symbol(), MODE_SPREAD)*Point;
   
   string Text1 = "Position 1";        //Komentar
   string Text2 = "Position 2";
   string Text3 = "Position 3";

//+------------------------------------------------------------------+
//|                          Move on BE                              |
//+------------------------------------------------------------------+       
if (OrderSelect(p, SELECT_BY_POS, MODE_TRADES) && OrderType()==OP_BUY && Bid >= OrderOpenPrice()+BE
   && OrderMagicNumber()==Magic_number1 && OrderStopLoss()!=OrderOpenPrice())
      {modify=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(), 0, Blue);}
if (OrderSelect(p, SELECT_BY_POS, MODE_TRADES) && OrderType()==OP_SELL && Ask >= OrderOpenPrice()+BE
   && OrderMagicNumber()==Magic_number1 && OrderStopLoss()!=OrderOpenPrice())
      {modify=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(), 0, Red);}


//+------------------------------------------------------------------+
//|                   Obmedzovac poctu vstupov                       |
//+------------------------------------------------------------------+
for (q=0;q<OrdersTotal();q++)
   {if(OrderSelect(q, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber()==Magic_number1)
   {return(0);}}
   
//+------------------------------------------------------------------+
//|                       vstup BUY_(long)                           |
//+------------------------------------------------------------------+
    
if ((C>SMA)  )
  {
   //First position/Open 3 position with fix stop loss... 10 pips
   ticket1 = OrderSend(Symbol(), OP_BUYSTOP, Velkost_pozicie1, H1+2*Point+Spread, 0, H1+2*Point+Spread-SL1, 
   H1+2*Point+Spread+PT1,Text1,Magic_number1,iTime(Symbol(),PERIOD_CURRENT, 0)+50000, Blue);
      //If profit 1 is achieved, position 2 is move on breakeven BE
      ticket2 = OrderSend(Symbol(), OP_BUYSTOP, Velkost_pozicie2, H1+2*Point+Spread, 0, H1+2*Point+Spread-SL2, 
      H1+2*Point+Spread+PT2,Text1,Magic_number1,iTime(Symbol(),PERIOD_CURRENT, 0)+50000, Blue);
         
         
         // This is my problem...
         ticket3 = OrderSend(Symbol(), OP_BUYSTOP, Velkost_pozicie3, H1+2*Point+Spread, 0, H1+2*Point+Spread-SL3, 
         H1+2*Point+Spread+PT2,Text1,Magic_number1,iTime(Symbol(),PERIOD_CURRENT, 0)+50000, Blue);
   //*******************************************************************************************   
   //*******************************************************************************************
   //Problem is>
      // when you reach the profit target_1, so the BE is moved only position 2, 
      // third position but remains at -10 pips stop loss
      // and I will need to get to BE with position two
      // so if I reach profit on position 1, the remaining positions need to move to breakeven
      
   }

   return(0);
  }

 If you understand me, thank you for your answer :)

 

Mat 

 
if (OrderSelect(p, SELECT_BY_POS, MODE_TRADES) && OrderType()==OP_BUY && Bid >= OrderOpenPrice()+BE
I don't see that p is initialised with a value anywhere.
Reason: