оптимизация iCustom - страница 2

 
Taras Slobodyanik:

сравнить объем занимаемой памяти при вызове одног индикатора и при вызове 40 индикаторов (параметры обязательно должны быть разные)

не, с Виндой такие фокусы могут не прокатить, буферизация выделения памяти, освобождение памяти... гадать проще на кофейной гуще, чем что там Винда делает и терминал с памятью

вот в код индикатора добавил идентификатор:

#property copyright "Copyright 2019, IgorM"
#property link      "https://www.mql5.com/ru/users/igorm"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   3
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Label2
#property indicator_label2  "Label2"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrOrange
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot Label3
#property indicator_label3  "Label3"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrBlue
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- indicator buffers
input double   value=1.0;
double         Label1Buffer[];
double         Label2Buffer[];
double         Label3Buffer[];
static int id = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
   SetIndexBuffer(1,Label2Buffer);
   SetIndexBuffer(2,Label3Buffer);
   srand(GetTickCount());
   id = rand();
   Print("Init(), id = ",id);
//---
   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 i,limit;
   if(prev_calculated==0) limit=rates_total-1; else limit=rates_total-prev_calculated+1;
   Print("id = ",id ," , limit = ",limit," , value = ",value);
   for(i=limit; i>=0; i--)
     {
      Label1Buffer[i]=close[i] * value;
      Label2Buffer[i]=close[i] * value;
      Label3Buffer[i]=close[i] * value;
     }
   return(rates_total);
  }

однозначно @Andrey Khatimlianskii прав, в логе видно, что несколько копий индикатора запущено если iCustom()  с разными параметрами вызывается

2019.05.07 21:26:07.611 tst_ic EURUSD,H1: Вызов буффера 1 , результат = 1.11742

2019.05.07 21:26:07.611 tst_icustom EURUSD,H1: id = 25727 , limit = 1 , value = 1.0

2019.05.07 21:26:07.352 tst_ic EURUSD,H1: Вызов буффера 3 , результат = 3.35226

2019.05.07 21:26:07.350 tst_icustom EURUSD,H1: id = 26083 , limit = 21181 , value = 3.0

2019.05.07 21:26:07.349 tst_icustom EURUSD,H1: Init(), id = 26083

2019.05.07 21:26:07.301 tst_ic EURUSD,H1: Вызов буффера 2 , результат = 2.23484

2019.05.07 21:26:07.297 tst_icustom EURUSD,H1: id = 25932 , limit = 21181 , value = 2.0

2019.05.07 21:26:07.296 tst_icustom EURUSD,H1: Init(), id = 25932

2019.05.07 21:26:07.236 tst_ic EURUSD,H1: Вызов буффера 1 , результат = 1.11742

2019.05.07 21:26:07.234 tst_icustom EURUSD,H1: id = 25727 , limit = 21181 , value = 1.0

2019.05.07 21:26:07.233 tst_icustom EURUSD,H1: Init(), id = 25727



если вызывать iCustom()  с одинаковыми параметрами, то одна копия индикатора:

2019.05.07 21:31:38.141 tst_ic EURUSD,H1: Вызов буффера 2 , результат = 1.11742

2019.05.07 21:31:38.141 tst_ic EURUSD,H1: Вызов буффера 1 , результат = 1.11742

2019.05.07 21:31:38.141 tst_icustom EURUSD,H1: id = 21514 , limit = 1 , value = 1.0

2019.05.07 21:31:37.092 tst_ic EURUSD,H1: Вызов буффера 3 , результат = 1.11742

2019.05.07 21:31:37.092 tst_ic EURUSD,H1: Вызов буффера 2 , результат = 1.11742

2019.05.07 21:31:37.092 tst_ic EURUSD,H1: Вызов буффера 1 , результат = 1.11742

2019.05.07 21:31:37.089 tst_icustom EURUSD,H1: id = 21514 , limit = 21181 , value = 1.0

2019.05.07 21:31:37.088 tst_icustom EURUSD,H1: Init(), id = 21514