Moving Average Squeeze


Category:
0
0

Hi Pete. I’ve defined (5) moving averages with the lengths of 8, 13, 21, 34, and 55. I want to know when the distance between the uppermost and lowest moving average is <= 2% of the stock price.

Since the moving averages will not always be aligned in order, I’m trying to figure out how I can get the highest and lowest values based on which of the 5 MA’s are on top, and which one is on the bottom. I know the “highest” and “lowest” functions only accept 2 arguments so I’m pretty sure that’s not the solution. I’ve tried “AbsValue” and “GetValue” but I have too many arguments.

I’m still in thinkScript learning mode and I’m stuck. I hope I’m on the right track here. I would really appreciate your help on this. Thank you again!

*File Attached

Marked as spam
Posted by (Questions: 5, Answers: 9)
Asked on August 24, 2020 3:04 am
378 views
0
Private answer

Try using Min() and Max():

https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Min

https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/Max

That's all I have time for at the moment. More later if you need additional ideas.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on August 24, 2020 8:53 am
0
I think I got it. Another new tool for my thinkScript toolbox ? def val1 = AbsValue(ma1); def val2 = AbsValue(ma2); def val3 = AbsValue(ma3); def val4 = AbsValue(ma4); def val5 = AbsValue(ma5); def upper = max(val1,max(val2,max(val3,max(val4,val5)))); def lower = min(val1,min(val2,min(val3,min(val4,val5)))); def upperMinusLower = upper – lower; plot signal = if upperMinusLower <= (close * percentUpperMinusLower) then 1 else 0;
( at August 24, 2020 3:21 pm)