orders not open

 

Hi I had this code

it open 2 orders before

right now order 1 is work but order 2 not open  please help


//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   if (!IsTester) MainFunction();
   
  }  
  
void MainFunction()
{
   if (!TimeFilter()) return;
   
   if(UseTStop && TrailingStartInPoints>0 && TrailingStopInPoints>0 && TrailingStepInPoints>0)   TrailStop();

   if(BreakevenInPoints>0)   BreakEven();
   int shift=1;

/*
Comment(TrendProValue(_Symbol, PERIOD_CURRENT, TrendPro_BuySignal_Buffer, 1)
        ,"\n", TrendProValue(_Symbol, PERIOD_CURRENT, TrendPro_SellSignal_Buffer, 1)
        ,"\n", TrendProValue(_Symbol, PERIOD_CURRENT, TrendPro_TP1_Buffer, 1)
        ,"\n", TrendProValue(_Symbol, PERIOD_CURRENT, TrendPro_TP2_Buffer, 1)
        ,"\n", TrendProValue(_Symbol, PERIOD_CURRENT, TrendPro_SuccessRate_Buffer, 1)
       );
return;*/
   for (int SymbolNum = 0; SymbolNum < NumOfSymbols; SymbolNum++)
   {
   string symbol = SymbolArray[SymbolNum];
   
   for (int TFNum = 0; TFNum < TimeframesCount; TFNum++)
   {
      ENUM_TIMEFRAMES Timeframe = TFArray[TFNum];
      
   DeleteByDuration(PendingOrderExpirationMinutes * 60,SymbolArray[SymbolNum]);
      if (LastCandleTime[SymbolNum][TFNum] != iTime(SymbolArray[SymbolNum], TFArray[TFNum], 0))
      {         
         LastCandleTime[SymbolNum][TFNum] = iTime(SymbolArray[SymbolNum], TFArray[TFNum], 0);
         
         if (SymbolInfoInteger(symbol, SYMBOL_SPREAD) > MaxSpread) continue;
         
         int SignalBarShift = 0, SignalType = -1;
         
         {
         int i = 1, bars = iBars(symbol, Timeframe);
         while (i < bars) 
         {
            if (MainTrendProValue(symbol, Timeframe, TrendPro_SuccessRate_Buffer, i) >= MinSuccessRate)
            {
               if (MainTrendProValue(symbol, Timeframe, TrendPro_BuySignal_Buffer, i) > 0)
 {if(Order_Type==Instant_Order){SignalBarShift = i; SignalType = OP_BUY; break;}else {SignalBarShift = i; SignalType = OP_BUYLIMIT; break;}}
               if (MainTrendProValue(symbol, Timeframe, TrendPro_SellSignal_Buffer, i) > 0)
 {if(Order_Type==Instant_Order){SignalBarShift = i; SignalType = OP_SELL; break;}else {SignalBarShift = i; SignalType = OP_SELLLIMIT; break;}}
            }
            i++;
         }
         if (SignalBarShift == 0) continue;
         }
         
         bool AlreadyExist = PositionAlreadyExistAndClosePositionsBefore(SymbolNum, TFNum, iTime(symbol, Timeframe, SignalBarShift));
         
         TP[SymbolNum][TFNum][TPNum0] = MainTrendProValue(symbol, Timeframe, TrendPro_TP1_Buffer, SignalBarShift);
         TP[SymbolNum][TFNum][TPNum1] = MainTrendProValue(symbol, Timeframe, TrendPro_TP2_Buffer, SignalBarShift);
         
         TP[SymbolNum][TFNum][2] = Pivot(symbol, Timeframe, R1, shift);
         TP[SymbolNum][TFNum][3] = Pivot(symbol, Timeframe, R2, shift);
         TP[SymbolNum][TFNum][4] = Pivot(symbol, Timeframe, R3, shift);
         TP[SymbolNum][TFNum][5] = Pivot(symbol, Timeframe, R4, shift);

         TP[SymbolNum][TFNum][6] = Pivot(symbol, Timeframe, S1, shift);
         TP[SymbolNum][TFNum][7] = Pivot(symbol, Timeframe, S2, shift);
         TP[SymbolNum][TFNum][8] = Pivot(symbol, Timeframe, S3, shift);
         TP[SymbolNum][TFNum][9] = Pivot(symbol, Timeframe, S4, shift);

         if (!AlreadyExist && SignalBarShift == 1 
             && ATRFilterCheck(symbol, Timeframe, SignalType)
             && ADXFilterCheck(symbol, Timeframe, SignalType)
             && MACDFilterCheck(symbol, Timeframe, SignalType)
             && MomentumFilterCheck(symbol, Timeframe, SignalType)
             && ADXFilterCheck(symbol, Timeframe, SignalType)
             && RSIFilterCheck(symbol, Timeframe, SignalType)
             && StochasticFilterCheck(symbol, Timeframe, SignalType)
             && EasyTrend_FilterCheck(symbol, EasyTrend_Timeframe, SignalType)
             && IdentifyTrend_FilterCheck(symbol, IdentifyTrend_Timeframe, SignalType)
             && (!UseOtherTrendProFilter || FilterTrendProValue(symbol, Timeframe, (SignalType == OP_BUY ? TrendPro_UpTrend_Buffer :TrendPro_DownTrend_Buffer), 1) > 0)
             && (!UseHigherTFTrendProFilter 
                 ||
                 (HigherTFFilterTrendProValue(symbol, HTFArray[TFNum], (SignalType == OP_BUY ? TrendPro_UpTrend_Buffer :TrendPro_DownTrend_Buffer), 1) > 0
                  && HigherTFFilterTrendProValue(symbol, HTFArray[TFNum], TrendPro_SuccessRate_Buffer, 1) >= HigherTF_MinSuccessRate
                 )
                )
            )
         {
            int digit = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
    double sfx1,sfx2;
   double tfx1,tfx2;
 double price;
          
            //-- TP1
            if (VolumeRatioOfTP1 > 0 && VolumeRatioOfTP1 <= 100)
            {
               string comment = EnumToString(Timeframe)+",TP1";
            if(Order_Type==Instant_Order) price = (SignalType == OP_BUY ? SymbolInfoDouble(symbol, SYMBOL_ASK) : SymbolInfoDouble(symbol, SYMBOL_BID));
            else price = (SignalType == OP_BUYLIMIT ? SymbolInfoDouble(symbol, SYMBOL_BID) - offset : SymbolInfoDouble(symbol, SYMBOL_ASK) + offset);
if (SignalType == OP_BUY||SignalType == OP_BUYLIMIT)
  {
int zs1=(int)ssl1();
if(SL1_Type==SL1_Pipvalue && SL1_PipValue > 0)sfx1 = price - SL1_PipValue/PriceToPip(symbol);
else if(SL1_Type==SL1_Pivotpoint)sfx1 = TP[SymbolNum][TFNum][zs1]; 

if(TP1_Type==TP1_Pip && TP1_PipValue > 0)tfx1=price + TP1_PipValue/PriceToPip(symbol);
else if(TP1_Type==TP1_TrendPro) tfx1=TP[SymbolNum][TFNum][TPNum0];
else if(TP1_Type==TP1_Pivotpoint)tfx1=TP[SymbolNum][TFNum][Pivot_TP1];
else tfx1=0;
   }
else 
{
int ys=(int)Stp1();
int zs=(int)ssl1();

if(SL1_Type==SL1_Pipvalue  && SL1_PipValue > 0)sfx1 = price + SL1_PipValue/PriceToPip(symbol);
else if(SL1_Type==SL1_Pivotpoint)sfx1 = TP[SymbolNum][TFNum][zs]; 
if(TP1_Type==TP1_Pip && TP1_PipValue > 0)tfx1=price - TP1_PipValue/PriceToPip(symbol);
else  if(TP1_Type==TP1_TrendPro) tfx1=TP[SymbolNum][TFNum][TPNum0];
else  if(TP1_Type==TP1_Pivotpoint)tfx1=TP[SymbolNum][TFNum][ys];
else tfx1=0;
}
double lotSize;
if(LotType==UseFixedLot)lotSize=FixedLot_1;else lotSize=Lots(symbol, VolumeRatioOfTP1*0.01);
               int ticket = myOrderSend(symbol,SignalType,price,sfx1,tfx1,FixedLot_1,comment);
 //              int ticket = OrderSend(symbol, SignalType,FixedLot_2 , price, Slippage, sfx1, tfx1, comment, MagicNumber, 0);
               if (ticket <= 0) SendAlert("Error: Position not opened, ErrorCode: "+(string)GetLastError() + " :: " + "price: " + DoubleToString(price, digit) + " TP1 " + " pair: " + symbol + " Timeframe: " + EnumToString(Timeframe) + " " + (SignalType == OP_BUY ? "Buy" : "Sell"));
               else 
               {
                  OpenPosTicket[SymbolNum][TFNum][TPNum0] = ticket; if (SignalType == OP_SELL) OpenPosTicket[SymbolNum][TFNum][TPNum0] *= -1;
                  SendAlert("Position #"+(string)ticket+" opened :: " + "price: " + DoubleToString(price, digit) + " TP1: " + DoubleToString(tfx1, digit) + " pair: " + symbol + " Timeframe: " + EnumToString(Timeframe) + " " + (SignalType == OP_BUY ? "Buy" : "Sell"));
               }
            }
            //-- TP2
    if (100-VolumeRatioOfTP2 > 0 && 100-VolumeRatioOfTP2 <= 100)
            {
            string comment = EnumToString(Timeframe)+",TP2";
            if(Order_Type==Instant_Order) price = (SignalType == OP_BUY ? SymbolInfoDouble(symbol, SYMBOL_ASK) : SymbolInfoDouble(symbol, SYMBOL_BID));
            else price = (SignalType == OP_BUYLIMIT ? SymbolInfoDouble(symbol, SYMBOL_BID) - offset : SymbolInfoDouble(symbol, SYMBOL_ASK) + offset);
if (SignalType == OP_BUY||SignalType == OP_BUYLIMIT)
  {
int zs=(int)ssl2();
if(SL2_Type==SL2_Pipvalue  && SL2_PipValue > 0)sfx2 = price - SL2_PipValue/PriceToPip(symbol);
else if(SL2_Type==SL2_Pivotpoint)sfx2 = TP[SymbolNum][TFNum][zs]; 

if(TP2_Type==TP2_Pip  && TP2_PipValue > 0)tfx2=price + TP2_PipValue/PriceToPip(symbol);
else if(TP2_Type==TP2_TrendPro) tfx2=TP[SymbolNum][TFNum][TPNum1];
else if(TP2_Type==TP2_Pivotpoint)tfx2=TP[SymbolNum][TFNum][Pivot_TP2];
else tfx2=0;
  }
else
{
int ys2=(int)Stp2();
int zs2=(int)ssl2();
if(SL2_Type==SL2_Pipvalue && SL2_PipValue > 0)sfx2 = price + SL2_PipValue/PriceToPip(symbol);
else if(SL2_Type==SL2_Pivotpoint)sfx2 = TP[SymbolNum][TFNum][zs2]; 

if(TP2_Type==TP2_Pip && TP2_PipValue > 0)tfx2=price - TP2_PipValue/PriceToPip(symbol);
else if(TP2_Type==TP2_TrendPro) tfx2=TP[SymbolNum][TFNum][TPNum1];
else if(TP2_Type==TP2_Pivotpoint)tfx2=TP[SymbolNum][TFNum][ys2];
else tfx2=0;
}
double lotSize;
if(LotType==UseFixedLot)lotSize=FixedLot_2;else lotSize=Lots(symbol, VolumeRatioOfTP2*0.01);
               int ticket = myOrderSend(symbol,SignalType,price,sfx2,tfx2,FixedLot_2,comment);
         //      int ticket = OrderSend(symbol, SignalType,FixedLot_2 , price, Slippage, sfx2, tfx2, comment, MagicNumber, 0);
               if (ticket <= 0) SendAlert("Error: Position not opened, ErrorCode: "+(string)GetLastError() + " :: " + "price: " + DoubleToString(price, digit) + " TP2: " + " pair: " + symbol + " Timeframe: " + EnumToString(Timeframe) + " " + (SignalType == OP_BUY ? "Buy" : "Sell"));
               else 
               {
                  
                  OpenPosTicket[SymbolNum][TFNum][TPNum1] = ticket; if (SignalType == OP_SELL) OpenPosTicket[SymbolNum][TFNum][TPNum1] *= -1;
                  SendAlert("Position #"+(string)ticket+" opened :: " + "price: " + DoubleToString(price, digit) + " TP2: " + DoubleToString(tfx2, digit) + " pair: " + symbol + " Timeframe: " + EnumToString(Timeframe) + " " + (SignalType == OP_BUY ? "Buy" : "Sell"));
               }
            }
         }
      }
      //-- Check TP

   }
   }
   
   //-- Check TP1/SL
 if (SL1_AmountValue > 0 || SL2_AmountValue > 0 || TP1_Type == TP1_AmountValue || TP2_Type == TP2_AmountValue)
   {
      int total = OrdersTotal();
      for (int i = total-1; i >= 0; i--)
      {
      if (OrderSelect(i, SELECT_BY_POS) && OrderMagicNumber() == MagicNumber && OrderType() < 2
          && 
          ((SL1_AmountValue > 0 && OrderProfit() <= -SL1_AmountValue)||(SL2_AmountValue > 0 && OrderProfit() <= -SL2_AmountValue)
           ||
(StringFind(OrderComment(), ",TP1") > 0 &&(TP1_Type == TP1_Amount && OrderProfit() >= TP1_AmountValue)) || (StringFind(OrderComment(), ",TP2") > 0 &&(TP2_Type == TP2_Amount && OrderProfit() >= TP2_AmountValue))
          )
         )
      {
         if (!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), Slippage)) SendAlert("Error: positon #"+(string)OrderTicket()+" not closed, ErrorCode:"+(string)GetLastError());
      }
      }
   }      
   
 
Hussein Alebrahimi:please help

Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?

Reason: