Download MetaTrader 5
To add comments, please log in or register
How to test a program before buying?
phoenix1911
77
phoenix1911 2015.10.01 14:45 

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;
         
      
      }
Marco vd Heijden
Moderator
4506
Marco vd Heijden 2015.10.01 15:00  
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;
  }
Marco vd Heijden
Moderator
4506
Marco vd Heijden 2015.10.01 15:01  
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

Marco vd Heijden
Moderator
4506
Marco vd Heijden 2015.10.01 15:06  
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;
  }
Marco vd Heijden
Moderator
4506
Marco vd Heijden 2015.10.01 15:08  
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

phoenix1911
77
phoenix1911 2015.10.01 15:12  
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
Marco vd Heijden
Moderator
4506
Marco vd Heijden 2015.10.01 15:20  

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.

phoenix1911
77
phoenix1911 2015.10.01 15:26  
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."

Marco vd Heijden
Moderator
4506
Marco vd Heijden 2015.10.01 16:01  

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.

phoenix1911
77
phoenix1911 2015.10.01 16:30  
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.
Marco vd Heijden
Moderator
4506
Marco vd Heijden 2015.10.01 16:38  

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

/ /12
To add comments, please log in or register