[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How might this be done in TS?



PureBytes Links

Trading Reference Links

>Example: valuewhen(2,average(c,10) = C,rsi(c,20));
>
>would return the value of RSI on the 2nd most recent occurrence of  close 
>equal to the 10 bar moving average.

The following should work because TS saves local variable values
in separate contexts for each instance of a function call.

----------------------------------------------------------------------
{function valuewhen
 returns -999999 until the tested condition is true for maxcount number
 of times, after which the passed return value is returned.}

inputs:
    maxcount(NumericSimple),
    testcondition(TrueFalse),
    returnvalue(NumericSimple);

var: counter(0), savedretnval(-999999);

if counter < maxcount then begin
    if testcondition then counter = counter + 1;
    if counter = maxcount then savedretnval = returnvalue;
end;
ValueWhen = savedretnval;
----------------------------------------------------------------------

-Alex