Hi
Looking to try and code to return number of periods since when the close crosses above (or below) the supertend, and then note the last value of the supertrend prior to the close crossing it. I can see the barindex and tradeindex but don’t know how to refer to any other condition.
Thanks in advance 🙂
I moved your topic to ProOrder support, since you are referencing TRADEINDEX which is related to strategies.
This is the code:
ONCE CrossOVER = 0
ONCE CrossUNDER = 0
ONCE PrevClose = 0
MyST = Supertrend[3,10]
IF CrossUNDER = 0 THEN
IF close CROSSES UNDER MyST THEN
PrevClose = close[1]
CrossUNDER = BarIndex
CrossOVER = 0
ENDIF
ENDIF
IF CrossOVER = 0 THEN
IF close CROSSES OVER MyST THEN
PrevClose = close[1]
CrossUNDER = 0
CrossOVER = BarIndex
ENDIF
ENDIF
Basically you have to keep track of the bar when the crossing occurs and, at the same time, save the value of the CLOSE prior to the crossing.
Clear all values and flags when a reverse crossing occurs.
At the end of the code, PREVCLOSE, if other than 0, will retaing the CLOSing price the candle before the crossing occurs.
To tell how many bars have elapsed, in case CROSSOVER/UNDER > 0, just use the expression:
ElapsedBars = (BarIndex - CrossOver) + 1
ElapsedBars = (BarIndex - CrossUnder) + 1
Thank heaps for that. Sooo much appreciated