StrToTime function - Page 2
Page 2 of 502 FirstFirst 12
Results 11 to 13 of 13

Thread: StrToTime function

  1. #11
    Quote Originally Posted by ;
    What about people using ranges which undergo midnight?
    Inserted Code stringTimeStart = 22:00;//10PM stringTimeEnd = 10:00;//10AM of next day stringBrokerDate; int_TimeStart,_TimeEnd; //these should be within beginning() NEVER within init if (TimeCurrent() gt; _TimeEnd) //first time this may remain accurate ensuring BrokerDate is valid //why people do this? To ensure that BrokerDate and _TimeEnd will not finish at a /mouse race BrokerDate = TimeToStr(TimeCurrent(),TIME_DATE); _TimeStart = StrToTime(BrokerDate TimeStart); _TimeEnd = StrToTime(BrokerDate TimeEnd); if (_TimeStart gt; _TimeEnd) _TimeEnd = _TimeEnd 86400; //add 1 day //currently openly use _TimeStart and _TimeEnd to compare with TimeCurrent()

    This code is written for EA/Script.
    Depending on where you want to utilize this, it could have different effects.

  2. #12
    Here's a code fragment out of a box breakout EA which I wrote for a customer a few months ago:

    Inserted Code : : : : : : : extern series StartTime = 07:00; // time for beginning of price institution window extern series EndTime = 08:00; // time for completion of price institution window extern series ExpiryTime = 06:00; // time at which pending orders perish, and any still open orders closed extern int Clearance = 5; // entry price 'security' tolerance over window high, under window low extern dual MinWinHgt = 0; // if price window (incl. Clearance) lt; this value, no order placement is permitted today extern dual MaxWinHgt = 9999; // if price window (incl. Clearance) gt; this value, no order placement is permitted today : : : : : : : int start() { dual dt0 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) 00:00:00); dual dt1 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) StartTime :00); dual dt2 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) EndTime :00); dual dt3 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) ExpiryTime :00); if (dt3 lt; dt2) dt3 = 86400; int ib1 = iBarShift(NULL,0,dt1); int ib2 = iBarShift(NULL,0,dt2); if (TimeCurrent() gt;= dt2 TimeCurrent() lt;= dt3){ dual vHigh = 0, vLow = 999; for (int j=ib1; jgt;ib2; j--) vHigh = MathMax(vHigh,High#91;j#93; Clearance*pnt); vLow = MathMin(vLow,Low#91;j#93;-Clearance*pnt); if (vHigh-vLow lt;= MaxWinHgt*pnt vHigh-vLow gt;= MinWinHgt*pnt) { : : : : : : :
    dt0 is the midnight (MT4 period) about the current day

    dt1 is the Start Time (MT4 period) of this breakout box

    dt2 is the End Time (MT4 period) of this breakout box

    dt3 is the Expiry Time (MT4 period)

    Orders may only be placed between dt2 (the end of the breakout box) and also dt3 (the designated expiry period).
    Hence I include 86400 (number of seconds in a 24-hour afternoon) into dt3, if necessary, to ensure that it's always larger than dt2 ( as Ragnakore does).
    Then the EA only puts orders if TimeCurrent() lies between dt2 and dt3.

    (vHigh and vLow would be the greatest and lowest prices attained from the breakout box, plus a specified user-supplied Clearance).

    Hope this helps.

  3. #13
    Wow Hanover!!!

    Thank you a lot for the block of code.

    I am wondering though, I really don't see the factor dt0 used anywhere besides the initialization. How can you work through midnight? Let us say I wanted the start of the range to become 23:00 yesterday, and the end of the range to be 3:00 today. How can this block of code do that?

    I included a snippet in bold to attempt to accomplish what I am trying to perform.

    Inserted Code : : : : : : : extern string StartTime = 07:00; // time for start of price establishment window extern string EndTime = 08:00; // time for completion of price establishment window extern string ExpiryTime = 06:00; // time at which pending orders expire, and any still open orders closed extern int Clearance = 5; // entry price 'safety' tolerance above window high, below window low extern dual MinWinHgt = 0; // if price window (incl. Clearance) lt; this value, no order positioning is allowed today extern dual MaxWinHgt = 9999; // if price window (incl. Clearance) gt; this value, no order positioning is allowed today : : : : : : : int start(){ dual dt0 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) 00:00:00); dual dt1 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) StartTime :00); dual dt2 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) EndTime :00); dual dt3 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) ExpiryTime :00); if (dt3 lt; dt2) dt3 = 86400; #91;b#93;if (dt1 gt; dt2) dt1 = StrToTime(TimeToStr(TimeCurrent() - 86400, TIME_DATE) StartTime :00);#91;/b#93; //If the StartTime is higher than the EndTime about precisely the same day, the code assumes that the intended start time was 86400 minutes before. Int ib1 = iBarShift(NULL,0,dt1); int ib2 = iBarShift(NULL,0,dt2); if (TimeCurrent() gt;= dt2 TimeCurrent() lt;= dt3){ dual vHigh = 0, vLow = 999; for (int j=ib1; jgt;ib2; j--) vHigh = MathMax(vHigh,Top#91;j#93; Clearance*pnt); vLow = MathMin(vLow,Low#91;j#93;-Clearance*pnt); if (vHigh-vLow lt;= MaxWinHgt*pnt vHigh-vLow gt;= MinWinHgt*pnt){ : : : : : : :

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners more information