I tryed in another way, but it caused a bug on my PC (lol).
if(UP_Trend_Beggining[i]==1) { while(DOWN_Trend_Beggining[i]==0) { UpShift++; } if(Close[i]>BuyTrailingStop[i]) { UP_Trend[i]=UpShift; } } if(DOWN_Trend_Beggining[i]==1) { while(UP_Trend_Beggining[i]==0) { DownShift++; } if(Close[i]<BuyTrailingStop[i]) { DOWN_Trend[i]=DownShift; } }
rodrigosm:
I would like to count bars since an event occurs. I used a flag showing the time of the event and I insert it on the formula iBarShift.
if(Close[i+1]<=BuyTrailingStop[i+1] && Close[i]>BuyTrailingStop[i]) { // UP_Trend_Beggining[i]=Time[i]; // Buy Flag // The number of bars since this event is: i }
WHRoeder:
Thanks, it worked well... but now I don't known what is the function of iBarShift.... I thought it was to count periods since a specified time!
int iBarShift( string symbol, int timeframe, datetime time, bool exact=false)
Search for bar by open time. The function returns bar shift with the open time specified.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I would like to count bars since an event occurs. I used a flag showing the time of the event and I insert it on the formula iBarShift. I don’t know where my mistake is, but the result is always the same, and don’t start with 0, 1, 2… I think that is missing a looping between new data.
Thanks