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

Re: Easy-language slow code



PureBytes Links

Trading Reference Links

> The indicator below is the StochRSI of the detrended price.  Problem is that
> it takes over 1minute for the indicator to run through all the calculations
> and finally be put on the screen.  I'm running 2000i.  Anyone have any ideas
> on how to speed this one up?

YOWWWW..... without wading through the code, I see the same calc

  RSIClassic(detrend(close, detrend_length), rsi_length)

repeated many times. I also see you are using highest, lowest and
average with that number so chances are you are calculating the same
thing hundreds of times on the same bar. Better to start the code with

  myvariable = RSIClassic(detrend(close, detrend_length), rsi_length);

and then replace every instance of

  RSIClassic(detrend(close, detrend_length), rsi_length)

with

  myvariable

That way you only need to calculate it once on each bar. In general, you
should declare a variable and only do the calculation once for any code
snippet that you are using more than once. 

  var: rs(0), avgrs(0) {etc};

  rs = {whatever};
  avgrs = average(rs,len);
  etc

The built-in variables, value1 etc, don't have to be declared with a
var: statement but it's better to use descriptive names that make sense
to you.

You might also read up on if/then/else statements. That excel-like iff
stuff gets really kludgey if you want to do anything very complicated.

-- 
  Dennis