reference specific candles based on closing times

 

Trying to reference specific bars based on their closing times on mql4.


Part of my script is to look for

  1. On 1H chart - a 9:00 candle closed green at 10:00.

  2. On M30 chart – a 9:30 candle closed green at 10:00

  3. On M15 chart – a 9:45 candle closed green at 10:00

  4. On M5 chart – a 9:55 candle closed green at 10:00

But i would like for this to happen at end of every hour to check for the above conditions


How do i reference these specific bars, functions should i be using ? and logic layout?


Thanks for any input

p { margin-left: 0.21cm; direction: ltr; text-align: left; background: transparent none repeat scroll 0% 0%; }p.western { font-family: "Georgia", serif; font-size: 12pt; }p.cjk { font-family: "Georgia"; font-size: 12pt; }p.ctl { font-size: 12pt; }

 
    1. Take the current time, subtract PeriodSeconds(TF), get the index via iBarShift(TF), access the specific bars. Timeseries and Indicators Access
    2. If it's the same symbol, then just access the specific bar with index 1.

  1. On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4
 

Thanks for the help.

I was looking at the timeseries and indicator access link you referenced.  How would I access the timeseries array if I am looking for the 45min bar every hour on the 15min chart?

ie..

   ArraySetAsSeries(TimeAsSeries,true);
   ResetLastError();
   int copied=CopyTime(NULL,0,0,0,TimeAsSeries);
   if(copied<=TimetoStr(copied) + ":45:00")
     {
      Print("Found");
      return;
     }
 
  1. mkwctrader12: How would I access the timeseries array if I am looking for the 45min bar every hour on the 15min chart?

    Same way you access any bar. That isn't your problem. Your problem is: is it the 45 minute bar?

      const int min45 = 45 * 60, oneHr = 60 * 60; // seconds
      datetime t15    = iTime(NULL, PERIOD_M15, 0);
    bool isLastQuarterHour = t15 % oneHr >= min45;
  2. #1.2 still applies with the above code. Replacing iTime(…) with TimeCurrent() removes that requirement (unless you later look at the M15 bar data.)

  3. TimetoStr(copied) + ":45:00")
    Your attempt would have worked if you had used TIME_DATE|TIME_MINUTES to include the hour in your string representation and then removed the current ":Mi" from your string before adding your ":45" to your string
              TimeToStr - Conversion Functions - MQL4 Reference
Reason: