I'm interested in writing some ThinkScript code that will allow me to scan for stocks where over the last N bars, the 17EMA M bars ago is greater than the 17EMA M+1 bars ago. I'm learning ThinkScript now and started initially by manually typing out a chain of conditions as shown below. I'm wondering if I can use a fold statement to rewrite this so I can set the number of bars I look back over to any arbitrary value.
Any suggestions?MovAvgExponential("length" = 17)."AvgExp" is greater than MovAvgExponential("length" = 17)."AvgExp" from 1 bars ago and
MovAvgExponential("length" = 17)."AvgExp" from 1 bars ago is greater than MovAvgExponential("length" = 17)."AvgExp" from 2 bars ago and
MovAvgExponential("length" = 17)."AvgExp" from 2 bars ago is greater than MovAvgExponential("length" = 17)."AvgExp" from 3 bars ago and
MovAvgExponential("length" = 17)."AvgExp" from 3 bars ago is greater than MovAvgExponential("length" = 17)."AvgExp" from 4 bars ago