Questions from Beginners MQL5 MT5 MetaTrader 5 - page 874

 

Hello, could you advise please, in the code below without the loop block (which comes after the CopyByffer), the indicator normally runs, but if you include a cycle comparing the price of a candle with the price of one of the bars, the bars themselves after the start are not displayed, what could be the problem?

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots   3
#property indicator_type1   DRAW_LINE
#property indicator_color1  Olive
#property indicator_type2   DRAW_LINE
#property indicator_color2  Green
#property indicator_type3   DRAW_LINE
#property indicator_color3  Olive

input int peroid = 20;        // период полос 1
input int bands_shift= 0;           // смещение полос 1 
input double deviation = 2.3;   // отклонение полос 1

input ENUM_APPLIED_PRICE   applied_price=PRICE_CLOSE; // тип цены 

double      Base[];     // массив для BASE_LINE индикатора iBands
double      Upper[];    // массив для UPPER_BAND индикатора iBands
double      Lower[];    // массив для LOWER_BAND индикатора iBands

int iBands1_handle; //Указатель на первый индикатор 
int iBands2_handle; //Указатель на первый индикатор 

int g_i_Window;


int OnInit()
  {
   g_i_Window=ChartWindowFind();
   SetIndexBuffer(0,Base,INDICATOR_DATA);
   SetIndexBuffer(1,Upper,INDICATOR_DATA);
   SetIndexBuffer(2,Lower,INDICATOR_DATA);
           
   iBands1_handle=iBands(NULL,PERIOD_CURRENT,peroid,bands_shift,deviation,applied_price);

   if(iBands1_handle==INVALID_HANDLE){
         Alert("Неудалось загрузить индикатор, повторите попытку");
         return(-1);
         }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,      // размер входных таймсерий 
                 const int prev_calculated,  // обработано баров на предыдущем вызове
                 const datetime& time[],     // Time 
                 const double& open[],       // Open 
                 const double& high[],       // High 
                 const double& low[],        // Low 
                 const double& close[],      // Close 
                 const long& tick_volume[],  // Tick Volume 
                 const long& volume[],       // Real Volume 
                 const int& spread[])         // Spread 
  {
   int i;
   int shift = 0;
   int shift1;
   int shift2;
   int shift3;
   string alert;
   
   double O, O1, O2, C, C1, C2, L, L1, L2, H, H1, H2;
      shift1 = shift;
      shift2 = shift + 1;
      shift3 = shift + 2;   
      O = open[shift1];
      O1 = open[shift2];
      O2 = open[shift3];
      H = high[shift1];
      H1 = high[shift2];
      H2 = high[shift3];
      L = low[shift1];
      L1 = low[shift2];
      L2 = low[shift3];;
      C = close[shift1];
      C1 = close[shift2];
      C2 = close[shift3]; 
   
   i = (prev_calculated==0)?1: prev_calculated;
   i = (prev_calculated==rates_total)?rates_total-1: i;
   
   CopyBuffer(iBands1_handle,0,0,rates_total-1,Base);
   CopyBuffer(iBands1_handle,1,0,rates_total-1,Upper);
   CopyBuffer(iBands1_handle,2,0,rates_total-1,Lower);

   for (i = i; i < rates_total; i++)
   {
    if(H > L && O > Lower[i])
    {
     int time_waiting = (int)TimeLocal() + 1;
     while(TimeLocal() < time_waiting){}
     Comment("True");
     return(0);
    }
     else Comment("False"); 
   }
   
   
   if (prev_calculated==0) ChartRedraw();   
   return(rates_total);
  }

Result:


 
Aleksey Vyazmikin:

You can not.

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

Alexey Viktorov, 2018.05.30 15:53

Well, not quite so dynamically, but once through re-initialization you can. I did.


 
Alexey Viktorov:

If you can elaborate, please describe

 
Andrii Djola:

if you can be more specific

How much more detailed?

In one situation I needed to make coloured bars or coloured candlesticks. They use 4 value buffers and 1 colour buffer. The other, I needed to display a coloured line, where 1 value buffer and 1 colour buffer.

Calling and changing indicator properties causes initialization of the indicator. Accordingly, if the settings contain bars or candlesticks, then one option of initialization. If the line, the other option of initialization.

It is impossible to change the number of buffers in the middle of the indicator, which is what Alexey Vyazmikin said without being aware of the other options.

 
Alexey Viktorov:

How much more detail?

In one situation I needed to make coloured bars or coloured candlesticks. They use 4 value buffers and 1 colour buffer. Another, I needed to display a coloured line, where 1 value buffer and 1 colour buffer.

Calling and changing indicator properties causes initialization of the indicator. Accordingly, if the settings contain bars or candlesticks, then one option of initialization. If a line, then another initialization option.

It is impossible to change the number of buffers in the middle of the indicator, which is what Alexey Vyazmikin said, without being aware of other options.

If you decide to write my last name in Russian, it sounds like Vyazmikin.

Regarding my suspicions - I think the answer is correct to the question posed. Without an explanation of needs there is no point in saying otherwise. Reinitialisation is a restart of the program, it is clear that you can change anything in the settings.

 
Aleksey Vyazmikin:

If you choose to write my surname in Russian, it sounds like Vyazmikin.

Regarding my suspicions - I believe the answer to the question posed is correct. Without an explanation of the needs, there is no point in saying otherwise. Reinitialisation is a restart of the program, it is clear that you can change anything in the settings.

Does the lack of a soft sign offend that much?

Did I talk about incorrectness, in my opinion I emphasised exactly the correctness of the answer.

 
alph:
Can you tell me if this is a realistic tester figure? And is it good or bad result for a year with a deposit of 3000$?
real.
 
Alexey Viktorov:

Does the lack of a soft sign offend that much?

I am driven by enlightenment, not offence. Why would I be offended, did you know how to spell and want to offend me? I didn't even consider that option, was it for nothing?

 
Aleksey Vyazmikin:

I am motivated by enlightenment, not resentment. Why should I be offended, did you know how to write correctly and want to offend me? I didn't even consider that option, was it for nothing?

Peace, friendship, chewing gum.

 
Alexey Viktorov:

Peace, friendship, gum.

And the half-litres?

Reason: