Unsure why this code isn't placing orders

 
Looking for feedback on this code. As of right now it complies but it doesn't execute trades in the strategy tester. Any help is much appreciated
double SARValue;
double SimpleEma;
double Candle;
double Candle2; 

void OnTick()
  {
  
  if ((OrdersTotal()==0) && (SARValue > Bid) &&(Candle < SimpleEma) && (Candle > superTrend()))
  OrderSend (_Symbol, OP_SELL, .10, Bid, 10, 0, 0, NULL, 0, 0, Green);
  
  SARValue = iSAR(_Symbol, 0, 0.02, 0.2,0);
  SimpleEma = iMA(_Symbol, 0, 100, 0, MODE_SMA, PRICE_CLOSE, 1);
  Candle = iClose(NULL, 0, 1);
  Candle2 = iClose(NULL,0, 2);
  
  if (SARValue>Bid)
  CheckSARSellStop();

   
  }
  
  void CheckSARSellStop()
   {
      //going through all open orders
      for (int b= OrdersTotal()-1;b>=0;b--)
      
      {
         //select the order
         if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
            //check the order symbol
            if (OrderSymbol() ==Symbol())
            //check if we are in a buy trade
            if (OrderType() ==OP_SELL)
               {
                  //if the sl is below the sar value
                  if ((OrderStopLoss() > SARValue) || (OrderStopLoss() ==0))
                  
                     //adjust the sl
                     OrderModify(
                                    OrderTicket(),       //for the current order
                                    OrderOpenPrice(),    //for the open price we had
                                    SARValue,            //set the sl
                                    OrderTakeProfit(),   //for the unchanged tp
                                    0,                   //no expiration
                                    CLR_NONE             //no color
                                );
               }
      }
   }
//+------------------------------------------------------------------+

double superTrend()
   {
      double superTrend = iCustom(_Symbol, _Period, "Super_Trend", PRICE_CLOSE, 0,0);
      
      return superTrend;
   }

 
Tiberious:
Looking for feedback on this code. As of right now it complies but it doesn't execute trades in the strategy tester. Any help is much appreciated
double SARValue;
double SimpleEma;
double Candle;
double Candle2; 

void OnTick()
  {
  SARValue = iSAR(_Symbol, 0, 0.02, 0.2,0);
  SimpleEma = iMA(_Symbol, 0, 100, 0, MODE_SMA, PRICE_CLOSE, 1);
  Candle = iClose(NULL, 0, 1);
  Candle2 = iClose(NULL,0, 2);
  if ((OrdersTotal()==0) && (SARValue > Bid) &&(Candle < SimpleEma) && (Candle > superTrend()))
  OrderSend (_Symbol, OP_SELL, .10, Bid, 10, 0, 0, NULL, 0, 0, Green);
  
  
  
  if (SARValue>Bid)
  CheckSARSellStop();

   
  }
  
  void CheckSARSellStop()
   {
      //going through all open orders
      for (int b= OrdersTotal()-1;b>=0;b--)
      
      {
         //select the order
         if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
            //check the order symbol
            if (OrderSymbol() ==Symbol())
            //check if we are in a buy trade
            if (OrderType() ==OP_SELL)
               {
                  //if the sl is below the sar value
                  if ((OrderStopLoss() > SARValue) || (OrderStopLoss() ==0))
                  
                     //adjust the sl
                     OrderModify(
                                    OrderTicket(),       //for the current order
                                    OrderOpenPrice(),    //for the open price we had
                                    SARValue,            //set the sl
                                    OrderTakeProfit(),   //for the unchanged tp
                                    0,                   //no expiration
                                    CLR_NONE             //no color
                                );
               }
      }
   }
//+------------------------------------------------------------------+

double superTrend()
   {
      double superTrend = iCustom(_Symbol, _Period, "Super_Trend", PRICE_CLOSE, 0,0);
      
      return superTrend;
   }
 
Mehmet Bastem #:

Just tried switching where the if statement was. Still doesn't execute the trade. Could it just be the tester?

 
Tiberious #:

Just tried switching where the if statement was. Still doesn't execute the trade. Could it just be the tester?

your question was that it didn't work in the strategy test. I tried it works. If real or demo doesn't work, you need to fix your code. for instance

  double superTrend = iCustom(_Symbol, _Period, "Super_Trend", PRICE_CLOSE, 0,0);

expression

  double superTrend = iCustom(_Symbol, _Period, "Super_Trend", PRICE_CLOSE, 0,1);

You can try changing it to .

dd

 
Mehmet Bastem #:

your question was that it didn't work in the strategy test. I tried it works. If real or demo doesn't work, you need to fix your code. for instance

  double superTrend = iCustom(_Symbol, _Period, "Super_Trend", PRICE_CLOSE, 0,0);

expression

  double superTrend = iCustom(_Symbol, _Period, "Super_Trend", PRICE_CLOSE, 0,1);

You can try changing it to .


 
So its working for you but not me. Is that still a code issue?
Reason: