I am trying to sum the values, if RSI (close, x) > 0 then 1 else 0, across different lookback (x) RSI periods and different sum periods. The long hand coded version would look like the following:
input lb1 = 14;
input lb2 = 15;
input lb3 = 16;
input SumPeriod = 34;
def sum1 = sum(if rsi(close,lb1) > 0 then 1 else 0, SumPeriod);
def sum2 = sum(if rsi(close,lb2) > 0 then 1 else 0, SumPeriod);
def sum3 = sum(if rsi(close,lb3) > 0 then 1 else 0, SumPeriod);
The following fold works correctly, but is not what I am trying to arrive at. It sums the rsix values > 0 for the last number of bars in the SumPeriod (34).
input lb1 = 14;
input SumPeriod = 34;
def rsix = rsi(close, lb1);
def sum = fold i = 0 to SumPeriod with s do s + if rsix > 0 then 1 else 0;
I know the following fold function is not the complete code that is the equivalent of the long hand code above, but I cannot get past this part, TOS does not like this:
def sum = fold i = 0 to lb1 with s do s + rsi(close,i);
Is what I am asking of the fold function outside of it's capabilities, or I am missing something? Any assistance is appreciated!
input lb1 = 14;
input lb2 = 15;
input lb3 = 16;
input SumPeriod = 34;
def sum1 = sum(if rsi(close,lb1) > 0 then 1 else 0, SumPeriod);
def sum2 = sum(if rsi(close,lb2) > 0 then 1 else 0, SumPeriod);
def sum3 = sum(if rsi(close,lb3) > 0 then 1 else 0, SumPeriod);
The following fold works correctly, but is not what I am trying to arrive at. It sums the rsix values > 0 for the last number of bars in the SumPeriod (34).
input lb1 = 14;
input SumPeriod = 34;
def rsix = rsi(close, lb1);
def sum = fold i = 0 to SumPeriod with s do s + if rsix > 0 then 1 else 0;
I know the following fold function is not the complete code that is the equivalent of the long hand code above, but I cannot get past this part, TOS does not like this:
def sum = fold i = 0 to lb1 with s do s + rsi(close,i);
Is what I am asking of the fold function outside of it's capabilities, or I am missing something? Any assistance is appreciated!