How to validate a signal... help needed

 

Hi,


I have a signal if price cross a level.

before entering... I would check if market can sustain this level for 10 sec at least.


 //--------
 if( lastTradeTime != Time[THIS_BAR] ){
       lastTradeTime = Time[THIS_BAR];
       datetime Duration = 0;} 
 
 if (Duration == 0) {
 if ( Bid > highValue || Bid < lowValue ) {Duration  = TimeCurrent(); }
 }


// Logic open order

     if (countTrades() == 0 && Short_Scalping && TimeCurrent() - Short_lastclosedtime > Time_btw_2_Short_Min*60 
      && TimeCurrent()-Duration>=10 // When I had this... it's not working
      )
      {openShortTrade();
       }


Cheers

 
Why not just Sleep for 10 seconds and then check the values again?
 
FrenchyTrader: before entering... I would check if market can sustain this level for 10 sec at least.
 if ( Bid > highValue || Bid < lowValue ) {Duration  = TimeCurrent(); }
How are you going to test for a duration? You only check Bid above HV once per bar and once it is, you've lost any previous "duration" so there is nothing to test with. You use a local variable, so once you return the value is lost. "Duration" is a datetime so it can't be a duration (elapsed time,) use better variable names. You need something more like
static datetime lastBreakout = 0;
if ( Bid <= highValue && Bid >= lowValue ) lastBreakout = 0; // No longer
else{                                                        // Breakout.
   if(lastBreakout == 0) lastBreakout = TimeCurrent();       // first one
   else if(                                                  // still going.
      TimeCurrent()-Duration>=10 // When I had this... it's not working
   && countTrades() == 0 
   && Short_Scalping 
   && TimeCurrent() - Short_lastclosedtime > Time_btw_2_Short_Min*60 
      ){
      openShortTrade();
      }
}
 
Ok thank you
Reason: