[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 632

 
alsu:

For example, you need to calculate a simple moving average with PeriodSMA. To calculate the SMA, add the values of the last PeriodSMA bars and divide by the PeriodSMA. It is obvious that for the bars with numbers Bars-1, Bars-2, ..., Bars-PeriodSMA+1 it will not work, because we simply do not have the necessary amount of bars for the calculation (the leftmost bar has Bars-1 index). Therefore, we have to start calculation of the indicator not with the last bar in the chart, but with the bar with the Bars-PeriodSMA index.

Why do they write this value, and not an arbitrary one? It is because this shift of the calculation start allows us to calculate the maximal amount of bars without prejudice to correctness of the calculation.

But keep in mind that this is the simplest case. Sometimes it may not be immediately clear from the code how many past bars the program needs for calculation and where exactly this shift comes from. Well, you should probably ask the developer who wrote the code. But in general, there is a universal way - just look at the code, what in principle the maximum index of the bar can be obtained using price data and index buffers data during the program operation, usually already at this stage it becomes clear...

Now everything is falling into place. Thank you Alexei for your responsiveness!
 
skyjet:


Thanks for the clarification!

And just to clarify, if I mechanically add 0, will TP and SL work in this type of terminal?


They will, of course they will.
That's what they are for, external variables, to set any values.

But it is easier to place in the initialisation module what you have been advised.
Or in this form:
// для терминала с 5 знаками
if (Digits == 3 || Digits == 5) {
   decimal = 10; // Определяет кол-во пунктов в четвертом(втором) знаке
   STOPLOSS *= decimal;
   TAKEPROFIT *= decimal;
   slippage *= decimal; // прочие целочисленные переменные в пунктах
} else decimal = 1;
Variables will be adjusted automatically, and for other needs use multiplier "decimal".
 
skyjet:


Спасибо за разъяснения!

И просто чтобы уточнить, если я механическим путем добавлю 0, то TP и SL будут работать в данном типе терминалов?

prorab:

They will, of course.
That's what they are for, external variables, to set any values.

But it's easier still to put what you've been advised to do in the initialization module.
Or in this form:
Variables will be automatically adjusted, and for other needs use multiplier "decimal"

This task needs clarification:

  • Your input parameters (STPOLOSS, TAKEPROFIT, etc.) must be entered with 4\2 digits in mind!!!
 

Good afternoon...

SOS!!! GOOD PEOPLE, HELP!!! I am a beginner in programming in general (I am self-taught), and in MQL in particular. I wrote a simple indicator: RSI + Bollinger Bands in one person. But here is the trouble: if I do not expressly specify the quantity of elements in the array Buf_std_dev (i.e. the array declaration line looks like this: double Buf_std_dev[]), then when displaying this indicator in the client terminal window(CT) I get the following picture:

Explanation of the picture:

a) at the top is RSI, which is available in the set of indicators supplied with CT, and the Bollinger Bands have been dragged to the window of this RSI by drag and drop);

b) at the bottom is the RSI, which is programmed by me;

The compiler does not detect any errors or warnings.

 

If, on the other hand, when declaring array Buf_std_dev, I explicitly specify number of elements in it (i.e., the array declaration line looks like this: double Buf_std_dev[5502], where 5502 is number of bars, which is obtained using variable Bars), then everything goes back to normal (for as seen from comparison of two indicators: all values are the same):

Can you tell me what to do to save the image, as on the second picture, but explicitly NOT to set the number of elements in the array Buf_std_dev.

P.S. Thank you in advance for the answer.

 
Show all the code
 

Code attached (without some parts - can't fit in 4 MB!!!):

....
double Buf_rsi[];                                                       //открываем индикаторный массив для значений RSI+
double Buf_ma[];                                                        //открываем индикаторный массив для значений скользящей средней по RSI+
double Buf_up_line[];                                                   //открываем индикаторный массив для значений ВЛБ по RSI+
double Buf_down_line[];                                                 //открываем индикаторный массив для значений НЛБ по RSI+
double Buf_std_dev[5498];                                               //открываем массив для хранения данных по стандартному отклонению  

string timeframe[9];                                                    //объявляем массив для значений таймфреймов
extern int Период_RSI=14;                                               //внешняя переменная: период RSI+
extern int Применить_к=PRICE_CLOSE;                                     //внешняя переменная: цена, для к-й рассчитывается RSI+
extern int Сдвиг=0;                                                     //внешняя переменная: сдвиг относительно текущего графика RSI+
extern double Сигма=2.0;                                                //внешняя переменная: количество стандартных отклонений для расчета лент Боллинджера по RSI+
extern int МА=21;                                                       //внешняя переменная: период скользящей средней для расчета лент Боллинджера по RSI+
....
   if(Bars<=Период_RSI) return(0);                                      //если баров на графике меньше, чем период RSI+, то выходим
//+-------------------------------------------------------------------------------------- 9 --
   int counted_bars=IndicatorCounted();                                 //количество посчитанных баров
   int i;                                                               //техническая переменные: счетчики

   int limit=Bars-counted_bars;                                         //индекс первого непосчитанного по массиву Buf_ma (т.к. этот массив НЕ является массивом таймсерией)
   if(counted_bars<0)limit--;                                           //если значение переменной counted_bars больше 0, то увеличиваем на 1 значение переменной limit
//+-------------------------------- Рассчет линий индикатора ---------------------------- 10 --
   for(i=0;i<=limit;i++)Buf_rsi[i]=iRSI(NULL,0,Период_RSI,Применить_к,i);//рассчет значения RSI+ на i-ом баре      
   for(i=0;i<=limit;i++)                                                //цикл по рассчету линий на основе RSI+     
       {                                                                //начало for
        Buf_std_dev[i]=iStdDevOnArray(Buf_rsi,Bars,МА,Сдвиг,MODE_SMA,i);//рассчитываем стандатное отклонение по массиву RSI+
        Buf_ma[i]=iMAOnArray(Buf_rsi,Bars,МА,Сдвиг,MODE_SMA,i);         //рассчет значения MA по RSI+ на i-ом баре
        Buf_up_line[i]=Buf_ma[i]+Сигма*Buf_std_dev[i];                  //рассчет значения ВЛБ по RSI+
        Buf_down_line[i]=Buf_ma[i]-Сигма*Buf_std_dev[i];                //рассчет значения НЛБ по RSI+
       }                                                                //конец for
   for(i=0;i<=Bars;i++)                                                 //цикл по подсчету количества данных внутри ЛБ
      {                                                                 //начало for
       int sum;                                                         //техническая переменные: сумма данных, к-е находятся внутри ЛБ 
       if(Buf_rsi[i]>Buf_down_line[i]&&Buf_rsi[i]<Buf_up_line[i])sum++; //если значение RSI+ > НЛБ и значение RSI+ < НЛБ, то переменная sum увеличиваестся на 1 (т.о.)
      }                                                                 //конец for
//+------------------------------------------------------------------------------------- 11 --
 
FAQ:
Show all code

Please advise if there are ways to dump code over 4Mb here (or dump it here in parts?) ?
 

If your Buf_std_dev is not an indicator buffer (one of the eight), you need to specify its size, or any size (if you intend to change it (size) in the future) when declaring it.

 

Right, it isn't... If I may, then two more questions at once:

1. If I assign a buffer to it (the array Buf_std_dev) , it means that it will be displayed in the indicator window, as well?

If I don't assign a buffer to it, then (if I understand correctly) the following situation will occur: assume that I have specified the size of 100 bars. Then when new bars appear (i.e. if for example Bars=101), we will perform calculations only for the last 100 bars we specified (i.e. the oldest bar - 101 - will be discarded). So, when loading history, the array size will always be equal to 100 bars only (or some other value, which I will specify when declaring)?

Reason: