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

Re: Easy-language slow code



PureBytes Links

Trading Reference Links

> YOWWWW..... without wading through the code, I see the same calc
>   RSIClassic(detrend(close, detrend_length), rsi_length)
> repeated many times. 

Dennis is right.  You're doing the same calculations a zillion times 
each bar.  Compute the values once, save them in variables, and use 
those variables where you need the values.  Not only is that going to 
run a lot faster, it's a whole lot easier to read too.  

In fact now that I've simplified it with variables, I see what looks 
like a logic error.  In the calculation of RSIval, you test for 
clsRSI-lowRSI=0, but then you use (highest(clsRSI,rsi_length) - 
lowRSI) in the denominator.  Isn't that (the denominator value) what 
you want to test, to make sure you don't divide by zero?

I don't have TS2k nor your RSIClassic function so I can't verify 
this, but this should be very close:


Inputs:detrend_length(90), rsi_length(14), Length(14), BuyZone(.30),
SellZone(.70), BZColor(Green), SZColor(Magenta);
var: value1(0);

vars: clsRSI(0), lowRSI(0), RSIval(0);
clsRSI = RSIClassic(detrend(close, detrend_length), rsi_length);
lowRSI = lowest(clsRSI, rsi_length));
RSIval = iff((clsRSI-lowRSI=0, 0, 
               (clsRSI-lowRSI)/(highest(clsRSI,rsi_length) - lowRSI));

Plot1(RSIval, "RSI");
Plot2(BuyZone, "BuyZone");
Plot3(SellZone, "SellZone");
plot4(average(RSIval, length), "RSI ave");

If Plot1 > SellZone then Begin
 Alert("The detrend RSI is in overbought territory");
 SetPlotColor(1, SZColor);
End
Else
 If Plot1 < BuyZone then Begin
  Alert("The detrend RSI is in oversold territory");
  SetPlotColor(1, BZColor);
 End;