Define Pause if a specific condition is fulfilled

 

Hello Guys,

I am currently struggling with a function, that has to introduce pause into my trading system. The idea is pretty simple, if the rsx value is above 90, ea has to stop trading for a defined number of bars. Here is a part of my script. What am I doing wrong? Is there is simple solution for the problem?


if (tradeEnabled == true &&newBar == true && iBarShift(NULL,0, SignalTime) > WaitXBars)  

      {

      if (rsx[0]>SellLevel)

      SellSignal=1;

         {              

            if(OrderSell<1 && SellSignal==1 && rsx[0]<rsx[1])

               {

               OPSELL();

               SellSignal=0;

               }

            }

      if (rsx[0]<BuyLevel)

      BuySignal=1;

         {

            if(OrderBuy<1 && BuySignal==1 && rsx[0]>rsx[1])

               { 

               OPBUY();

               BuySignal=0;

               }

      if (rsx[0] < CritBuyLevel && rsx[0] > CritSellLevel)

         {

         SignalTime=TimeCurrent();

         Print("starting to wait");

         }

       }
 
Igor Polushkin:

Hello Guys,

I am currently struggling with a function, that has to introduce pause into my trading system. The idea is pretty simple, if the rsx value is above 90, ea has to stop trading for a defined number of bars. Here is a part of my script. What am I doing wrong? Is there is simple solution for the problem?


Hello,

You could delay it by checking another bar than the 2 lasts with your rsi : 

 if(OrderSell<1 && SellSignal==1 && rsx[10]<rsx[11]) <--- will check for a signal at the 10th and 11th bar, rather than the two last (0&1) it's an example

Edit : 

      if (rsx[0] < CritBuyLevel && rsx[0] > CritSellLevel)
         {
         SignalTime=TimeCurrent();
         Print("starting to wait");
         }

This will never happen also ... you won't have the last rsx superior to critselllevel & inferior to critbuylevel simultaneously.

      if (rsx[0] < CritBuyLevel || rsx[0] > CritSellLevel)
         {
         SignalTime=TimeCurrent();
         Print("starting to wait");
         }
Try it so
 
Igor Polushkin: What am I doing wrong? Is there is simple solution for the problem?
if (tradeEnabled == true &&newBar == true && iBarShift(NULL,0, SignalTime) > WaitXBars)  

Is SignalTime a global or static variable?

Reason: