Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1136

 
Iurii Tokman:

Here is the code that draws a line on M5:

      int Price_high  = iHighest(Symbol(), 0, MODE_HIGH, 11, 1);
       int Price_low   = iLowest(Symbol(), 0, MODE_LOW, 11, 1);
            
       ObjectCreate("TrendLine", OBJ_TREND, 0, Time[11], NormalizeDouble( (High[Price_high] + Low[Price_low])/2, Digits), Time[1], 
                     NormalizeDouble( (High[Price_high] + Low[Price_low])/2, Digits));

I would like a line to be drawn at the beginning of each hour on M5 that will not be connected to the previous ones. I.e. just a horizontal line, not a broken line. The line is the average price of the previous hour.

And if you remove the *beam* property of this line, it would be great.

 
      
int Price_high  = iHighest(Symbol(), 0, MODE_HIGH, 11, 1);
int Price_low   = iLowest(Symbol(), 0, MODE_LOW, 11, 1);

if(!NewBar(PERIOD_H1)) return;
            
ObjectCreate("TrendLine", OBJ_TREND, 0, Time[11], NormalizeDouble( (High[Price_high] + Low[Price_low])/2, Digits), Time[1], 
              NormalizeDouble( (High[Price_high] + Low[Price_low])/2, Digits));


//---
//---
bool NewBar(ENUM_TIMEFRAMES TF = 0)
  {
   static datetime NewTime=0;
   if(NewTime!=iTime(Symbol(),TF,0))
     {
      NewTime=iTime(Symbol(),TF,0);
      return(true);
     }
   return(false);
  }
//----
 
Iurii Tokman:

It doesn't work. It only draws one line at start-up and that's it.

void OnTick()
{
  
int Price_high  = iHighest(Symbol(), 0, MODE_HIGH, 11, 1);
int Price_low   = iLowest(Symbol(), 0, MODE_LOW, 11, 1);

if(!NewBar(PERIOD_H1)) return;
            
ObjectCreate("TrendLine", OBJ_TREND, 0, Time[11], NormalizeDouble( (High[Price_high] + Low[Price_low])/2, Digits), Time[1], 
              NormalizeDouble( (High[Price_high] + Low[Price_low])/2, Digits));

}
//+------------------------------------------------------------------+ 
//---
bool NewBar(ENUM_TIMEFRAMES TF = 0)
  {
   static datetime NewTime=0;
   if(NewTime!=iTime(Symbol(),TF,0))
     {
      NewTime=iTime(Symbol(),TF,0);
      return(true);
     }
   return(false);
  }
//----
//+------------------------------------------------------------------+
 
Snajper007:

It doesn't work. It only draws one line at start-up and that's it.

How many do you need?

 
Iurii Tokman:

How much do you need?

I would like a line to be drawn at the beginning of each hour on M5 that will not be connected to the previous ones. I.e. just a horizontal line, not a broken line. The line is the average price for the previous hour.
 
Snajper007:
I would like to see a line drawn at the beginning of each hour on M5 that will not be connected to the previous ones. I.e. just a horizontal line, not a broken line. The line is the average price of the previous hour.

middle of the bar H1 ?

 
Iurii Tokman:

middle of the bar H1 ?

Yes, only on M5.
 
Snajper007:
Yes, only on the M5.

draw a picture as it should be, and not with one line

 
Iurii Tokman:

draw a picture as it should be, and not with one line

Here's
Files:
 
Snajper007:
***

By the way, why draw exactly with the Horizontal Line graphical object? Wouldn't it be better to do it with an indicator andDRAW_ARROW style?

Something like this display:

Resistance and Support 2

Reason: