Hi Coders. I have the following two lines of simple codes to get the shift of the 1st day of current month :-
Question : How to get the shift at the end of the current month ?
Please bear in mind that :-
1) In every 4 years of Feb, it would be a leap year, the last day of Feb would be on 29th.
2) The last day for months of Jan, Mar, May, Jul, Aug, Oct, Dec is 31th, other months would be < 31th.
3) If the last day of a month is falling on Sat / Sun (no trading day) or a holiday (e.g. New Year on 1st Jan), your codes must be able to move backward automatically to Fri (a trading day). Of course, if the Fri is a holiday, the codes must be able to keep on moving backward automatically till a trading day.
My mission is to get the current month's last day of the Shift (let's say : int endD0Sf = XX [Shift No.]) so that I can calculate my exit plan. For example :-
Presuming that the :-
1) calculated codes : int endD0Sf == 20;
2) int hh=TimeHour(TimeCurrent());
My exit plan would be as follows :-
I wish your codes could be simple enough for me to understand as I do not have any programming background. The best if your codes can be in just a few lines.
Thank you.
Inserted Code
int startD0Sf=iBarShift(Symbol(),1440,iTime(Symbol(),43200,0),true); if(startD0Sf==-1) startD0Sf=iBarShift(Symbol(),1440,iTime(Symbol(),43200,0),false)-1; {Alert(Symbol()+" Month Start Shift : "+IntegerToString(startD0Sf));}
Question : How to get the shift at the end of the current month ?
Please bear in mind that :-
1) In every 4 years of Feb, it would be a leap year, the last day of Feb would be on 29th.
2) The last day for months of Jan, Mar, May, Jul, Aug, Oct, Dec is 31th, other months would be < 31th.
3) If the last day of a month is falling on Sat / Sun (no trading day) or a holiday (e.g. New Year on 1st Jan), your codes must be able to move backward automatically to Fri (a trading day). Of course, if the Fri is a holiday, the codes must be able to keep on moving backward automatically till a trading day.
My mission is to get the current month's last day of the Shift (let's say : int endD0Sf = XX [Shift No.]) so that I can calculate my exit plan. For example :-
Presuming that the :-
1) calculated codes : int endD0Sf == 20;
2) int hh=TimeHour(TimeCurrent());
My exit plan would be as follows :-
Inserted Code
if(startD0Sf == 20 && hh >= 12) ... exit action codes ... // (I'll design these action codes by myself, no worry)
I wish your codes could be simple enough for me to understand as I do not have any programming background. The best if your codes can be in just a few lines.
Thank you.