BarsSince used in different timeframe causing problem

OneMinute=in1Minute*1;
TimeFrameSet(OneMinute);
barsSinceBullishBreach=BarsSince(L<=cloudSupportPrimary);
TimeFrameRestore();
_TRACE("barsSinceBullishBreach="+barsSinceBullishBreach);

Chart interval is 30 seconds. I select a bar using the mouse cursor and then scroll. Why is the value of the trace change. I use barsSinceBullishBreach for the buy signal and since the value changes the signal too appears and disappears as i scroll back and forth. No such problem when chart is viewed in 1 minute interval.

1 Like

Sorry I had missed pasting the timeframeexpand line of code. The problem is elsewhere.

OneMinute=in1Minute*1;
TimeFrameSet(OneMinute);
barsSinceBullishBreach=BarsSince(L<=cloudSupportPrimary);
TimeFrameRestore();
barsSinceBullishBreach=TimeFrameExpand(barsSinceBullishBreach, OneMinute);
_TRACE("barsSinceBullishBreach="+barsSinceBullishBreach);

I think it has to do with zoom level. I mean how the value of the array changes once it is out of focus. I think the focus is being set by 1 minute TF where as the chart is of 30 sec. something in those lines.

Your variable cloudSupportPrimary is defined somewhere before TimeFrameSet. But you need to define it after TimeFramset and before TimeFrameRestore.

OneMinute=in1Minute*1;
TimeFrameSet(OneMinute);
cloudSupportPrimary = /*your code here*/
barsSinceBullishBreach=BarsSince(L<=cloudSupportPrimary);
TimeFrameRestore();
barsSinceBullishBreach=TimeFrameExpand(barsSinceBullishBreach, OneMinute);
_TRACE("barsSinceBullishBreach="+barsSinceBullishBreach);
4 Likes

Yes this worked. fxshrat had sent me a message about this.