indicator is too slow, 190961 ms. rewrite the indicator, please

 

Всем, привет!

Регулярно получаю сообщения:

2015.06.30 03:18:13.865 RSI-BB-SMA EURUSD.e,M15: indicator is too slow, 190961 ms. rewrite the indicator, please

2015.06.30 02:25:39.836 RSI-BB-SMA EURUSD.e,M15: indicator is too slow, 190867 ms. rewrite the indicator, please

2015.06.30 01:03:12.677 RSI-BB-SMA EURUSD.e,M15: indicator is too slow, 190898 ms. rewrite the indicator, please

Индюк составной из трех: на данных RSI строится Полосы Болленджера и МА(SMA)

Вопрос: что нужно/можно изменить в индюке, чтобы работал шустрее?

//+------------------------------------------------------------------+
//|                                                   RSI-BB-SMA.mq4 |
//|                                                   Fromme2You     |
//+------------------------------------------------------------------+
#property copyright "fromme2you (c) 2015"
#property version   "1.00"
#property strict
#property indicator_separate_window

input int     RSI_period =  9;            // RSI период
input int      BB_period = 13;            // BB период
input int      BB_Dev    =  1;            // Отклонение BB
input int      MA_period = 55;            // МА период
input ENUM_MA_METHOD MA_method=MODE_SMA;  // метод сглаживания МА

#property indicator_buffers    5
#property indicator_color1     LightSeaGreen
#property indicator_level1    70.0
#property indicator_level2    50.0
#property indicator_level3    30.0
#property indicator_levelcolor clrSilver
#property indicator_levelstyle STYLE_DOT

double RSIBuf[], BB_UP[],BB_MN[],BB_DN[], SMA[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   IndicatorBuffers(5);
   IndicatorShortName("RSI("+IntegerToString(RSI_period)+")"+
                      " BB("+IntegerToString(BB_period)+"/"+IntegerToString(BB_Dev)+")"+
                      " SMA("+IntegerToString(MA_period)+")");
   
   SetIndexBuffer(0,RSIBuf);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,clrDodgerBlue);
   
   SetIndexBuffer(1,BB_UP);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,clrYellow);
   
   SetIndexBuffer(2,BB_MN);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1,clrYellow);
   
   SetIndexBuffer(3,BB_DN);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1,clrYellow);
   
   SetIndexBuffer(4,SMA);
   SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1,clrRed);
   
   
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   int limit=0;
   
   if(Bars<=MA_period) return(0);
   
   if(prev_calculated==0)
      limit=rates_total-MA_period-1;
   if(prev_calculated>0)
      limit=rates_total-prev_calculated;

   for(int i=limit; i>=0; i--)
   {
     RSIBuf[i]= iRSI(NULL, 0, RSI_period,PRICE_CLOSE,i);
     BB_UP[i] = iBandsOnArray(RSIBuf,0,BB_period,BB_Dev,0,MODE_UPPER,i);
     BB_MN[i] = iBandsOnArray(RSIBuf,0,BB_period,BB_Dev,0,MODE_MAIN,i);
     BB_DN[i] = iBandsOnArray(RSIBuf,0,BB_period,BB_Dev,0,MODE_LOWER,i);
     SMA[i]   = iMAOnArray(RSIBuf,0,MA_period,0,MA_method,i);
   }

   return(rates_total);
}
 
fromme2you:

Всем, привет!

Регулярно получаю сообщения:

2015.06.30 03:18:13.865 RSI-BB-SMA EURUSD.e,M15: indicator is too slow, 190961 ms. rewrite the indicator, please

2015.06.30 02:25:39.836 RSI-BB-SMA EURUSD.e,M15: indicator is too slow, 190867 ms. rewrite the indicator, please

2015.06.30 01:03:12.677 RSI-BB-SMA EURUSD.e,M15: indicator is too slow, 190898 ms. rewrite the indicator, please

Индюк составной из трех: на данных RSI строится Полосы Болленджера и МА(SMA)

Вопрос: что нужно/можно изменить в индюке, чтобы работал шустрее?

В настройках терминала уменьшите параметр макс. баров в окне. Пользуйтесь поиском.
 
Tapochun:
В настройках терминала уменьшите параметр макс. баров в окне. Пользуйтесь поиском.
А такое решение верно?
if(prev_calculated==0)   limit=rates_total-MA_period-1;
if (limit>1000) limit=1000; // ограничим вычисления последними 1000 баров
if(prev_calculated>0) limit=rates_total-prev_calculated;
 
fromme2you:
А такое решение верно?

Лучше в input константу вынести.

И... оптимальнее будет так:

if( prev_calculated <= 0 )
{
 limit = rates_total-MA_period-1;
 if( limit > 1000 ) limit = 1000;
}
else limit = rates_total-prev_calculated;

В этом случае проверку на limit > 1000 не будет происходить на каждом тике. (работоспособность кода не проверял)