Duplicate lots when order hit stop loss

 

Hi i have a problem i write this and nothing change, the lots dont duplicate,why?

help me please.

#define PivotPoint "PivotPoint"
#define PivotPoint_P 0
extern int tp=25;
extern int sl=100;
extern double lotti=0.10;
extern bool TENKANSEN;
input int InpTenkan=9;   // Tenkan-sen
input int InpKijun=26;   // Kijun-sen
input int InpSenkou=52 ;
#define Ichimoku "Ichimoku"
#define Ichimoku_ExtTenkanBuffer 0
extern int margin=200;

extern int bho = 1;
datetime LastActiontime;
   
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

void OnTick()
  {


double  DailyPivot  = iCustom( _Symbol, PERIOD_D1, "PivotPoint", bho, PivotPoint_P, 0 );
double  Tenkan  = iCustom( _Symbol, PERIOD_CURRENT, "Ichimoku", InpTenkan,InpKijun,InpSenkou, Ichimoku_ExtTenkanBuffer, 0 );

double OpenBuyRange;
double OpenSellRange;
OpenBuyRange=DailyPivot+margin*Point;
OpenSellRange=DailyPivot-margin*Point;


double sellstoploss=Bid+(sl*Point);
double buystoploss=Ask-(sl*Point);





 // int i=OrdersHistoryTotal()-1;


if(OrdersTotal()==0){

if (Hour()>2){

//if(TENKANSEN){  


   if(LastActiontime!=Time[0] && Close[1]>= DailyPivot && Close[1]<= OpenBuyRange && DailyPivot >= Open[1] && Close[1]>= Tenkan ){
   


      
      int ticket = OrderSend(Symbol(),OP_BUY,lotti,Ask,3,buystoploss,Ask+(tp*Point),"Buy Order",0,0,Blue);
      
      
   if( OrderSelect(ticket,SELECT_BY_TICKET,MODE_HISTORY)){
    if(OrderClosePrice()==OrderStopLoss()) lotti=lotti*2;
}
         
      LastActiontime=Time[0];
     }
  
       if(LastActiontime!=Time[0] && Close[1]<= DailyPivot && Close[1] >= OpenSellRange && DailyPivot <= Open[1] && Close[1]<= Tenkan  ){

          

      //Code to execute once in the bar
     int ticket = OrderSend(Symbol(),OP_SELL,lotti,Bid,3,sellstoploss,Bid-(tp*Point) ,"Sell Order",0,0,Blue);
     
           if( OrderSelect(ticket,SELECT_BY_TICKET,MODE_HISTORY)){
    if(OrderClosePrice()==OrderStopLoss()) lotti=lotti*2;
}
  
  
      
      LastActiontime=Time[0];
     }
      
  
}



      
      
  
  
}

  
  
    /* else if (TENKANSEN==false){
      
       if(LastActiontime!=Time[0] && Close[1]>= DailyPivot && Close[1]<= OpenRange && DailyPivot >= Open[1] ){
       
        int ticket = OrderSend(Symbol(),OP_BUY,lotti,Ask,3,Ask-(sl*Point),Ask+(tp*Point),"Buy Order",0,0,Blue);
      
      LastActiontime=Time[0];
  }
  
  

      
      
       if(LastActiontime!=Time[0] && Close[1]<= DailyPivot && Close[1] >= OpenRange && DailyPivot <= Open[1] ){
         int ticket = OrderSend(Symbol(),OP_SELL,lotti,Bid,3,Bid+(sl*Point),Bid-(tp*Point) ,"Sell Order",0,0,Blue);
      
      LastActiontime=Time[0];
       }
      
      
      }
  
  }
  }

  
*/

  }
 

Ok i resolve my problem,now i have an another problem :

error 131... But my lot is exactly, I made code errors?

//+------------------------------------------------------------------+
//|                                                checkbarclose.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
#define PivotPoint "PivotPoint"
#define PivotPoint_P 0
extern int tp=25;
extern int sl=100;
extern double lotti=0.10;

extern bool TENKANSEN;
input int InpTenkan=9;   // Tenkan-sen
input int InpKijun=26;   // Kijun-sen
input int InpSenkou=52 ;
extern double x=0.10;
#define Ichimoku "Ichimoku"
#define Ichimoku_ExtTenkanBuffer 0
extern int margin=200;

extern int bho = 1;
datetime LastActiontime;
   
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

void OnTick()
  {


double  DailyPivot  = iCustom( _Symbol, PERIOD_D1, "PivotPoint", bho, PivotPoint_P, 0 );
double  Tenkan  = iCustom( _Symbol, PERIOD_CURRENT, "Ichimoku", InpTenkan,InpKijun,InpSenkou, Ichimoku_ExtTenkanBuffer, 0 );

double OpenBuyRange;
double OpenSellRange;
OpenBuyRange=DailyPivot+margin*Point;
OpenSellRange=DailyPivot-margin*Point;


double sellstoploss=Bid+(sl*Point);
double buystoploss=Ask-(sl*Point);





 // int i=OrdersHistoryTotal()-1;


if(OrdersTotal()==0){

if (Hour()>2){

//if(TENKANSEN){  


   if(LastActiontime!=Time[0] && Close[1]>= DailyPivot && Close[1]<= OpenBuyRange && DailyPivot >= Open[1] && Close[1]>= Tenkan ){
   


      
      int ticket = OrderSend(Symbol(),OP_BUY,x,Ask,3,buystoploss,Ask+(tp*Point),"Buy Order",0,0,Blue);
      
  /*    
   if( OrderSelect(ticket,SELECT_BY_POS,MODE_HISTORY)){
    if(OrderClosePrice()==OrderStopLoss()) lotti=lotti*2;
}*/
         
      LastActiontime=Time[0];
     }
  
       if(LastActiontime!=Time[0] && Close[1]<= DailyPivot && Close[1] >= OpenSellRange && DailyPivot <= Open[1] && Close[1]<= Tenkan  ){

          

      //Code to execute once in the bar
     int ticket = OrderSend(Symbol(),OP_SELL,x,Bid,3,sellstoploss,Bid-(tp*Point) ,"Sell Order",0,0,Blue);
     
         /*  if( OrderSelect(ticket,SELECT_BY_POS,MODE_HISTORY)){
    if(OrderClosePrice()==OrderStopLoss()) lotti=lotti*2;
}*/
  
  
      
      LastActiontime=Time[0];
     }
      
  
}



      
      
  
  
}

  int cnt;
//

cnt=OrdersHistoryTotal()-1;
//
//

while (cnt>=0)
{
if (OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))
  {
   if (OrderStopLoss() == OrderClosePrice()) x=x+x;


   cnt--;
  }
  
}
  
    /* else if (TENKANSEN==false){
      
       if(LastActiontime!=Time[0] && Close[1]>= DailyPivot && Close[1]<= OpenRange && DailyPivot >= Open[1] ){
       
        int ticket = OrderSend(Symbol(),OP_BUY,lotti,Ask,3,Ask-(sl*Point),Ask+(tp*Point),"Buy Order",0,0,Blue);
      
      LastActiontime=Time[0];
  }
  
  

      
      
       if(LastActiontime!=Time[0] && Close[1]<= DailyPivot && Close[1] >= OpenRange && DailyPivot <= Open[1] ){
         int ticket = OrderSend(Symbol(),OP_SELL,lotti,Bid,3,Bid+(sl*Point),Bid-(tp*Point) ,"Sell Order",0,0,Blue);
      
      LastActiontime=Time[0];
       }
      
      
      }
  
  }
  }

  
*/

  }
  

  
  
  
  
  
  
//+------------------------------------------------------------------+
Reason: