How to take action only on closed candle data
How to take action only on closed candle data
15 Apr 2015, 21:57
For example the Sample Trend cBot, it is my understanding that this acts on the moving average crossovers immediatly at the cross-over, which is probably in the middle of the candle. And this is because it is comparing Result.Last(0) with Result.Last(1) for the MAs, and while Result.Last(1) is the close of the last candle, Result.Last(0) is changing every tick. Is that correct?
If I wanted this to work off of closed candles, should I use Result.Last(1) vs Result.Last(2), and figure out a way to have it only execute once as ticks keep coming in?
Furthermore there is the Function.HasCrossedAbove, but it even says in the documentation that it can return true and then the price can cross back before the candle closes. I can't imagine how that could be useful, especially since, although you can tell it to look back a certain number of periods, you can't say not to look at the current unfinished candle.
This seems like a trivial thing and I don't want to over-engineer a solution. Thanks for any advice you have.
Replies
WhiteSage
16 Apr 2015, 11:01
OnBar() is called as a new bar opens I believe, so you will want Result.Last[1], Last[0] is always the current incomplete bar.
@WhiteSage
GunArm
15 Apr 2015, 22:40
Is the right way to do this to use OnBar() instead of OnTick(), and then use Result.Last(1) and Result.Last(2) ignoring Result.Last(0)?
@GunArm