Подскажите, пожалуйста, как создать буфер для сохранения только последних расчетных значений из цикла? - страница 3

 
//+------------------------------------------------------------------+
//|                                                     Konveyer.mq4 |
//|                                           Copyright © 2006, XEON |
//|                                                       xeon@nm.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, XEON"
#property link      "xeon@nm.ru"
 
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Magenta
#property indicator_color4 Yellow
#property indicator_color5 Aqua
 
extern int shift1 =1;
extern int shift2 =3;
extern int shift3 =5;
extern int shift4 =7;
extern int shift5 =9;
extern int Per    =5;
 
double ArrayPrice[10000][5];
double IndBuffer1[];
double IndBuffer2[];
double IndBuffer3[];
double IndBuffer4[];
double IndBuffer5[];
double AllPrc;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexBuffer(0,IndBuffer1);
   SetIndexBuffer(1,IndBuffer2);
   SetIndexBuffer(2,IndBuffer3);
   SetIndexBuffer(3,IndBuffer4);
   SetIndexBuffer(4,IndBuffer5);
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE);
//---- index labels
   SetIndexLabel(0,"IndBuffer1");
   SetIndexLabel(1,"IndBuffer2");
   SetIndexLabel(2,"IndBuffer3");
   SetIndexLabel(3,"IndBuffer4");
   SetIndexLabel(4,"IndBuffer5");
   Comment("   ");
//----
   return(0);
  }
 
int start()
  {
   int    counted_bars=IndicatorCounted();
   int    limit = Bars-counted_bars;
   
//----
     for(int i=limit;i>=0;i--){
         ArrayPrice[i][0]=(Open[i]+Close[i])/2;
         ArrayPrice[i][1]=(High[i]+Low[i])/2;
         ArrayPrice[i][2]=(High[i]+Low[i]+Close[i])/3;
         ArrayPrice[i][3]=(Open[i]+High[i]+Low[i]+Close[i])/4;
         AllPrc=0;
         for(int ma=i;ma<Per+i;ma++){
             AllPrc=AllPrc+Close[ma];
         }  
       
         ArrayPrice[i][4]=AllPrc/Per;
 
         IndBuffer1[i]=ArrayPrice[i+shift1][0];
         IndBuffer2[i]=ArrayPrice[i+shift2][1];
         IndBuffer3[i]=ArrayPrice[i+shift3][2];
         IndBuffer4[i]=ArrayPrice[i+shift4][3];
         IndBuffer5[i]=ArrayPrice[i+shift5][4];
     }     
      Comment(ArrayPrice[0][0],"   ",ArrayPrice[0][1],"   ",ArrayPrice[0][2],"   ",ArrayPrice[0][3],"   ",ArrayPrice[0][4]);   
//----
   return(0);
  }
//+------------------------------------------------------------------+
Надеюсь этот код поможет вам сделать то что вы хотите.


 
xeon -спасибо за помощь, хотя не совсем понял, как применить последний Ваш код к моей задаче.
Также не понял в чем ошибка в моем решении, почему сохраняется только последнее занесенное значение, а то, что сдвигается - теряется, единственный вывод который напрашивается - на глобальном уровне можно сохранять только переменные, а массивы - нельзя.
Не любля быть должником, надеюсь, чем-то смогу помочь и Вам.
 
Этим кодом я хотел показать как можно делать нужный вам сдвиг по сохраненным в массиве данным.
Параметры сдвига задаются в этих переменных
extern int shift1 =1;
extern int shift2 =3;
extern int shift3 =5;
extern int shift4 =7;
extern int shift5 =9;

Вы писали - строится 20 моделей различных гармоник тренда
я для примера сделал 5 типов цен

Вы писали - буферный массив в который записывается один из сигналов при каждом старте функции
я записал все 5 типов цен в массив

ArrayPrice[i][0]=(Open[i]+Close[i])/2;
ArrayPrice[i][1]=(High[i]+Low[i])/2;
ArrayPrice[i][2]=(High[i]+Low[i]+Close[i])/3;
ArrayPrice[i][3]=(Open[i]+High[i]+Low[i]+Close[i])/4;
AllPrc=0;
for(int ma=i;ma<Per+i;ma++){
    AllPrc=AllPrc+Close[ma];
}  
   
ArrayPrice[i][4]=AllPrc/Per;

Вы писали - цикл, в котором осушествляется реверсивный сдвиг всех накопленных сигналов
Здесь я попытался показать как можно сдвигать данные при перегрузке из массива в индикаторный буфер

IndBuffer1[i]=ArrayPrice[i+shift1][0];
IndBuffer2[i]=ArrayPrice[i+shift2][1];
IndBuffer3[i]=ArrayPrice[i+shift3][2];
IndBuffer4[i]=ArrayPrice[i+shift4][3];
IndBuffer5[i]=ArrayPrice[i+shift5][4];

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

В этом примере все 5 типов цен с установленным сдвигом сохраняются в индикаторных буферах и отображаются на графике

>Не любля быть должником, надеюсь, чем-то смогу помочь и Вам.
не волнуйтесь вы мне ничего не должны :-)