Afternoon. Critique. A day is not always a fixed number of candles. In your case - it is not always correct to check data of 96 candles for M15. Sometimes you can get into the data of another day.
Thanks for the comment, I really haven't encountered this myself as I have given up the daily TL in favour of intraday trading (I look at 4 hours, hour and m15). But in general, we will have to take a closer look at the situation.
This is true for any TF, not necessarily M15. The point is that if you are looking for tops/roots within a day, for example, the previous day, you should not rely on a fixed number of candles, it is better to rely on the time: from the opening of the previous day, in this case, to the opening (the first candle, which may have a time other than 00.00) of the current day.
Just now I am writing one EA on mql4 and remembered your criticism. Although I have not encountered this situation in practice, I decided to exclude it. The solution is as follows:
//1.2 Determine the bar following the extremum int UpperFractal_1_base_next=UpperFractal_1_base-1; int UpperFractal_2_base_next=UpperFractal_2_base-1; int LowerFractal_1_base_next=LowerFractal_1_base-1; int LowerFractal_2_base_next=LowerFractal_2_base-1; //1.3 Determine the time of fractal formation datetime UpFractalTime_1_base=iTime(NULL,base_tf,UpperFractal_1_base); datetime UpFractalTime_2_base=iTime(NULL,base_tf,UpperFractal_2_base); datetime LowFractalTime_1_base=iTime(NULL,base_tf,LowerFractal_1_base); datetime LowFractalTime_2_base=iTime(NULL,base_tf,LowerFractal_2_base); //1.4 Determine the time of the bar following the extremum datetime UpFractalTime_1_base_next=iTime(NULL,base_tf,UpperFractal_1_base_next); datetime UpFractalTime_2_base_next=iTime(NULL,base_tf,UpperFractal_2_base_next); datetime LowFractalTime_1_base_next=iTime(NULL,base_tf,LowerFractal_1_base_next); datetime LowFractalTime_2_base_next=iTime(NULL,base_tf,LowerFractal_2_base_next); //1.5 Determine bar indices on m15 for fractal bar opening time int UpperFractal_1_m15_base=iBarShift(NULL, 15, UpFractalTime_1_base,true); int UpperFractal_2_m15_base=iBarShift(NULL, 15, UpFractalTime_2_base,true); int LowerFractal_1_m15_base=iBarShift(NULL, 15, LowFractalTime_1_base,true); int LowerFractal_2_m15_base=iBarShift(NULL, 15, LowFractalTime_2_base,true); //1.6 Determine bar indices on m15 for the bar following the extremum int UpperFractal_1_m15_base_next=iBarShift(NULL, 15, UpFractalTime_1_base_next,true); int UpperFractal_2_m15_base_next=iBarShift(NULL, 15, UpFractalTime_2_base_next,true); int LowerFractal_1_m15_base_next=iBarShift(NULL, 15, LowFractalTime_1_base_next,true); int LowerFractal_2_m15_base_next=iBarShift(NULL, 15, LowFractalTime_2_base_next,true); //1.7 Find the number of bars on m15 between the bar - fractal and the next bar int UpperFractal_1_m15_NumBars_base=(UpperFractal_1_m15_base-UpperFractal_1_m15_base_next); int UpperFractal_2_m15_NumBars_base=(UpperFractal_2_m15_base-UpperFractal_2_m15_base_next); int LowerFractal_1_m15_NumBars_base=(LowerFractal_1_m15_base-LowerFractal_1_m15_base_next); int LowerFractal_2_m15_NumBars_base=(LowerFractal_2_m15_base-LowerFractal_2_m15_base_next); // --- Stage 2 - - refinement of extrema //2.1 For the first smallest fractal int Bar_1_Lowest_m15_base=iLowest(NULL,PERIOD_M15,MODE_LOW,LowerFractal_1_m15_NumBars_base,LowerFractal_1_m15_base_next); datetime Time_1_Lowest_m15_base=iTime(NULL,PERIOD_M15,Bar_1_Lowest_m15_base); double Price_1_Lowest_m15_base=iLow(NULL,PERIOD_M15,Bar_1_Lowest_m15_base); //2.2 For the second smallest fractal int Bar_2_Lowest_m15_base=iLowest(NULL,PERIOD_M15,MODE_LOW,LowerFractal_2_m15_NumBars_base,LowerFractal_2_m15_base_next); datetime Time_2_Lowest_m15_base=iTime(NULL,PERIOD_M15,Bar_2_Lowest_m15_base); double Price_2_Lowest_m15_base=iLow(NULL,PERIOD_M15,Bar_2_Lowest_m15_base); //2.3 For the first largest fractal int Bar_1_Highest_m15_base=iHighest(NULL,PERIOD_M15,MODE_HIGH,UpperFractal_1_m15_NumBars_base,UpperFractal_1_m15_base_next); datetime Time_1_Highest_m15_base=iTime(NULL,PERIOD_M15,Bar_1_Highest_m15_base); double Price_1_Highest_m15_base=iHigh(NULL,PERIOD_M15,Bar_1_Highest_m15_base); //2.4 For the second largest fractal int Bar_2_Highest_m15_base=iHighest(NULL,PERIOD_M15,MODE_HIGH,UpperFractal_2_m15_NumBars_base,UpperFractal_2_m15_base_next); datetime Time_2_Highest_m15_base=iTime(NULL,PERIOD_M15,Bar_2_Highest_m15_base); double Price_2_Highest_m15_base=iHigh(NULL,PERIOD_M15,Bar_2_Highest_m15_base);
Although I have not encountered this situation in practice, I decided to exclude it nevertheless
Today, for example, open the pair GBPUSD/EURUSD M5 the first candle opened at 00:05. If we take 288 candlesticks by analogy with M15, we will get into the data of another day.
True, this is for MT5... on MT4 (MetaQuotes-Demo server) - also, at another broker from 00:00, so... everything is individual and you still need to check it.
New article Plotting trend lines based on fractals using MQL4 and MQL5 has been published:
Author: Almat Kaldybay
Hi,
I dont get the trendline as ilustrated above.
Any special setting?
Hi,
I dont get the trendline as ilustrated above.
Any special setting?
Hi Almat,
I am not getting trendlines in chart, but I am getting continuous mobile alerts. Please help if I miss anything.
thanks,
Prakash.R
Hi Almat,
I am not getting trendlines in chart, but I am getting continuous mobile alerts. Please help if I miss anything.
thanks,
Prakash.R
Hi,
1. You need compile mq4 file in the metaeditor;
2. I think that you have trendlines in chart, but you do not see them because of the scale of chart

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article Plotting trend lines based on fractals using MQL4 and MQL5 has been published:
The article describes the automation of trend lines plotting based on the Fractals indicator using MQL4 and MQL5. The article structure provides a comparative view of the solution for two languages. Trend lines are plotted using two last known fractals.
Recently, I have been thinking about using trend lines. There was a question about choosing a method of determining the points for plotting lines, and also about plotting accuracy. I decided to use fractals as a basis.
I often analyze markets at my main job where I can spend some time on trading. Also, you can't just draw the lines on a larger timeframe - the line should be plotted by extreme points with accuracy up to 15 minutes. The reason for this is that the fractal time on a larger timeframe doesn't always match the time of the same extreme point on M15. In short, this is where automation comes to help. It happened that I began writing the code using MQL5 and then moved to MQL4, because I needed this program for MetaTrader 4.
In this article I presented my solution of the problem using MQL4 and MQL5. The article provides the comparative view, but it would be inappropriate to compare the efficiency of MQL4 and MQL5 here. Also, I understand that there are probably other solutions, more effective than mine. The article can be useful to beginners who write scripts using either MQL4 or MQL5, especially to those who plan to use fractals and trend lines.
3. Determining price and time values of fractals
To draw the line we need to determine the time and price of a fractal. Of course, in MQL4 we could simply use the High[] and Low[] predefined timeseries, and the iTime() function, however we also need to get more precise time coordinates to ensure the correct plotting of the trend line.
Fig. 1-2 show the difference between the time values of extreme points on H4 and M15 timeframes.
Fig.1. The extreme point time value on H4
Fig.2. The extreme point time value on M15
Author: Almat Kaldybay