[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

I should have posted the code in function form so you can call it 
from your EL code as easily as you can from Metastock.  Here is a 
ValueWhen function that takes the same parameters as the MS 
ValueWhen, except you must also specify how far back you want it 
to search for the event.

For example:  

  RSIwhen = ValueWhen(2, C crosses over average(C,10), RSI(C,20), 50);

Gary

===

{ Function ValueWhen }

inputs: 
    Nth(NumericSimple),       { Find Nth most recent occurence }
    Expression(TrueFalse),    {  of this expression            }
    DataArray(NumericSeries), {  return this val on that bar   }
    Lookback(Numeric);        { #bars back to search           }

vars: BarsBack(0);

BarsBack = MRO(Expression, Lookback, Nth);
if BarsBack >= 0 then ValueWhen = DataArray[BarsBack];