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

 
Sorry to bother you again, but a question has come up. There is a Color Level indicator for MT4, in its set there are line segments, which are created from TrendCreate trend line, which has 4 anchor points - date and price, and if I extend it further as a level, I have to press Shift. Is it possible to change the TrendCreate property like the HLineCreate, i.e. to have the segment as from the level, or maybe there is a way to make the segment by HLineCreate itself? I mean to make the segment behave like a level, not a trend line
 
DYM:
Sorry to bother you again, but a question has come up. There is a Color Level indicator for MT4, it has line segments in its set which are created from TrendCreate line that has 4 anchor points - date and price, and if I stretch it further as a level I have to hold Shift. Is it possible to change the TrendCreate property like the HLineCreate, i.e. to have the segment as from the level, or maybe there is a way to make the segment by HLineCreate itself? I mean to make the segment behave like a level, not a trend line

The question is not clear...

Why hold down Shift? The lines move however you want. If you move by the centre point, the slope does not change.

If you want to change the length of the line in the indicator, add the yellow highlight to the code

extern   int               x_coor         =  10;                  // Coordinate X
extern   int               y_coor         =  20;                  // Coordinate Y

extern   int               x_size         =  155;                 // длина объектов
 
Waaaaaaaaaaaaaaaaaaa. Help me solve the problem. I can't figure out what's wrong. It's not even testing in the tester. What is missing there? Why is it executed on each candle, and not on the arrow? I'm going crazy already((((
Files:
123.mq4  10 kb
 
MakarFX:

The question is not clear...

Why hold down Shift? The lines move however you want. If you move by the centre point, the slope does not change.

If you want to change the length of the line in the indicator, add the highlighted yellow line to the code

I made a gif, the first line has trend line properties, the second one has level properties (it seems that way to me). I would like to understand how you can make a line segment have the properties of the second line.

Files:
line.gif  2022 kb
 
DYM:

I made a gif, the first line has trend line properties, the second line has level properties (well, it seems that way to me). I would like to understand how a line segment can have the properties of the second line.

double a=ObjectGetDouble(ChartID,name,OBJPROP_PRICE1);
double b=ObjectGetDouble(ChartID,name,OBJPROP_PRICE2);
if(b!=a) ObjectSetDouble(ChartID,name,OBJPROP_PRICE2,a);
 
MakarFX:

Igor, thank you, but MT4 is not working correctly.


Can you tell me what to fix?

This code should work:

#property copyright "IgorM"
#property link      "https://www.mql5.com/ru/users/igorm"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1

// plot ZigZagZZ
#property indicator_label1  "ZigZagZZ"
#property indicator_type1   DRAW_SECTION
#property indicator_color1  clrDarkBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  3
// input parameters
input int   Deviation=10;
// indicator buffers
double         ZZBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
// indicator buffers mapping
   SetIndexBuffer(0,ZZBuffer,INDICATOR_DATA);
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
   SetIndexEmptyValue(0,0.0);
   //PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
   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[])
  {
   static bool UP;
   static double max,min;
   static int LastExt=rates_total - 1;
   static const double dev=NormalizeDouble(Deviation*_Point,_Digits);
   int limit=LastExt;
   if(prev_calculated==0)
     {
      ArrayInitialize(ZZBuffer,0.0);
      limit = LastExt = rates_total - 1;
      if(low[0]<high[1]) { min=low[limit];  max=high[limit - 1];   UP=true;  }
      else               { max=high[limit]; min  = low[limit - 1]; UP=false; }
     }
   for(int i=limit; i>=0; i--)
     {
      ZZBuffer[i]=0.0;
      if(UP)
        {
         if(low[i]-min<=0.0) { min=low[i]; ZZBuffer[LastExt]=0.0; LastExt=i; ZZBuffer[i]=min; }
         else
           {
            if(high[i]-min-dev>0.0) { max=high[i]; LastExt=i; ZZBuffer[i]=max; UP=false; }
           }
        }
      else
        {
         if(high[i]-max>=0.0) { max=high[i]; ZZBuffer[LastExt]=0.0; LastExt=i; ZZBuffer[i]=max; }
         else
           {
            if(low[i]-max+dev<0.0) { min=low[i]; LastExt=i; ZZBuffer[i]=min; UP=true; }
           }
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Igor Makanu:

this code should work:

Thank you very much! It all works...now I'll try to figure out the logic (the zig-zag construction is difficult for me to understand).
 
MakarFX:
Thanks so much! Everything works...now I'll try to figure out the logic(building a zigzag is difficult for me to understand).

did not check, ran it - it draws

The logic is simple - look for the number of bar in which one of the conditions occurs and store it in the code

static int LastExt

and then compare this bar with the next one, if it is a break in phase, we will memorize this bar in static int LastExt

 
Igor Makanu:

did not check, ran it - it draws

The logic is simple - look for the number of bar in which one of the conditions occurs and store it in the code

and then you compare this bar with the next one and if there is a break in phase, you store it in static int LastExt

Now everything is lined up in my head) Thank you, Igor.

 
MakarFX:

I'm having trouble with this, I understand the price1 anchor point, but I can't figure out how to make the condition. My variant doesn't work.

extern ENUM_LINE_STYLE  line_st   =  STYLE_SOLID;         // 9. Стиль линий
extern int              line_wd   =  2;                   // 10. Толщина линий
// Координаты
extern int x_coor = 7;    // Сдвиг по оси X
extern int y_coor = 10;    // Сдвиг по оси Y
//-- глобальные переменные
string line[6] = {"line_1","line_2","line_3","line_4","line_5","line_6"};

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
  
   datetime dt1     = 0;
   double   price1  = 0;
   datetime dt2     = 0;
   double   price2  = 0;
   int      window   = 0;
   int      x        = 0;
   int      y        = 0;

//+------------------------------------------------------------------+
   //--- Клик по 1 линии
   if(id==CHARTEVENT_OBJECT_CLICK)
     {
      string clickObject=sparam;
      if(clickObject==line[0])
        {
         string name="line_"+IntegerToString(MathRand()+100,0,' ');

         y=210;
         ChartXYToTimePrice(0,x_coor+25,y,window,dt1,price1);
         ChartXYToTimePrice(0,x_coor+157,y,window,dt2,price2);

         TrendCreate(0,name,0,dt1,price1,dt2,price2,color2,line_st,line_wd,false,true,false,false,false,0);
         
           price1=ObjectGetDouble(id,name,OBJPROP_PRICE1);
           price2=ObjectGetDouble(id,name,OBJPROP_PRICE2);
             if(price2!=price1) 
           {
            ObjectSetDouble(id,name,OBJPROP_PRICE2,price1);
           }

        }
     }
}
//+------------------------------------------------------------------+
Reason: