Drawing a square or rectangle. Really need help... - page 6

 
evillive:

So where does it work? It draws lines on every bar, not on the TF. Or in the picture above is TF=H1?

Count on a piece of paper what limit and i will be at each iteration of cycles.

My example shown above is never accounted for, as I understand it.

The tick arrows can be drawn using indicator buffers, as well as lines connecting candlestick shadows.

PERIOD_H;. Below H4 period everything is drawn well.

i = 0;

Limit is external variable by default = 5;

extern int barsToProcess = 5; //--- Number of periods (lines) to be displayed .

"Tick arrows can be drawn using indicator buffers, as well as lines connecting candlestick shadows. "

I understand it this way.

In the buffer with the index [Limit] the values of high from the Array are assigned.

double Buf_High[Limit] =mqlRates[0].high;

I understand how to circle on every bar. But I don't understand how to do it on every H4 bar.

 
Alex_Profit:

PERIOD_H;. Below the H4 period, all is drawing well.

i = 0;

Limit is an external variable by default = 5;

extern int barsToProcess = 5; //--- Number of displayed periods (lines) .

"Tick arrows can be drawn using indicator buffers, as well as lines connecting candlestick shadows. "

I understand it this way.

In the buffer with the index [Limit] the values of high from the Array are assigned.

double Buf_High[Limit] =mqlRates[0].high;

I understand how to circle on every bar. But I don't understand how to do it on every H4 bar.

Figure out how loops work before you use them.i = 0 only the first time, theni++, up to limit.

When first running the indicator limit=Bars-counted_bars=Bars-0=Bars.

The for loop in this case should theoretically count from 0 to the number of bars on the chart. BUT!!! The second while loop interferes here and it recalculates both i and limit.

I can't understand why I should have done so, and who taught me to do it...

Here is an example, we set: bars - 100, barsToProcess = 5.

During the first indicator run, counted_bars=0, have not been counted yet, therefore limit=100. It means that the loop for the beginning should be executed 100 times, from 0 to 99.

Iterations of the for loop:

1. i=0, limit=barsToProcess=5, while(i<5) - the internal loop with lines and ticks drawn is executed 5 times, from 0 to 4, every time i++, upon finishing while - i=5, limit=5.

2. i=5=limit - for loop is complete.

THIS IS IT! The indicator does not do anything further until the next tick. A tick comes, counted_bars=99, limit=Bars-counted_bars= 100-99=1.

The for loop is executed once, the while loop is not executed at all (since the condition if(limit>barsToProcess) is not fulfilled). We will continue until the indicator is unloaded from the chart or the timeframe is changed, in general, until reinitialization of the indicator.

In fact, the indicator draws its tick-lines once when it is loaded on the chart, and it remains idle until reinitialization. The question is why do we need such an indicator? The script can handle a single response.

 

I've rewritten the code. Everything seems to be correct with the loop.

There is still the question of drawing the "buffer" line.

#property strict 

#property indicator_chart_window


extern int     Total_bars = 5;        //--- Кол-во отображаемых Элементов в истории


    //---  Глобальные переменные    

string Name_VLine;     //--- Имя Элементов

string Name_CHECK;     //--- Имя Элементов


MqlRates    mqlRates[1]; //Структура для хранения информации 


#property indicator_buffers 1

#property indicator_type1   DRAW_LINE   // тип графического построения - линия 

#property indicator_color1  clrRed      // цвет линии 

#property indicator_style1  STYLE_SOLID // стиль линии 

#property indicator_width1  1           // толщина линии 


double Buff_High[];

 

//+------------------------------------------------------------------+

int OnInit()

  {

     return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

{

  

     SetIndexBuffer(0,Buff_High);     

     SetIndexStyle(0,DRAW_LINE);     

     SetIndexStyle(0,DRAW_SECTION);

     

//+------------------------------------------------------------------+

int limit;                                //--- переменная  старт кол-во баров. Линии рисуем о по всем барам

int counted_bars = IndicatorCounted();     //--- перем counted_bars = функц.  Возвращает количество баров

   

if(counted_bars > 0) counted_bars --;      //--- последний посчитанный бар будет пересчитан 

  //--- основной цикл 

  limit = Bars - counted_bars;         

  for(int i = 0; i <= limit; i ++)

   {

     if(limit > Total_bars)              //--- Если кол-во баров на графике > Кол-ву выбранных элементов 

      {

       limit = Total_bars-1;              //--- тогда кол-во баров на графике = Кол-ву выбранных элементов

      }

      

   datetime t_Line = iTime(Symbol(),PERIOD_H4,i);         //--- В ПЕРЕМ t_Line Будет Присваиваться значение времени открытия бара

   CopyRates(_Symbol, PERIOD_H4, t_Line, 1, mqlRates);    //--- Структура для хранения информации 

         

   //+------------------------ Рисуем вертикальную линии -----------------------------------------------------+                 

   ObjectCreate (Name_VLine + " VLine" + DoubleToStr(i,0),OBJ_VLINE,0,t_Line,0);         //--- Создаём обьект вертикальную линию

   ObjectSet    (Name_VLine + " VLine" + DoubleToStr(i,0),OBJPROP_STYLE,2);              //--- Со стилем

   ObjectSet    (Name_VLine + " VLine" + DoubleToStr(i,0),OBJPROP_COLOR,DimGray);        //--- Со цветом  

   ObjectSet    (Name_VLine + " VLine" + DoubleToStr(i,0),OBJPROP_WIDTH,0);              //--- С  толщиной

   ObjectSet    (Name_VLine + " VLine" + DoubleToStr(i,0),OBJPROP_BACK,0);               //--- С типом отображения. Объект на заднем плане


   //--- кубики по хай (В место галочек нужно подставить кубики)

   ObjectCreate    (0,Name_CHECK + "H_CHECK" + DoubleToStr(i,0), OBJ_ARROW_CHECK, 0, t_Line, mqlRates[0].high, t_Line,mqlRates[0].high);

   ObjectSetInteger(0,Name_CHECK + "H_CHECK" + DoubleToStr(i,0), OBJPROP_COLOR, clrGreen); 

   

   //--- кубики по лоу (В место галочек нужно подставить кубики)

   ObjectCreate    (0,Name_CHECK + "L_CHECK" + DoubleToStr(i,0), OBJ_ARROW_CHECK, 0, t_Line, mqlRates[0].low, t_Line,mqlRates[0].low);

   ObjectSetInteger(0,Name_CHECK + "L_CHECK" + DoubleToStr(i,0), OBJPROP_COLOR, clrGreen); 


  // На ТФ Н4 линии рисуются по хайям,

  // При смене ТФ линия рисуется на растоянии параметра Total_bars. 

  

   //--- Заполнение буфера

   Buff_High[i] = mqlRates[0].high ;  

  

   }

    return(rates_total);

}

//+------------------------------------------------------------------+


 
evillive:

Why I did that, who taught me, I don't understand...

I found a suitable indicator and "disassembled" it, until the fragment I needed remained. Then I assembled the code fragments and got what I needed. It goes like this.

"I'm learning."

 
Alex_Profit:

I've rewritten the code. Everything seems to be correct with the loop.

There is still the question of drawing the "buffer" line.

To paste the code there is SRC button on the top panel of message editing window, it inserts the code nicely and without empty lines.

The line will probably have to be drawn by objects too (trending), store the previous time/price in separate variables and use as second point coordinates.

To replace a tick with another symbol -OBJ_ARROW and ARROW_CODE.

 
evillive:

For code insertion there is SRC button on top panel of message editing window, inserts code nicely and without empty lines.

The line will probably have to be drawn by objects too (trend), store the previous time/price in separate variables and use as second point coordinates.

To replace a tick with another symbol -OBJ_ARROW and ARROW_CODE.

What is not to like

DRAW_SECTION

1

Line segments between non-empty line values

 
AlexeyVik:

А чем не нравится

DRAW_SECTION

1

Отрезки между непустыми значениями линии

I don't know how to apply it.

 
AlexeyVik:

What's not to like about

DRAW_SECTION

1

Line segments between non-empty values of the line

Evillive:

The line would probably have to be drawn by objects too (trend), store the previous time/price in separate variables and use as second point coordinates.

The idea is good. I'll give it a try if it works.

As a matter of fact, there is no need to draw it. Just as long as it works properly.

 

Alex_Profit:

I don't know how to apply it.

Simply in OnInit() instead of

SetIndexStyle(0, DRAW_LINE);

write

SetIndexStyle(0, DRAW_SECTION);

 

Somehow no change

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
  
     SetIndexBuffer(0,Buff_High);     
     //SetIndexStyle(0,DRAW_LINE);     
     SetIndexStyle(0,DRAW_SECTION);
Reason: