How can I start ENUM_TIMEFRAMES variables from a shift of specified minutes from their regular starting times?
All you need is the M1 timeframe to compose any timeframe you want.
You start with the candle that has the time you want to start with.
You take the open of that candle.
Then you go forward and catch the highest high and the lowest low while you move towards the time where you want to end your candle.
Then you take the close of the candle at the end.
There you have your open, high, low and close for your time period of your desire.
A simple while loop will do the job for you.
Dominik Christian Egert #:
All you need is the M1 timeframe to compose any timeframe you want.
You start with the candle that has the time you want to start with.
You take the open of that candle.
Then you go forward and catch the highest high and the lowest low while you move towards the time where you want to end your candle.
Then you take the close of the candle at the end.
There you have your open, high, low and close for your time period of your desire.
A simple while loop will do the job for you.
I am looking for a pattern match every few minutes. Let's say 3 minutes. I have a specified start time and I want to end at the last closed candle for each timeframe (candle index 1 for every timeframe). How can I handle the various M1 candle residues when they are not enough to form a complete candle for one of the timeframes in the array?
Look at the chart and watch a 5M candle form.
If you are missing data, then you need to use what you have got. And wait for all data to be ready, so that you can close the candle.
BluePipsOnly
I am trying to figure out how to shift the starting times for the above ENUM_TIMEFRAMES elements so that with a shift of -1 minute
An example which may help - adjust as needed
//+------------------------------------------------------------------+ //| 429580-TimeFrameShifter.mq5 | //| Copyright 2022, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2022, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnStart() { ENUM_TIMEFRAMES thisTF = PERIOD_M30; datetime openTime = iTime(_Symbol, thisTF, 0 ); datetime closeTime = openTime + PeriodSeconds(thisTF); for(int min = 0; min <= 5; min++) //Minute shifter { PrintFormat( "min=%i - %s OpenTime = %s Close Time = %s", min, EnumToString(thisTF), TimeToString(openTime), TimeToString(closeTime) ); openTime -= 60; closeTime -= 60; } } //+------------------------------------------------------------------+
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am working with the following array of ENUM_TIMEFRAMES elements:
Normally, PERIOD_M2 starts at 00:00 and continues to 00:02, 00:04 and so on. Also PERIOD_M3 starts at 00:00 and continues to 00:03, 00:06 and so on. The other timeframes follow in a similar manner.
I am trying to figure out how to shift the starting times for the above ENUM_TIMEFRAMES elements so that with a shift of -1 minute
PERIOD_M2 starts at 23:59 and continues to 00:01, 00:0 and so on. Also PERIOD_M3 starts at 23:59 and continues to 00:02, 00:05 and so on.
also for a shift of 1 minute
PERIOD_M2 starts at 00:01 and continues to 00:03, 00:03 and so on. Also PERIOD_M3 starts at 00:01 and continues to 00:04, 00:07 and so on.
and other timeframes follow suit.
I am using this array to compare Open, High, Low and Close of various candlesticks. Below is an example of how I am using the array to compare highs of two candles from two timeframes: