Code it.
OK, but how?
I Use This One But It's Not Work On MT5 :
bool time; int startTime = 6; int endTime = 17; void OnStart() { datetime tm=TimeCurrent(); //gets current time in datetime data type string str=TimeToString(tm,TIME_MINUTES); //changing the data type to a string string current = StringSubstr(str, 0, 2); //selecting the first two characters of the datetime e.g. if it's 5:00:00 then it'll save it as 5, if it's 18 it will save 18. int currentTimeInt = StringToInteger(current); //changes the string to an integer if(currentTimeInt>startTime && endTime>currentTimeInt) { time = true; } else { time = false; } }
And Then Use This On My Main Indicator :
for(i=limit;i<rates_total-3 && !IsStopped();i++) { //---- Upper Fractal if(High[i]>=High[i+1] && High[i]>High[i+2] && High[i]>=High[i-1] && High[i]>High[i-2] && time == true) ExtUpperBuffer[i]=High[i]; else ExtUpperBuffer[i]=EMPTY_VALUE; //---- Lower Fractal if(Low[i]<=Low[i+1] && Low[i]<Low[i+2] && Low[i]<=Low[i-1] && Low[i]<Low[i-2] && time == true) ExtLowerBuffer[i]=Low[i]; else ExtLowerBuffer[i]=EMPTY_VALUE; }
OK, but how?
I Use This One But It's Not Work On MT5 :
And Then Use This On My Main Indicator :
You are on the right track - there is a handy function TimeToStruct(). Have a look at the documentation - you can easily extract the hour using the MqlDateTime.hour structure, which you can compare the current time hour.
Another simpler way is to calculate how many seconds have elapsed since midnight ( TimeCurrent()%(24*3600) ) - if it's greater than 9am (9 * 3600) then execute.
You are on the right track - there is a handy function TimeToStruct(). Have a look at the documentation - you can easily extract the hour using the MqlDateTime.hour structure, which you can compare the current time hour.
The other way is to calculate how many seconds have elapsed since midnight if it's greater than 9am (9 * 3600) then execute.
Could you give me an example?
ulong secsSinceMidnight = TimeCurrent()%(24*3600); ulong secsStartTime = 9 * 3600; PrintFormat("Secs = %d Time = %s", secsSinceMidnight, TimeToString(datetime(secsSinceMidnight), TIME_SECONDS )); if(secsSinceMidnight > secsStartTime) { Print("Execute"); } else { Print("Pause"); }
so, What is the problem in my coding; becuase it didnt change time value to true or false.
I checked it - with endtime = 17 it was false (because the MetaTrader time is 17:48) but with endtime = 23 it was true
Although with your approach representing midnight needs some additional logic - I prefer calculating secs since midnight (as per the example I gave above)
I checked it - with endtime = 17 it was false (because the MetaTrader time is 17:48) but with endtime = 23 it was true
Although with your approach representing midnight needs some additional logic - I prefer calculating secs since midnight (as per the example I gave above)
Thanks Mate,
Could You Give Me An Example; That Untill 9am to 11pm (broker time) make "bool time;" true; and for another time it's set as false?
thanks
Thanks Mate,
Could You Give Me An Example; That Untill 9am to 11pm (broker time) make "bool time;" true; and for another time it's set as false?
thanks
Here, try this:
ulong secsSinceMidnight = TimeCurrent() % (24 * 3600); ulong secsStartTime = 9 * 3600; ulong secsEndTime = 23 * 3600; bool time = false; PrintFormat("SecsSinceMidnight = %d TimeSinceMidnight = %s [start = %s end = %s]", secsSinceMidnight, TimeToString(datetime(secsSinceMidnight), TIME_SECONDS), TimeToString(datetime(secsStartTime), TIME_SECONDS), TimeToString(datetime(secsEndTime), TIME_SECONDS) ); if((secsSinceMidnight > secsStartTime) && (secsSinceMidnight < secsEndTime)) { time = true; } else { time = false; } PrintFormat("time = %s", string(time));
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I Want To Set an Time Limitation For My Indicator. (MT5)
How Can I Do That?
For Example, I Want to Start Calculating From 9:00 To 00:00.
Thanks.