Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1483

 
Alexey Viktorov:

Note the conversion of time and price to XY coordinates in pixels

Read line price, convert it to pixels and assign coordinatesto "Text Mark" object on Y axis, while X coordinate remains unchanged.

I've been looking at this function for a long time, but didn't know how to go about it because I'm not experienced enough. Thanks, I'll try to integrate it into code.

 
Aleksei Stepanenko:

Line And Text Indicator Ver 1

The indicator moves the text following the line. Insert the name of the line in the input parameter.

Thank you. This is also an interesting layout. I will definitely take it out, as soon as I figure out ChartTimePriceToXY().

 

Can you please tell me what could be wrong?

   for(int i=rates_total-prev_calculated-2;i>=0;i--)
     {
      ADRBuffer1[i]=High[i];
      if(High[i]<ADRBuffer1[i+1])
      ADRBuffer1[i]=ADRBuffer1[i+1];
      ADRBuffer2[i]=Low[i];
      if(Low[i]>ADRBuffer2[i+1])
      ADRBuffer2[i]=ADRBuffer2[i+1];
     }

Low draws but High doesn't want to...

 
MakarFX:

Can you please tell me what could be wrong?

Low draws but High doesn't want to...

What is ADRBuffer1[i+1] equal on first run? Probably there is more rubbish than High[i]

 
Alexey Viktorov:

What does ADRBuffer1[i+1] equal on first run? Probably there is more rubbish than High[i].

Please tell me how to fix it and why Low draws fine?

All code

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDimGray
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrCrimson
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrTeal
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- indicator buffers
double   ADRBuffer0[];
double   ADRBuffer1[];
double   ADRBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorDigits(Digits);
//--- indicator buffers mapping
   SetIndexBuffer(0,ADRBuffer0,INDICATOR_DATA);
   SetIndexBuffer(1,ADRBuffer1,INDICATOR_DATA);
   SetIndexBuffer(2,ADRBuffer2,INDICATOR_DATA);
   SetIndexLabel(0,"ADR");
   SetIndexLabel(1,"ADR1");
   SetIndexLabel(2,"ADR2");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---
   if((rates_total-prev_calculated-2)<=0)return(0);
   for(int i=rates_total-prev_calculated-2;i>=0;i--)
     {
      ADRBuffer1[i]=High[i];
      if(High[i]<ADRBuffer1[i+1])
      ADRBuffer1[i]=ADRBuffer1[i+1];
      ADRBuffer2[i]=Low[i];
      if(Low[i]>ADRBuffer2[i+1])
      ADRBuffer2[i]=ADRBuffer2[i+1];
     }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
MakarFX:

Can you please tell me how to fix and why Low draws normally?

The whole code

The number of constructions must necessarily be declared. And try writing the buffer initialization with zero, provided that prev_calculate == 0;

 
Alexey Viktorov:

It is obligatory to declare the number of constructions.

It's not clear to me, unfortunately, what this means.

Alexey Viktorov:

And try writing the buffer initialisation with zero, provided that prev_calculate == 0;

Didn't help(

 
MakarFX:

I unfortunately don't understand what it means.

It didn't help(


if( prev_calculated == 0 ) {
   ADRBuffer1[rates_total-1] = High[rates_total-1];
   ADRBuffer2[rates_total-1] = Low[rates_total-1]
}

for(int i=rates_total-prev_calculated-2;i>=0;i--)
{
...
}
 
MakarFX:

I unfortunately don't understand what it means.

It didn't help(

#property indicator_plots   3

The default is 1. And if announcing the number of constructions doesn't help, then proceed to option B.

 
PapaYozh:


Thank you, it helped...I didn't do it right)))
Reason: