SuperTrend Indicator to slow

 

Hi,

I am using the SuperTrend indicator as part of an EA, but the indicator is very slow and is making the testing incredibly slow.

Can anyone help with how to speed it up?

Cheers

Paul

 
   if(counted_bars > 0) counted_bars--;
   limit=Bars-counted_bars;
   //Print(limit);
   
//----
   for (i = Bars; i >= 0; i--) { <---replace Bars with limit.
 

i = Bars is wrong. You can't access Close[Bars], it does not exist.

limit = Bars - counted_bars is wrong. When counted_bars == 0 limit points beyond.

The decrement is unnecessary Contradictory information on IndicatorCounted() - MQL4 forum

for (i = Bars - 1 - counted_bars; i >= 0; i--) {
 

Hi, 

this thread is 8 years old now, but i have a question about the original supertrend indicator in mt4 and also in mt5.

It is sooo slow iwhile backtesting on BOTH Platform 4 and 5.

I ve tried the solutions above, but nothing changes during the Backtest.

Has anybody a solution ?


Thanks very much...

oschi

 
Hi Oschi, 

Yes it can be very slow to backtest if you are accumulating indicators or calling then to often.

If your code is already optimized then try to call it only when really pertinent.

 
  1. EAs : Don't do per tick that you can do per bar, or on open.
    If you are waiting for a level, don't reevaluate, wait until price reaches it (or a new bar starts and you recalculate.)
    If you are waiting for an order to open or close, only look when OrdersTotal (or MT5 equivalent) has changed.
              How to get backtesting faster ? - MT4 - MQL4 programming forum

  2. Indicators: Code it properly so it only recomputes bar zero (after the initial run.)
              How to do your lookbacks correctly.
    Or, reduce Tools → Options (control-O) → Charts → Max bars in chart to something reasonable (like 1K.)
     

    ok, thank you both, that helps..

    I now "call" the supertrend values, when

    i have a "high" ATR as part of my strategy

    i am testing. Speed up on 300 % now.

    Not really fast, but i can work with....

    But why ist supertrend so slow? All other Indis are much faster.

    Is there a mistake (coding) in the original MT4-Supertrend ?

    Or is it in the "nature" of the supertrend ??

    Thanks, you helped me a lot, but i want to learn more... :-)

    Oschi

    Reason: