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

 

Hello! I've started to learn mquel4. I will use an example of a simple indicator that calculates max and min candle prices and draws lines at candle extremums through two buffers on the screen:

#property indicator_chart_window // Индик. рисуется в основном окне
#property indicator_buffers 2 // Количество буферов
#property indicator_color1 Blue // Цвет первой линии
#property indicator_color2 Red // Цвет второй линии

double Buf_0[],Buf_1[]; // Объявление массивов (под буферы индикатора)
//--------------------------------------------------------------------
int init() // Специальная функция init()
{
SetIndexBuffer(0,Buf_0); // Назначение массива буферу
SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);// Стиль линии
SetIndexBuffer(1,Buf_1); // Назначение массива буферу
SetIndexStyle (1,DRAW_LINE,STYLE_DOT,1);// Стиль линии
return; // Выход из спец. ф-ии init()
}
//--------------------------------------------------------------------
int start() // Специальная функция start()
{
int i,// Индекс бара
Counted_bars; // Количество просчитанных баров 
//--------------------------------------------------------------------
Counted_bars=IndicatorCounted(); // Количество просчитанных баров 
i=Bars-Counted_bars-1;
// Индекс первого непосчитанного
while(i>=0) // Цикл по непосчитанным барам
{
Buf_0[i]=High[i]; // Значение 0 буфера на i-ом баре
Buf_1[i]=Low[i]; // Значение 1 буфера на i-ом баре

i--; // Расчёт индекса следующего бара
}
//--------------------------------------------------------------------
return; // Выход из спец. ф-ии start()
}

So, how to make the buffer line go through two (three, etc.) candlesticks instead of each one?

 
wolf05632:

So, how do I make the buffer line go through two (three, etc.) candles instead of every candle?

First, learn how to insert a message into the code correctly, using the "SRC" button, so that it has a readable form and looks just like in MetaEditor.


The second step will be your attempt to link the Counted_bars variable to the if statement.

For example:

We'll enter an indicator calculation every second bar (skip the odd ones, leave the even ones):

if (MathMod(Counted_bars, 2) == 0)
{
   // расчёт для буферов индикатора
}
else return(0);

Here you can read about function MathMod(). But you don't have to use it. You can insert any condition in the if statement.

But don't forget that such code modifications will cause loss of some values in the buffer. Whether you need it or not, I don't know. Everything will depend on your task.

 

I'm a little confused. I tried to make the cycle step equal to two (I think you would have the same meaning), but it doesn't work. I don't need to go through one specifically, but through an arbitrary number of candles. My understanding is that the structure should be like this:

buffer array[1]= array of candlesticks[1]

buffer array[2]= array of candlesticks[2]

buffer array[3]= array of candlesticks[4]

...

buffer array[5]= array of candlesticks[x] etc. But it doesn't work.

 
wolf05632:

I don't see a pattern between the buffer indices and the candlestick indices...

And it would be even better if you attached a picture of what you want to get.

 

It goes like this

And I need it like this:

But don't be attached specifically to the lines being drawn through a candle, they can be drawn through two, or three, etc.

 
sergeev:

I think we should have taken this down to the telepaths instead of here.

He's just messing with us.


Look at the code, you can see without spaces where the result of sending the order, its error code and digits for the instrument.
 

Then you have to use a zig-zag like indicator (My point of view):

#property indicator_chart_window // Индик. рисуется в основном окне
#property indicator_buffers 2 // Количество буферов
#property indicator_color1 Blue // Цвет первой линии
#property indicator_color2 Red // Цвет второй линии

double Buf_0[], Buf_1[]; // Объявление массивов (под буферы индикатора)
//--------------------------------------------------------------------
int init() // Специальная функция init()
{
   SetIndexBuffer(0, Buf_0); // Назначение массива буферу
   SetIndexStyle (0, DRAW_SECTION);
   SetIndexBuffer(1, Buf_1); // Назначение массива буферу
   SetIndexStyle (1, DRAW_SECTION);
   return; // Выход из спец. ф-ии init()
}
//--------------------------------------------------------------------
int start() // Специальная функция start()
{
   int i,// Индекс бара
   Counted_bars; // Количество просчитанных баров 
   //--------------------------------------------------------------------
   Counted_bars=IndicatorCounted(); // Количество просчитанных баров 
   if (MathMod(Bars, 2) != 0 && Counted_bars == 0)
      return(0);
   i = Bars-Counted_bars-1;
   // Индекс первого непосчитанного
   while(i >= 0) // Цикл по непосчитанным барам
   {
      if (MathMod(i, 2) == 0)
      {
         Buf_0[i] = High[i]; // Значение 0 буфера на i-ом баре
         Buf_1[i] = Low[i]; // Значение 1 буфера на i-ом баре
      }
   
      i--; // Расчёт индекса следующего бара
   }
   //--------------------------------------------------------------------
   return; // Выход из спец. ф-ии start()
}

I think you can figure out the changes. The only thing I was wrong about, it's better to use Bars parameter instead of IndicatorCounted() as an index of bar to be calculated.

Your task now is to take the divider into an external parameter. It will be equal to the number of candlesticks passed.

 
grell:

Just look at the code, you can see without spaces where the result of sending the order, its error code and digits for the instrument.

Exactly. That's why we are talking about telepaths.

You gave us the code earlier:

Alert("Ordersend_Number",res,err);

I did not look through the code, but, unfortunately, I failed to find the error... I have no experience in writing multicurrency Expert Advisors. I just know some principles, that's all.

 
It's obvious that -1129 is the error code, where did you see error number 1292?
 
grell:
It is clear that -1129 is an error code, where did you see error number 1292?

Anything can happen...

Have you only tested your EA on one DC? Does error 129 take a long time to appear? Or the order opens after several requests?