Hiya,
I’d like to compare today’s high to each of the highs in a lookback range of 20 bars. Then divide that number by the bars since that high occured, in order to find the highest angle possible between today’s high and a single high in the lookback period. Could I have some clues where to start please?
Angles/Slopes are impossible to be measured, this has been extensively discussed here and elsewhere. Some useful links:
https://www.prorealcode.com/topic/ema-45-degres-uptrend/
https://www.prorealcode.com/topic/indicator-for-inclination-of-moving-average/
https://www.prorealcode.com/topic/calculating-the-angle-linear-regression-of-a-line/
Anyway, to retrieve the BarIndex ID of a bar you can only use loops, since there’s no function returning that info, as of this version of PRT:
FOR i = 0 TO 19 //20 bars lookback
IF high[i] > high[i+1] THEN //put here anything you like to check
.
.
ENDIF
NEXT
in order to find the highest angle possible between today’s high and a single high in the lookback period
I guess if you had said … to get a measure of the rate of change between today’s high and a single high in the lookback period ... may be less confusing and might get you the code you need? 🙂
Thanks for the help Robert and Grahal.
Grahal, that’s an excellent idea. Am I geting closer with the following?
FOR i = 0 TO 20 //20 bars lookback
IF high[i] > high[i+1] THEN //put here anything you like to check
a = high[i+1] /barindex
aa = highest[20](a)
ENDIF
NEXT
ok that attempt was no good.
I’m trying to create a substitute for a downsloping trendline which can be auto-traded by finding (in psuedocode):
highest angle in lookback = (high[lookback] – today’s high ) / barindex
then for each bar after today, subtracting that angle to create a trigger price, until the close >trigger.
Suggestions very welcome!
Barindex can be 10000 or more, maybe highest angle in lookback = (high[lookback] – today’s high ) / i would be better, but I did not test it.