如何在当前时间范围内找到当天的第一支蜡烛的HIGH,LOW

时间:2018-02-03 13:04:54

标签: mql4 mt4

我是MT4的新手,对MQL4知之甚少。我在印度股票交易时间为UTC + 5:30。我只想要一小段代码来获取当前TimeFrame中的第一支蜡烛HIGH和LOW。我们的交易从IST上午9:15开始,到IST下午3:30结束。

  

例如如果我选择PERIOD_M15(15分钟图表),那么我需要有一天的第一支蜡烛(即从早上9:15到9:30)HIGH和LOW。

提前感谢。

2 个答案:

答案 0 :(得分:1)

欢迎来到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);
}

答案 1 :(得分:0)

下面是我的指标代码,

//+------------------------------------------------------------------+
//|                                                      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);
  }
//+------------------------------------------------------------------+