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

 
prom18:

Maybe there are examples. Visually it would be easier to understand. Thank you.

If I understand correctly that you need bars in a certain time interval, you can select them using iTime
 
prom18:

Hello. I'm reading a textbook. There are some examples of how to write indicators. I have a question concerning the separatewindow.mq4 indicator. You can set the number of calculated bars there. What if you need to specify the calculation from the opening price of the day (or from zero) to the closing price of the day? How should I do it? I tried to search for a solution, but did not find it.

Here is the opening price of the day in the current timeframe

//+------------------------------------------------------------------+
//|                                                      DayOpen.mq4 |
//|                                            Copyright 2018, IgorM |
//|                              https://www.mql5.com/ru/users/igorm |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, 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 Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         Label1Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
   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;
   static double dayopen=0.0;
   static int lastday=0;
   if(prev_calculated==0)
     {
      limit=rates_total-1;
      dayopen=0.0;
      lastday=0;
     }
   else limit=rates_total-prev_calculated;
   for(i=limit; i>=0; i--)
     {
      if(TimeDay(time[i])!=lastday)
        {
         dayopen=open[i];
         lastday= TimeDay(time[i]);
        }
      Label1Buffer[i]=dayopen;
     }
   return(rates_total);
  }
 

Hello! Is it possible to find the right bar on the history to the RIGHT of a given bar by condition? Thank you.

 
Sfinks35:

Hello! Is it possible to find the right bar on the history to the RIGHT of a given bar by condition? Thank you.

Yes, we can.

 
Artyom Trishkin:

You can.

How do you do it? Please tell me.
 
Sfinks35:
How do you do it? Can you tell me about it, please?

How do you find a given bar?

 
Artyom Trishkin:

How do you find a given bar?


It took me a long time, but I wrote a function like this:

double GetPatt5barsDN()
{
double low3 = 0;
int index = 0;
for(int i=1; i<20; i++)
{
if
((Close[i] > Open[i]) &&
(Close[i+1] > Open[i+1]) &&
(Close[i+2] > Open[i+2]) && //Low[i+2] is needed on this candle
(Close[i+3] < Open[i+3]) &&
(Close[i+4] < Open[i+4])

low3 = Low[i+2];
index = i+2;
}

return(low3);
}

 
Igor Makanu:

here is the opening price of the day in the current TF

Thank you, Igor. But I have not formulated it correctly. The indicator is calculated and drawn for a specified number of bars (50 in this case) and in the separate window. It needs not the open price but the first bar of the day to indicate the MA. But anyway, thank you.

 
Igor Makanu:

here is the opening price of the day on the current TF

Can you tell me what is written in

int i,limit=prev_calculated==0 ? rates_total-1 : rates_total-prev_calculated;

"==" , "?" , ": "

?

 
Sfinks35:


It took me a long time, but I wrote a function like this:

Return also the index in the function parameter passed by the link

Reason: