When I use the StrToTime function, it seems that Metatrader is using the Local (computer) time as opposed to the broker's time.
Can anyone confirm this?
Can anyone confirm this?
required to function call function 2 replies
coding help - StrToTime confusion 5 replies
stop loss function and edit time function for Breakout EA 1 reply
Need Expert Help on Time Function 4 replies
View internal function code 2 replies
DislikedWhen I use the StrToTime function, it seems that Metatrader is using the Local (computer) time as opposed to the broker's time.
Can anyone confirm this?Ignored
DislikedNot quite what I meant.
You know zen that some of my TradingTime code uses that string function. I'm trying to figure out how best to set trading times down to the minute.Ignored
string TradingTimes = "Outside Trading Times"; if(TimeCurrent() > StrToTime("10:00") && TimeCurrent() < StoToTime("20:00")) TradingTimes = "Inside Trading Times";
//Find End Time Shift
int EndTimeShift = 1;
int EndTimeUsed = 0;
bool EndTimeFound = False;
while (!EndTimeFound)
{
if(TimeHour(Time[EndTimeShift + 1]) <= EndHour && TimeHour(Time[EndTimeShift]) >= EndHour && TimeMinute(Time[EndTimeShift + 1]) <= EndMinute && TimeMinute(Time[EndTimeShift]) >= EndMinute)
{
EndTimeFound = True;
EndTimeUsed = EndTimeShift;
}
else
{
EndTimeShift++;
}
}
//Find the most recent Start Time before end time
bool StartTimeFound = False;
int StartTimeShift = EndTimeUsed;
int StartTimeShiftUsed = 0;
while (!StartTimeFound)
{
if(TimeHour(Time[StartTimeShift + 1]) <= StartHour && TimeHour(Time[StartTimeShift]) >= StartHour && TimeMinute(Time[StartTimeShift + 1]) <= StartMinute && TimeMinute(Time[StartTimeShift]) >= StartMinute)
{
StartTimeFound = True;
StartTimeShiftUsed = StartTimeShift;
}
else
{
StartTimeShift++;
//Print("Here I am: 1");
}
//Print("Here I am: 2");
}
//+------------------------------------------------------------------+ //| test.mq4 | //| Copyright © 2009, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" // note the change in input type extern int StartHour = 0; extern int StartMinute = 30; extern int EndHour = 3; extern int EndMinute = 30; int init() { start(); // remove this away when you implement the snipplet to your code. return (0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //Find End Time Shift int EndTimeShift = 0; bool EndTimeFound = false; while (!EndTimeFound) { // checking the minute segment allows you to attach this EA to lower timeframes if (TimeHour(Time[EndTimeShift]) == EndHour && TimeMinute(Time[EndTimeShift]) == EndMinute) { EndTimeFound = true; } else { EndTimeShift++; } } //Find the most recent Start Time before end time int StartTimeShift = EndTimeShift; bool StartTimeFound = False; while (!StartTimeFound) { if(TimeHour(Time[StartTimeShift]) == StartHour && TimeMinute(Time[StartTimeShift]) == StartMinute) { StartTimeFound = true; } else { StartTimeShift++; } } Comment ("StartTimeShift: "+StartTimeShift+"nEndTimeShift: "+EndTimeShift); }
QuoteDislikedWhat about people using ranges which go through midnight?
stringTimeStart = "22:00";//10PM stringTimeEnd = "10:00";//10AM of next day stringBrokerDate; int_TimeStart,_TimeEnd; //these should be within start() NEVER within init if (TimeCurrent() > _TimeEnd) { //first time this will always be true ensuring BrokerDate is valid //why we do this? to ensure that BrokerDate and _TimeEnd will not end in a cat/mouse race BrokerDate = TimeToStr(TimeCurrent(),TIME_DATE); } _TimeStart = StrToTime(BrokerDate + " " + TimeStart); _TimeEnd = StrToTime(BrokerDate + " " + TimeEnd); if (_TimeStart > _TimeEnd) { _TimeEnd = _TimeEnd + 86400; //add 1 day } //now freely use _TimeStart and _TimeEnd to compare with TimeCurrent()
: : : : : : : extern string StartTime = "07:00"; // time for start of price establishment window extern string EndTime = "08:00"; // time for end 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 double MinWinHgt = 0; // if price window (incl. Clearance) < this value, no order placement is permitted today extern double MaxWinHgt = 9999; // if price window (incl. Clearance) > this value, no order placement is permitted today : : : : : : : int start() { double dt0 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " 00:00:00"); double dt1 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " " + StartTime + ":00"); double dt2 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " " + EndTime + ":00"); double dt3 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " " + ExpiryTime + ":00"); if (dt3 < dt2) dt3 += 86400; int ib1 = iBarShift(NULL,0,dt1); int ib2 = iBarShift(NULL,0,dt2); if (TimeCurrent() >= dt2 && TimeCurrent() <= dt3) { double vHigh = 0, vLow = 999; for (int j=ib1; j>ib2; j--) { vHigh = MathMax(vHigh,High[j]+Clearance*pnt); vLow = MathMin(vLow,Low[j]-Clearance*pnt); } if (vHigh-vLow <= MaxWinHgt*pnt && vHigh-vLow >= MinWinHgt*pnt) { : : : : : : :
: : : : : : : extern string StartTime = "07:00"; // time for start of price establishment window extern string EndTime = "08:00"; // time for end 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 double MinWinHgt = 0; // if price window (incl. Clearance) < this value, no order placement is permitted today extern double MaxWinHgt = 9999; // if price window (incl. Clearance) > this value, no order placement is permitted today : : : : : : : int start() { double dt0 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " 00:00:00"); double dt1 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " " + StartTime + ":00"); double dt2 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " " + EndTime + ":00"); double dt3 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " " + ExpiryTime + ":00"); if (dt3 < dt2) dt3 += 86400; [b]if (dt1 > dt2) dt1 = StrToTime(TimeToStr(TimeCurrent() - 86400, TIME_DATE) + " " + StartTime " + ":00");[/b] //If the StartTime is greater than the EndTime on the same day, the code assumes that the intended start time was 86400 seconds earlier. int ib1 = iBarShift(NULL,0,dt1); int ib2 = iBarShift(NULL,0,dt2); if (TimeCurrent() >= dt2 && TimeCurrent() <= dt3) { double vHigh = 0, vLow = 999; for (int j=ib1; j>ib2; j--) { vHigh = MathMax(vHigh,High[j]+Clearance*pnt); vLow = MathMin(vLow,Low[j]-Clearance*pnt); } if (vHigh-vLow <= MaxWinHgt*pnt && vHigh-vLow >= MinWinHgt*pnt) { : : : : : : :