But it is working...what do you need?
-
double C0_D1_highestValue=iHigh(NULL, PERIOD_D1, 0); // Today's high
On MT4: Unless the current chart is that specific symbol(s)/TF(s) 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 (2019) - Younis Alsulaimi #: , but for the time its placed on the beginning of the day, where it should be placed on the time of the highest value.
Stop using the D1. Find the time of the beginning of the day, and it's bar number. Find the highest bar of today. Now you have the time and value for your endpoint.
date/time (2017)
Find bar of the same time one day ago - MQL4 programming forum (2017)
Ok, it placed on the level of highest value, but for the time its placed on the beginning of the day, where it should be placed on the time of the highest value. I hope its clear now?
try this way :
int periodsecond = PeriodSeconds(); int day = 86400; int timecurent = Hour() * 60*60 + Minute()*60 + Seconds(); int candles = (timecurent/periodsecond); double mod = fmod(timecurent,periodsecond); int todaycandles = ( mod > 0 )? candles : candles -1; int yesterdaycandles = day / PeriodSeconds(); int totalcandles = todaycandles + yesterdaycandles; int todaycanlde = iHighest(_Symbol,_Period,MODE_HIGH,todaycandles,0); datetime TodayHighCandleTime = iTime(_Symbol,_Period,todaycanlde); int yesterdaycandle = iHighest(_Symbol,_Period,MODE_HIGH,(totalcandles-todaycandles),todaycandles); datetime YesterdayHighCndleTime = iTime(_Symbol,_Period,yesterdaycandle); double todayhigh = iHigh(_Symbol,_Period,todaycanlde); double yesterdayhigh = iHigh(_Symbol,_Period,yesterdaycandle); // //// Drawline ObjectDelete("HighTrendLine"); ObjectCreate( 0, "HighTrendLine", OBJ_TREND, 0, YesterdayHighCndleTime, //first point time yesterdayhigh, //first point value TodayHighCandleTime , //second point time todayhigh //second point value ); ObjectSetInteger(0,"HighTrendLine",OBJPROP_COLOR,White); ObjectSetInteger(0,"HighTrendLine",OBJPROP_STYLE,STYLE_DASHDOT); ObjectSetInteger(0,"HighTrendLine",OBJPROP_WIDTH,1); ObjectSetInteger(0,"HighTrendLine",OBJPROP_RAY,true); // Show Figures on Chart Comment( "Yesterday High Time: " ,YesterdayHighCndleTime,"\n", "Yesterday High Value: " ,yesterdayhigh,"\n", "Today Time: " ,TodayHighCandleTime,"\n", "Today High Value: " ,todayhigh );
I wokeup this morning to go through william response, just to see your code ready, Thank you so much its the start of my code i'll add to it the low point and continue from there, really appreciate it Daniel.
-
On MT4: Unless the current chart is that specific symbol(s)/TF(s) 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 (2019) -
Stop using the D1. Find the time of the beginning of the day, and it's bar number. Find the highest bar of today. Now you have the time and value for your endpoint.
date/time (2017)
Find bar of the same time one day ago - MQL4 programming forum (2017)
Thank you William, i'll defently look into the error handling thing, its something i should learn.
If you ask for iTime with PERIOD_D1 I suppose there will only be one time at each day: The start of that day's candle, no?
Thanks Penny.
-
int timecurent = Hour() * 60*60 + Minute()*60 + Seconds();
simplifyint timecurent = TimeCurrent();
-
int candles = (timecurent/periodsecond);
This assumes every bar every exists — they don't. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)
"Free-of-Holes" Charts - MQL4 Articles (2006)
No candle if open = close ? - MQL4 programming forum (2010)Use iBarShift.
- simplify -
-
This assumes every bar every exists — they don't. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)
"Free-of-Holes" Charts - MQL4 Articles (2006)
No candle if open = close ? - MQL4 programming forum (2010)Use iBarShift.
int timecurent = TimeCurrent();
- simplify - How? TimeCurrent() gives the time of last tick -- I need it to know how many seconds have past since midnight..
How about this version :
int day = 86400; int today = Hour()*60*60 + Minute()*60 + Seconds(); int todaybars = iBarShift(_Symbol,_Period,(TimeCurrent()-today)); int totalbars = iBarShift(_Symbol,_Period,(TimeCurrent()-today)-day); int yesterdaybars = totalbars - todaybars; int todaycanlde = iHighest(_Symbol,_Period,MODE_HIGH,todaybars,0); datetime TodayHighCandleTime = iTime(_Symbol,_Period,todaycanlde); int yesterdaycandle = iHighest(_Symbol,_Period,MODE_HIGH,yesterdaybars,todaybars); datetime YesterdayHighCndleTime = iTime(_Symbol,_Period,yesterdaycandle); double todayhigh = iHigh(_Symbol,_Period,todaycanlde); double yesterdayhigh = iHigh(_Symbol,_Period,yesterdaycandle); // //// Drawline ObjectDelete("HighTrendLine"); ObjectCreate( 0, "HighTrendLine", OBJ_TREND, 0, YesterdayHighCndleTime, //first point time yesterdayhigh, //first point value TodayHighCandleTime , //second point time todayhigh //second point value ); ObjectSetInteger(0,"HighTrendLine",OBJPROP_COLOR,White); ObjectSetInteger(0,"HighTrendLine",OBJPROP_STYLE,STYLE_DASHDOT); ObjectSetInteger(0,"HighTrendLine",OBJPROP_WIDTH,1); ObjectSetInteger(0,"HighTrendLine",OBJPROP_RAY,true); // Show Figures on Chart Comment( "Yesterday High Time: " ,YesterdayHighCndleTime,"\n", "Yesterday High Value: " ,yesterdayhigh,"\n", "Today Time: " ,TodayHighCandleTime,"\n", "Today High Value: " ,todayhigh );
In that case you simplify remove the date portion from TimeCurrent()
int today = time();
date/time (2017)Find bar of the same time one day ago - MQL4 programming forum (2017)

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone, i'm new to programming and to this nice forum :D
with this code i'm trying to draw a line from the previous day high to the current day high,
i got the values for each but couldn't specify the time correctly