How to access the second if clause

 

I am totally drain out. I took few hours to find out why the program wont enter the second if clause.

Any skillful programmer wanna give a shot?

if(TodayVolatilityPercentage>=90&&(dayTrend==1)&&orderOpened==false)
      {
         Print("Entered if clause");
         ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0*Point,0*Point,NULL,MagicNumber,0,Blue);
         orderOpened=true;
         if(TodayVolatilityPercentage>=110) orderOpened=false;
           
      }
      if(TodayVolatilityPercentage>=110&&(dayTrend==1)&&orderOpened==false)
      {
         Print("Entered second if clause");
         ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0*Point,0*Point,NULL,MagicNumber,0,Blue);
         orderOpened=true;
         
      
      }
 
if(TodayVolatilityPercentage>=90&&(dayTrend==1)&&orderOpened==false)
  {
   Print("Entered if clause");
   ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0*Point,0*Point,NULL,MagicNumber,0,Blue);
    orderOpened=true;
  }





if(TodayVolatilityPercentage>=110) orderOpened=false;
  {
   //???????
  }         
      



     
if(TodayVolatilityPercentage>=110&&(dayTrend==1)&&orderOpened==false)
  {
   Print("Entered second if clause");
   ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0*Point,0*Point,NULL,MagicNumber,0,Blue);
   orderOpened=true;
  }
 
if(TodayVolatilityPercentage>=90&&(dayTrend==1)&&orderOpened==false)
  {
   Print("Entered if clause");
   ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0*Point,0*Point,NULL,MagicNumber,0,Blue);
    orderOpened=true;
  }





if(TodayVolatilityPercentage>=110)
  {
   orderOpened=false;
  }         
      



     
if(TodayVolatilityPercentage>=110&&(dayTrend==1)&&orderOpened==false)
  {
   Print("Entered second if clause");
   ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0*Point,0*Point,NULL,MagicNumber,0,Blue);
   orderOpened=true;
  }


What are the conditions

 
if(TodayVolatilityPercentage>=90&&(dayTrend==1)&&orderOpened==false)
  {
   Print("Entered if clause");
   ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0*Point,0*Point,NULL,MagicNumber,0,Blue);
    orderOpened=true;

  if(TodayVolatilityPercentage>=110)
    {
     orderOpened=false;
    } 
  }


if(TodayVolatilityPercentage>=110&&(dayTrend==1)&&orderOpened==false)
  {
   Print("Entered second if clause");
   ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0*Point,0*Point,NULL,MagicNumber,0,Blue);
   orderOpened=true;
  }
 
so if
TodayVolatilityPercentage>=90


orderOpened= set to true,


but if

TodayVolatilityPercentage>=110


it is also >90 so orderOpened will always be set to true before encountering the second if statement if>=110

 
Marco vd Heijden:
      if(TodayVolatilityPercentage>=90&&(dayTrend==1)&&orderOpened==false)
      {
         Print("Entered if clause");
         ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0*Point,0*Point,NULL,MagicNumber,0,Blue);
         orderOpened=true;
         if(TodayVolatilityPercentage>=110) orderOpened=false;
           
      }
      if(TodayVolatilityPercentage>=110&&(dayTrend==1)&&orderOpened==false)
      {
         Print("Entered second if clause");
         ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0*Point,0*Point,NULL,MagicNumber,0,Blue);
         orderOpened=true;
         
      
      }
my point is if the volatility reaches 90 percent, the ea will place one and only one order,  and it will stop and listen till the volatility reaches 110 to place the second order. However, for my program when I am doing back testing, it will never enter the second if clause which means the ea will never place the second order even if the volatility reaches 110
 

because if it reaches 110 it is also above 90 and it will always execute the first if statement first setting orderOpened to true and it can never enter the second because of that.

 
Marco vd Heijden:

because if it reaches 110 it is also above 90 and it will always execute the first if statement first setting orderOpened to true and it can never enter the second because of that.

Thank you for your explanation. Now I start wondering that is it able to modify this program and achieve my point above "if the volatility reaches 90 percent, the ea will place one and only one order,  and it will stop and listen till the volatility reaches 110 to place the second order."

 

if you only remove the > is greater then it should work, but only on the exact points of interest namely 90 and 110.

if you want to modify you write for the first instance VolatilityPercentage>=90 BUT ALSO <110

if(TodayVolatilityPercentage>=90 && TodayVolatilityPercentage<110) 


to isolate the event.

 
Marco vd Heijden:

if you only remove the > is greater then it should work, but only on the exact points of interest namely 90 and 110.

if you want to modify you write for the first instance VolatilityPercentage>=90 BUT ALSO <110


to isolate the event.

Well, it solves the range problem, but how to control the EA to place one and only one order. Because if the EA detects the prices within the range 90-110, it will place countless order.
 

you can also use something like

if(OrdersTotal==0)
 {
  //Do Something...
 }


if(OrdersTotal==1)
 {
  //Do Something else...
 }

if(OrdersTotal==2)
 {
  //Do...
 }


or you can

switch (OrdersTotal())

case 0:

break;

case 1:

break

case 2:

break;


and etc. to give few examples

Reason: