I`ve just wanted to put a time filter in my EA to only trade between 7 Am and 16 PM (london- ny session) and for some reason, it took trades even after 20 PM yesterday, so it might be a glitch:
Its probably the simplest if() in my whole EA and this doesnt work too.... So please help me.
Use the search and you would have seen recommendations to replace Hour() with TimeHour(TimeCurrent()) what is Hour ?
Well i thought the Hour() function should return the current hour time of the broker.Isnt that obvious, otherwise why does a Hour() function exist if it doesnt show the current hour...?
OK then, it does what you want so use it . . . but you have said it doesn't . . . write a test script and test it, then you will know when it works and when it doesn't, then when you have found out when t doesn't you can find out why . . . or just use the code I have suggested.
- RaptorUK: Use the search and you would have seen recommendations to replace Hour() with TimeHour(TimeCurrent()) what is Hour ?This was based on a post that Hour(), DayOfWeek(), etc didn't work properly in the tester. IIRC there are a test of that on build 5xx that showed it has been corrected.
- Proximus: I`ve just wanted to put a time filter in my EA to only trade between 7 Am and 16 PM (london- ny session) and for some reason, it took trades even after 20 PM yesterday,If your broker's time UTC+1? Otherwise you need to post the broken code.
- RaptorUK: Use the search and you would have seen recommendations to replace Hour() with TimeHour(TimeCurrent()) what is Hour ?This was based on a post that Hour(), DayOfWeek(), etc didn't work properly in the tester. IIRC there are a test of that on build 5xx that showed it has been corrected.
My broker has GMT +0 timezone it is based in London, but i dont know how that makes a difference, i have build 509
@ RaptorUK, i dont know, it seems that TimeHour(TimeCurrent()) doesnt work either, i just recoded it and replaced every Hour() with TimeHour(TimeCurrent()) and it doesnt work, i put the EA yesterday on forward test at around 8 AM GMT +0 and let it run until 23PM, but my filter clearly said that it shouldn't take trades after 17 PM, the last trade must be no later than 16:59, yet it took trades at even 22:30 PM, so i dont know if it works...
My broker has GMT +0 timezone it is based in London, but i dont know how that makes a difference, i have build 509
@ RaptorUK, i dont know, it seems that TimeHour(TimeCurrent()) doesnt work either, i just recoded it and replaced every Hour() with TimeHour(TimeCurrent()) and it doesnt work, i put the EA yesterday on forward test at around 8 AM GMT +0 and let it run until 23PM, but my filter clearly said that it shouldn't take trades after 17 PM, the last trade must be no later than 16:59, yet it took trades at even 22:30 PM, so i dont know if it works...
I can assure you 100% that TimeHour(TimeCurrent()) will give you the correct hour, Print("Hour number - current time: ", TimeHour(TimeCurrent()) ) and see for yourself. Perhaps your STATUS variable/constant ? was not set to what you thought it should be . . . or perhaps your OrderSend() has an issue ?
On backtest both the Hour() and the TimeHour(TimeCurrent()) works, i printed the outcomes of both and they worked, however in real time trading the Hour() doesnt work anymore, i think because of this:
Note: At the testing, the last known server time is modelled. |
Which is pretty silly, but whatever, but the TimeHour(TimeCurrent()) should work on real time trading, i printed it out, it works if i printed it, but if i tested it in an IF() then it doesnt work property, i dont know why?
Which is pretty silly, but whatever, but the TimeHour(TimeCurrent()) should work on real time trading, i printed it out, it works if i printed it, but if i tested it in an IF() then it doesnt work property, i dont know why?
On backtest both the Hour() and the TimeHour(TimeCurrent()) works, i printed the outcomes of both and they worked, however in real time trading the Hour() doesnt work anymore, i think because of this:
Note: At the testing, the last known server time is modelled. |
Which is pretty silly, but whatever, but the TimeHour(TimeCurrent()) should work on real time trading, i printed it out, it works if i printed it, but if i tested it in an IF() then it doesnt work property, i dont know why?
I believe you have misinterpreted the text you've highlighted from the documentation. See my detailed explanation here.
From my experience, Hour() works both live on a chart and in the tester. I use it in my live EA, and I've tested it in the strategy tester. See my explanation link above.
Also, you should split your IF statement into a more manageable statement--remember: simpler is better.
if (Hour()>=7 && Hour()<=16) { if (STATUS="BUY") //BUY.... else if (STATUS="SELL") //SELL.... }
The above code snippet will first evaluate whether the hour is between 7 and 16, inclusively, and then (only if Hour() is >= 7 and <=16) the STATUS variable is evaluated to determine whether it is BUY or SELL. This has the added benefit of allowing you to better and more effectively debug the statement to determine if it is working correctly (and if not, where the problem is likely to be).
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I`ve just wanted to put a time filter in my EA to only trade between 7 Am and 16 PM (london- ny session) and for some reason, it took trades even after 20 PM yesterday, so it might be a glitch:
Its probably the simplest if() in my whole EA and this doesnt work too.... So please help me.