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!

 
answered in this thread before to get the daily highs and lows of a specific day:

Why do you want to zone in on a specific day? what's the problem with returning the daily highs and lows for X number of previous days?
 
Thanks for the refference. I am just trading based on Monday PA , this is why i need the specific range for it 
 
there's also a nice indicator recently published in the codebase

You can see the date and time under the chart of course
 
metinique:

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:

TimeToStruct - Date and Time - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5

Documentation on MQL5: Date and Time / TimeToStruct
Documentation on MQL5: Date and Time / TimeToStruct
  • www.mql5.com
Converts a value of datetime type (number of seconds since 01.01.1970) into a structure variable MqlDateTime . Parameters dt [in]  Date value...
 
metinique:

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"
           );
  }
 
amrali #:
that logic doesn't make sense just looking at it

If today was Thursday (4) then Thursday (4) - Monday (1) would give you the highs and lows of 3...which is Wednesday
 
Conor Mcnamara #:
that logic doesn't make sense just looking at it

If today was Thursday (4) then Thursday (4) - Monday (1) would give you the highs and lows of 3...which is Wednesday

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
Documentation on MQL5: Timeseries and Indicators Access / Indexing Direction in Arrays, Buffers and Timeseries
Documentation on MQL5: Timeseries and Indicators Access / Indexing Direction in Arrays, Buffers and Timeseries
  • www.mql5.com
The default indexing of all arrays and indicator buffers is left to right. The index of the first element is always equal to zero. Thus, the very...