StrToTime function
Page 1 of 502 12 LastLast
Results 1 to 10 of 13

Thread: StrToTime function

  1. #1
    While I use the , it seems that Metatrader is utilizing the Local (pc) time rather than the broker's time.

    Can anyone confirm this?

  2. #2
    Quote Originally Posted by ;
    When I use the StrToTime purpose, it seems that Metatrader is using the Local (computer) time as opposed to the broker's time.

    Can anyone confirm that?
    That's correct. It will fill in the date as according to your computer's system clock, if your string only offer time but no date.

  3. #3

  4. #4
    Quote Originally Posted by ;
    How then can I get the broker's time?
    Use TimeCurrent()

    datetime TimeCurrent()
    Returns the last known server period (period of incoming of the Most Recent quote)

  5. #5
    Not what I intended.

    You know zen that a few of my TradingTime code uses which series function. I'm trying to figure out how best to set trading times .

  6. #6
    Quote Originally Posted by ;
    Not quite what I intended.

    You understand zen that a few of my TradingTime code uses that string function. I am attempting to figure out how best to set trading times down to the moment.
    Vague.

    Best is if you can post a few codes of what you wish to do.
    I have struck this string to period conversion problem years back.

  7. #7
    Inserted Code string TradingTimes = Outdoor Trading Times; if(TimeCurrent() gt; StrToTime(10:00) TimeCurrent() lt; StoToTime(20:00)) TradingTimes = Interior Trading Times;
    It seems that the StrToTime purpose is utilizing the Local computer time as opposed to the broker time, so occasionally this trading times issue doesn't work correctly.

    How can I still drill down to the moment for your trading ranges?

  8. #8
    Ah.. So you need is a method for the EA to trade only within a specific time period.

    But to answer your issue. I'd do something similar to this:
    int TimeShift = TimeCurrent()-TimeLocal();

    if(TimeCurrent()-TimeShift gt; StrToTime(10:00) TimeCurrent()-TimeShift lt; StrToTime(20:00)) TradingTimes = Inside Trading Times;


    To offer my egy, I will only use TimeLocal() instead of TimeCurrent(); this manner the codes are broker separate:

    if(TimeLocal() gt; StrToTime(10:00) TimeLocal()lt; StrToTime(20:00)) TradingTimes = Inside Trading Times;

  9. #9
    But in the event that you really insist on using TimeCurrent(), I propose this more appropriate one:


    if(TimeCurrent()gt; StrToTime(TimeToStr(TimeCurrent(), TIME_DATE) 10:00) TimeCurrent() lt; StrToTime(TimeToStr(TimeCurrent(), TIME_DATE) 20:00)) TradingTimes = Indoors Trading Times;

    this can guarantee StrToTime contains valid date to convert the time to.

  10. #10
    How about this?

    Inserted Code // ------------------------------------------------------------------ //| test.mq4 | //| Copyright ? 2009, MetaQuotes Software Corp.. | //| http://www.metaquotes.net | //p------------------------------------------------------------------ #property copyright Copyright ? 2009, MetaQuotes Software Corp. #property link http://www.metaquotes.net // notice the change in input kind extern int StartHour = 0; extern int StartMinute = 30; extern int EndHour = 3; extern int EndMinute = 30; int init() start(); // remove this away once you apply the snipplet to your code. Return (0); // ------------------------------------------------------------------ //| Custom indior iteration function | // ------------------------------------------------------------------ int begin() //Loe End Time Alter int EndTimeShift = 0; bool EndTimeFound = false; while (! EndTimeFound) // checking the second segment Permits You to attach this EA to reduce timeframes if (TimeHour(Time#91;EndTimeShift#93;-RRB- == EndHour TimeMinute(Time#91;EndTimeShiftNumber93;-RRB- == EndMinute) EndTimeFound = true; else EndTimeShift ; //Loe the most recent Start Time before finish time int StartTimeShift = EndTimeShift; bool StartTimeFound = False; while (! StartTimeFound) if(TimeHour(Time#91;StartTimeShift#93;-RRB- == StartHour TimeMinute(Time#91;StartTimeShift#93;-RRB- == StartMinute) StartTimeFound = true; else StartTimeShift ; Comment (StartTimeShift: StartTimeShift nEndTimeShift: EndTimeShift);
    but to use this, the very minute value should be something which the timeframe could offer. Meaning, should you place moment however you attach this on an hourly chart. You are going to be stuck in an infinite loop because all candles on hourly chart has 0 as their moment worth. Maybe you can think of a way to work around this restriction. Best of luck.

    regards,
    Zen

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