I will write the indicator for free - page 98

 
Aleksei Stepanenko:

I can only help a little, absolutely free.

There are two functions at the bottom of the indicator. In the comments it displays the value of the indicator itself and the value of the current point on the last trend line.

Figure it out.

Thank you, Alexei. Have a good day.
 
A-V-K:
Thank you, Alexei. Have a good day.

.

 

Good afternoon!

I wrote the following indicator


//+------------------------------------------------------------------+
//|                                                      MTF_H&L.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020"
#property strict
#property indicator_chart_window
#property indicator_buffers   2
#property indicator_width1    1
#property indicator_color1    clrTeal
#property indicator_type1     DRAW_LINE
#property indicator_width2    1
#property indicator_color2    clrCrimson
#property indicator_type2     DRAW_LINE
//---
input ENUM_TIMEFRAMES   period01 =  PERIOD_D1;
input ENUM_TIMEFRAMES   period02 =  PERIOD_M15;
input int               percount =  10;         //Ограничение истории

double Buffer1[];
double Buffer2[];
int    index1=-1;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   SetIndexBuffer(0, Buffer1, INDICATOR_DATA);
   SetIndexBuffer(1, Buffer2, INDICATOR_DATA);
//---
   IndicatorDigits(Digits);
   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[])
  {
//---
   int i, limit, barcount;
   barcount=period01/Period()*percount;
   if(barcount != 0) limit = barcount; 
   else limit = rates_total - 2;
   
   for(i=limit;i>=0;i--)
   {
      if(TimeSeconds(time[i])==0)
      index1=iBarShift(Symbol(), period02, time[i], false);

      if(TimeHour(time[i])==0&&TimeMinute(time[i])<period02)
      {
      Buffer1[i]=iOpen(NULL,period02,index1);
      Buffer2[i]=iOpen(NULL,period02,index1);
      }
      else 
      {
      Buffer1[i]=iHigh(NULL,period02,index1);
      if(Buffer1[i]<Buffer1[i+1]){
      Buffer1[i]=Buffer1[i+1];}
      
      Buffer2[i]=iLow(NULL,period02,index1);
      if(Buffer2[i]>Buffer2[i+1]){
      Buffer2[i]=Buffer2[i+1];}
      }
   }
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+

Please help me to correct the indicator or tell me how.

1) I don't know how to set the reference point "period01", so that the indicator would start with "iOpen" at the beginning of a new period.

2) I don't know how to use "iHighest" so I don't have to use such "crutches".

if(Buffer1[i]<Buffer1[i+1]){
   Buffer1[i]=Buffer1[i+1];}

Please help.

 
MakarFX:

Good afternoon!

I wrote the following indicator


Please help me to correct the indicator or tell me how.

1) I don't know how to set the reference point "period01", so that the indicator would start with "iOpen" at the beginning of a new period.

2) I don't know how to use "iHighest" so I don't have to use such "crutches".

Please help.

Why did you write it?

 
Алексей Тарабанов:

Why did you write it?

Looking for a pattern...

if moved to the basement it looks like this


 
MakarFX:

Good day!

Greetings, Makar!

What is the opening price for here ? To take the extremums of the first bar immediately. Like this one:

if(i==limit || TimeDay(time[i])!=TimeDay(time[i+1]))
   {
   Buffer1[i]=iHigh(NULL,period02,index1);
   Buffer2[i]=iLow(NULL,period02,index1);
   }
else
   {
   if(iHigh(NULL,period02,index1)-Buffer1[i+1]>0)
      {
      Buffer1[i]=iHigh(NULL,period02,index1);
      }
   else
      {
      Buffer1[i]=Buffer1[i+1];
      }
   if(Buffer2[i+1]-iLow(NULL,period02,index1)>0)
      {
      Buffer2[i]=iLow(NULL,period02,index1);
      }
   else
      {
      Buffer2[i]=Buffer2[i+1]; 
      }
   }
Or have I got the idea wrong?
 
Aleksei Stepanenko:

Greetings, Makar!

What is the opening price for here ? To take the extremums of the first bar immediately. Like this one:

Or did I get the idea wrong?

I wrote.

1) I do not know how to set the reference point "period01" so that the indicator would start with "iOpen" at the beginning of a new period.

To take right away the extrema of the first bar is correct and I take your code after "else". Thank you.

But here

if(i==limit || TimeDay(time[i])!=TimeDay(time[i+1]))

it does not fit, because it is linked to the beginning of the day and I need the "period01" selection - H1;H4; and so on

 

Alternatively, you could divide the current date by the number of seconds in the timeframe and then compare the resulting value with the previous value:

int part=0;

int OnCalculate(......)
   {

   for(......)
      {
      if(time[i]/PeriodSeconds(period01)>part)
         {      
         part=time[i]/PeriodSeconds(period01);
      
         Buffer1[i]=iHigh(NULL,period02,index1);
         Buffer2[i]=iLow(NULL,period02,index1);
         }
      else
.......
      

The start will probably not be synchronised with the chart, but the timing bars will count correctly. You could think about how to synchronise the first start,

such as:

if(time[i]%PeriodSeconds(period01)==0)
 
Aleksei Stepanenko:

Alternatively, you could divide the current date by the number of seconds in the timeframe and then compare the resulting value with the previous value:

The start will probably not be synchronised with the chart, but the timing bars will count correctly. You could think about how to synchronise the first start,

such as:

Thank you very much, I will try it.
 

You're welcome. A shorter entry:

Buffer1[i]=MathMax(iHigh(NULL,period02,index1),Buffer1[i+1]);
Buffer2[i]=MathMin(iLow(NULL,period02,index1),Buffer2[i+1]);