如何在当前时间范围内找到当天的第一根蜡烛的高价、低价

How to find day's first candle's HIGH, LOW in current Time frame

我是 MT4 的新手,对 MQL4 的基本编程知之甚少。我在 UTC+5:30 交易印度股票。我只想要一小段代码来获得当前 TimeFrame 中今天的第一根蜡烛的高点和低点。我们的交易开始于 9:15 AM IST,结束于 3:30 PM IST。

e.g. if I select PERIOD_M15 (15 min chart) then I need to have day's first candle (i.e. from 9:15AM to 9:30AM) HIGH and LOW.

提前致谢。

欢迎来到 SOF!

您需要输入参数(一天中开始的时间):

input int InpTimeStartHour=9; input int InpTimeStartMinute=15; 这可以作为一个字符串,但为了简单起见,这样的字段

bool getHighLowFistCandle(double &high,double &low){
   //check if first candle (zero-current) is after 9:15
   datetime lastCandle=iTime(Symbol(),0,1);
   if(TimeHour(lastCandle)<InpTimeStartHour || 
      (TimeHour(lastCandle)==InpTimeStartHour && TimeMinute(lastCandle)<InpTimeStartMinute){
      return(false);
   }
   //looking for that time candle starting from day start
   datetime todayStart=iTime(Symbol(),PERIOD_D1,0);
   int shift=iBarShift(Symbol(),0,todayStart);
   for(int i=shift;i>0;i--){
      datetime iCandleTime=iTime(Symbol(),0,i);
      if(TimeHour(iCandleTime)==InpTimeStartHour &&
         TimeMinute(iCandleTime)==InpTimeStartMinute){
          high=iHigh(Symbol(),0,i);
          low=iLow(Symbol(),0,i);
          return(true);
      }
   }
  return(false);
}

下面是我的指标代码,

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2018, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020,ANKUR SONI."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property  indicator_buffers 1
#property indicator_chart_window
#property indicator_width1 5
#property  indicator_color1 clrYellow

double engulfing[];
input int InpTimeStartHour=8;
input int InpTimeStartMinute=45;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0, engulfing);
   SetIndexStyle(0, DRAW_ARROW);
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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[])
  {
   for(int i = (Bars - 2) ; i > 0 ; i--)
     {
      if(TimeHour(time[i]) == InpTimeStartHour && TimeMinute(time[i]) == InpTimeStartMinute)
        {
         double currentHigh = High[i];
         double currentLow = Low[i];
         double nextHigh = High[i-1];
         double nextLow = Low[i-1];
         if(nextHigh > currentHigh && nextLow < currentLow)
           {
            engulfing[i-1] = High[i-1] + 15;
           }
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+