#twitter-follow { border: 0;position: fixed; top: 240px; left:0;} #live-support { border: 0;position: fixed; top: 370px; left:0;} #knowledge-base { border: 0;position: fixed; top: 170px; left:0;}

 Script or Custom Function? past _X_ closes less than current close 1

 Josh McCormick 2020-09-07 13:26:48 I want to do something incredibly easy, but after so many attempts, my brain has turned to mush. Here's a simplified version of the problem: There are any number of examples which show how many of the past _X_ closes are greater than a fixed number. Or how many of the past _X_ closes are greater than the closing value that was five bars before (or after) it. What I am looking for is something a little bit different: For each and every bar, I want to count (and graph) how many of the past 50 bars had a close which is lower than *the current bar*. I'd use something like SumIf, but I can't find a suitable comparison which tells it to compare the closing period against the current bar: a=SumIf (close > ???????,1,50); I tried both of these, but they don't return anything useful: a=SumIf (close > close[count()],1,50); a=SumIf (close > value (close,count()),1,50); Any thoughts? Or am I trying to do something with QS Script that I should be writing a custom (CSharp) function for? Thanks again, Josh McCormick
 QuantShare 2020-09-08 10:37:57   1 Best Answer SumIf will iterate through the "array" parameter and calculate the "condition" parameter once, so it will not work in this case. This is the kind of functions that currently needs to be developed in CSharp. Loop through each bar (A) then for each bar loop through each past N bars (B) and compare that bar close (A) with the bar close (B).
 Josh McCormick 2020-09-08 12:03:32   0 Thanks! You've rescused me from a mountain of troubleshooting.
No more messages