How to get the high and low of Monday.
Hi , i am new to coding with mql5 and i struggle to find a way of returning the monday high and low . I don't even know where to start from to be honest.
Thank you!
dayofweek for Monday is 1:
- www.mql5.com
Hi , i am new to coding with mql5 and i struggle to find a way of returning the monday high and low . I don't even know where to start from to be honest.
Thank you!
//+------------------------------------------------------------------+ //| Day of the week as integer (0-Sunday, 1-Monday, ... ,6-Saturday) | //+------------------------------------------------------------------+ int TimeDayOfWeek(const datetime t) { MqlDateTime st; TimeToStruct(t,st); return(st.day_of_week); } void OnStart() { datetime now = TimeTradeServer(); int shift = TimeDayOfWeek(now) - MONDAY; if (shift < 0) shift += 7; datetime time = iTime(Symbol(),PERIOD_D1,shift); double open = iOpen(Symbol(),PERIOD_D1,shift); double high = iHigh(Symbol(),PERIOD_D1,shift); double low = iLow(Symbol(),PERIOD_D1,shift); double close = iClose(Symbol(),PERIOD_D1,shift); long volume= iVolume(Symbol(),PERIOD_D1,shift); Comment(Symbol(),", Monday\n", "Time: " ,TimeToString(time,TIME_DATE),"\n", "Open: " ,DoubleToString(open,Digits()),"\n", "High: " ,DoubleToString(high,Digits()),"\n", "Low: " ,DoubleToString(low,Digits()),"\n", "Close: " ,DoubleToString(close,Digits()),"\n", "Volume: ",IntegerToString(volume),"\n" ); }
that logic doesn't make sense just looking at it
You need to understand how indexing in time series works https://www.mql5.com/en/docs/series/bufferdirection.
Indexing in time series is done in reverse.
If today was Thursday (4) then Thursday (4) - Monday (1) = 3
shift = 0; means Thursday D1 bar shift = 1; means Wednesday D1 bar shift = 2; means Tuesday D1 bar shift = 3; means Monday D1 bar
- www.mql5.com
Hi , i am new to coding with mql5 and i struggle to find a way of returning the monday high and low . I don't even know where to start from to be honest.
Thank you!