Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 727

 

Thank you all!

double arr[3];

arr[0] = 300.0;
arr[1] = 254.0;
arr[2] = Bid; 
Alert("В массиве arr под индексом 0 значение ", arr[0]); // 300
Alert("В массиве arr под индексом 1 значение ", arr[1]); // 254 
Alert("В массиве arr под индексом 1 значение ", arr[2]); // Bid всё равно меняется на каждом тике, в чём же прикол этих массивов?, я с таким же успехом могу и так сделать
Alert("В массиве arr под индексом 1 значение ", Bid); я думал что массив запоминает цену с первого тика и держит эту инфо на последующих тиках
 
tara:

What's the big deal?

Yeah, that's what I thought too, when I wrote it on my own. And when I inserted into void OnStart() of the script and got exit outside the array in the log, I came to such a conclusion. In your example, int start() is an old version of the script without #property strict.

And without #property strict this is what it outputs.

#property version   "1.00"
//#property strict

double arr[];
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   arr[0] = 300.0;
   arr[1] = 254.0;
   arr[2] = Bid;
   Alert("В массиве arr под индексом 0 значение ", arr[0]); // 300
   Alert("В массиве arr под индексом 1 значение ", arr[1]); // 254
   Alert("В массиве arr под индексом 2 значение ", arr[2]); // Bid
   
  }
//+------------------------------------------------------------------+


 

And it's best not to go beyond.

Here:

/*    Soft Fractals ZigZag Indicator - индикатор строит зигзаг по фракталам 
   с произвольными размерами правого и левого крыльев. */
#property strict
#property copyright "Copyright 2012, Тарабанов А.В."
#property link      "alextar@bk.ru"
#property indicator_chart_window                   // Индикатор в главном окне
// Индикаторные буферы
#property indicator_buffers 4
#property  indicator_width1 1                       // Толщина зигзага
#property  indicator_color3 Green                   // Нижние вершины
#property  indicator_width3 1
#property  indicator_color4 Red                     // Верхние вершины
#property  indicator_width4 1
double Min[]   , Max[],                            // Изломы зигзага
       Bottom[], Top[];                            // Вершины
// Константы
#define  Version "iSFZZ"                            // Версия
#define  Zero    0.00000001                         // Точность определения нуля
// Глобальные переменные
double      LastBottom , LastTop;                  // Предыдущие значения
int         iLastBottom, iLastTop;                 //    и их бары
datetime    tLastBottom, tLastTop;                 // Время предыдущих значений
bool        LastIsTop  , LastIsBottom;             // Предыдущий пик/впадина
extern bool ОтображатьВершины   =true;             // Внешние переменные
extern int  БаровЛевееВершины   =2,
            БаровПравееВершины  =2,
            СимволНижнейВершины =161,
            СимволВерхнейВершины=161;
//+------------------------------------------------------------------+
int init(){
   int DrawFractals=DRAW_NONE;
   if( ОтображатьВершины ) DrawFractals=DRAW_ARROW;
   // Атрибуты буферов
   SetIndexLabel(0,"Max");
   SetIndexBuffer(0,Max);
   SetIndexStyle(0,DRAW_ZIGZAG);
   SetIndexEmptyValue(0,0);
   SetIndexLabel(1,"Min");
   SetIndexBuffer(1,Min);
   SetIndexStyle(1,DRAW_ZIGZAG);
   SetIndexEmptyValue(1,0);
   SetIndexLabel(2,"Bottom");
   SetIndexBuffer(2,Bottom);
   SetIndexStyle(2,DrawFractals);
   SetIndexArrow(2,СимволНижнейВершины);
   SetIndexEmptyValue(2,0);
   SetIndexLabel(3,"Top");
   SetIndexBuffer(3,Top);
   SetIndexStyle(3,DrawFractals);
   SetIndexArrow(3,СимволВерхнейВершины);
   SetIndexEmptyValue(3,0);
   if( БаровЛевееВершины <1 ) БаровЛевееВершины=1; // Контроль значений
   if( БаровПравееВершины <1 ) БаровПравееВершины=1;
   LastBottom  =0;                                 // Инициализация
   LastTop     =0;
   iLastBottom =0;
   iLastTop    =0;
   tLastBottom =0;
   tLastTop    =0;
   LastIsTop   =false;
   LastIsBottom=false;
   return(0);
}
//+------------------------------------------------------------------+
int start(){
   int i, History=Bars-1, BarsLost=History-IndicatorCounted();
   if( BarsLost<History ){
      if( BarsLost<1 ) return(0);                  // Не повторять на том-же баре
      i=BarsLost+БаровПравееВершины;               // Число баров пересчета
   }
   else i=History-БаровЛевееВершины;               // Просмотр на всей истории
   double C[];
   int dim=ArrayResize(C,БаровЛевееВершины+1+БаровПравееВершины), j;
   if( tLastTop>0 ) iLastTop=iBarShift(NULL,0,tLastTop);
   if( tLastBottom>0 ) iLastBottom=iBarShift(NULL,0,tLastBottom);
   while( i>БаровПравееВершины ){                  // Перебор слева направо
      j=0;                                         // Поиск нижнего фрактала
      Bottom[i]=0;
      while( j < dim ){
         C[j]=Low[j+i-БаровПравееВершины];
         j++;
      }
      if( C[БаровПравееВершины+1]-C[БаровПравееВершины]>-Zero
       && C[БаровПравееВершины-1]-C[БаровПравееВершины]>-Zero ){
         Bottom[i]=C[БаровПравееВершины];          // Локальный минимум
         j=1;
         while ( j < dim ){
            if( ( j<БаровПравееВершины && Bottom[i]-C[j-1]>Zero )
             || ( j>БаровПравееВершины && Bottom[i]-C[j]  >Zero ) ) {
               Bottom[i]=0;                        // Нет фрактала
               break;
            }
            j++;
      }  }
      j=0;             // Поиск верхнего фрактала
      Top[i]=0;
      while( j<dim ){
         C[j]=High[j+i-БаровПравееВершины];
         j++;
      }
      if( C[БаровПравееВершины]-C[БаровПравееВершины+1]>-Zero
       && C[БаровПравееВершины]-C[БаровПравееВершины-1]>-Zero ){
         Top[i]=C[БаровПравееВершины];             // Локальный максимум
         j=1;
         while ( j < dim ){
            if( ( j<БаровПравееВершины && C[j-1]-Top[i]>Zero )
             || ( j>БаровПравееВершины && C[j]  -Top[i]>Zero ) ) {
               Top[i]=0;                           // Нет фрактала
               break;
            }
            j++;
      }  }
      if( Top[i]>Zero ){                           // Выбор вершины зигзага
         if( Bottom[i]>Zero ){                     // Top и Bottom
            if( LastIsTop || LastIsBottom ){       // Не начало зигзага
               Min[i]     =Bottom[i];              // Вертикальное колено
               Max[i]     =Top[i];
               LastBottom =Bottom[i];              // Запомнить Top и Bottom
               iLastBottom=i;
               LastTop    =Top[i];
               iLastTop   =i;
         }  }
         else{                                     // Top
            if( !LastIsTop ){                      // LastIsBottom, или
               Max[i]      =Top[i];                //    начало зигзага
               LastIsTop   =true;
               LastIsBottom=false; 
               LastTop     =Top[i];                // Запомнить Top
               iLastTop    =i;
            }
            else{                                  // LastIsTop
               if( Top[i]-LastTop>-Zero ){         // Перерисовка
                  Max[iLastTop]=0;
                  Max[i]       =Top[i];
                  LastTop      =Top[i];            // Запомнить Top
                  iLastTop     =i;
      }  }  }  }
      else{
         if( Bottom[i]>Zero ){                     // Bottom
            if( !LastIsBottom ){                   // LastIsTop, или
               Min[i]      =Bottom[i];             //    начало зигзага
               LastIsTop   =false;
               LastIsBottom=true; 
               LastBottom  =Bottom[i];             // Запомнить Bottom
               iLastBottom =i;
            }
            else{                                  // LastIsBottom
               if( LastBottom-Bottom[i]>-Zero ){   // Перерисовка
                  Min[iLastBottom]=0;
                  Min[i]          =Bottom[i];
                  LastBottom      =Bottom[i];      // Запомнить Bottom
                  iLastBottom     =i;
      }   }  }  }
      i--;
   }
   if( iLastTop>0 ) tLastTop=Time[iLastTop];       // Время крайних изломов
   if( iLastBottom>0 ) tLastBottom=Time[iLastBottom];
   return(0);
}

0 error(s), 0 warning(s) 1 1


 

Let's say I run an EA, then on the first tick using Bid, the EA has to remember this price to a certain point, maybe for a day, maybe for an hour.

What can be used to remember this price?

 
AlexeyVik:

And in your example int start()

I don't know why. (would like to know) why, but in 634 build, as well as in 711, int start() and without #property strict gives 0 values in the whole array if you declare an array without specifying its size...

 
With the help of memory. a=b, for example.
 
tara:

And it's best not to go beyond.

Here:

0 error(s), 0 warning(s) 1 1


So, it's not dynamic arrays in the example... It's a script, not an indicator... Don't take advantage of my inattention.
 
AlexeyVik:

I don't know why. (would like to know) why, but in 634 build, as well as in 711, in int start() and without #property strict it gives 0 values in the whole array if you declare an array without specifying its size...


#property strict means normal programming level. " I understand what I'm doing. "
 
gheka:

Let's say I run the Expert Advisor, then on the first tick using Bid, the Expert Advisor has to remember this price to a certain point, maybe for a day, maybe for an hour.

With what can I memorize it?

There is no trick. If you want to remember the value and not change it for some time, you should specify the condition

If(event) assign some value to a variable or array item.

In this case, the variable or array must be declared as a global variable, or static.

 
When you create a programme, you are always creating a universe that lives by the rules you and only you set.
Reason: