Hi Pete, Thanks for your great coding resources. Please consider this situation. I’m keeping track of the intraday high until a moving average crosses above the VWAP from below. After that I want to stop calculating the intraday high (I use larger timeframes).
I don’t care if the moving average opens above the VWAP, only if it comes down below VWAP and crosses above. In other words, I want to stop calculating the intraday high once the moving average has crossed VWAP from below only.
I can’t use a movingaverage >= VWAP condition because if the moving average opens above the VWAP, I don’t want my code to care about it. Likewise, I can’t use the crosses function because it only considers one candle.
I find that a solution to my problem lies in an if statement if I can make the below “else 0” condition do nothing instead. Is that possible?
def HasItCrossed = if (crosses(movingAverage, VWAP, CrossingDirection.ABOVE)) then 1 else 0;
rec RecordHigh = if (HasItCrossed == 0) then if (high > RecordHigh) then high else RecordHigh else RecordHigh
Another option- see if the movingaverage has crossed above since open? Can that be done?
Marked as spam
Please log in to post questions.