Counting candles from trigger.

 

HI,

I have a few indicators that I set a Global trigger to  eg  TriggerHit=Sell.

What I am trying to do is count the candles after the trigger so that I can reset the Trigger to=Null.

I have looked at iBarShift,  I also need to have it run the routine only once per candle/tick. 


nBars=iBarShift(Symbol(), PERIOD_H4, TimeCurrent(), false);

static datetime candle_time;
if(Time[0]==candle_time)return;
if (nBars==2) {Print("Trigger cleared =", nBars);}
                else{nBars=nBars++;}

i've probably got it completely wrong.

1) Check that its a new candle before doing the function.

2) Counting the candles after trigger is set.


Any help is gratefully appreciated.

Reason: