Seems to be ok, but can be simplified:
//if((Hour()>=0 && Hour()<1) || (Hour()>=4 && Hour()<5) || (Hour()>=18 && Hour()<20) || (Hour()>=22) )return; if( Hour()<1 || Hour()==4 || (Hour()>=18 && Hour()<20) || Hour()>=22 ) return;
That should work fine. A couple of finesse points you may be interested in
// only trade Monday to Friday inclusive if(DayOfWeek()==0 || DayOfWeek()==6) return; // don't trade during the hours of 0, 4, 18 to 19 inclusive, 22 to 23 inclusive int hr=Hour(); // this is more efficient than calling Hour() each time if(hr==0 || hr==4 || (hr>=18 && hr<20) || hr>=22)return; // this is simpler
Sorry gooly, looks like we posted at the same time.
gooly :Seems to be ok, but can be simplified: honest_knave: this is more efficient than calling Hour() each time | // only trade Monday to Friday inclusive if(DayOfWeek()==0 || DayOfWeek()==6) return; // don't trade during the hours of 0, 4, 18 to 19 inclusive, 22 to 23 inclusive int hr=Hour(); // this is more efficient than calling Hour() each time if(hr==0 || hr==4 || (hr>=18 && hr<20) || hr>=22)return; // this is simpler |
Even simplifier and efficient | int DOW[] = { 0,1,1,1,1,1,0}; // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 int HR[] = { 0,1,1,1,0,1,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0}; if(DOW[DayOfWeek()] == 0 || HR[Hour()] == 0)return; |
You could simplify it further using bool array
int DOW[] = { 0,1,1,1,1,1,0}; // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 int HR[] = { 0,1,1,1,0,1,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0}; if(DOW[DayOfWeek()] == 0 || HR[Hour()] == 0)return; --or-- bool DOW[] = { 0,1,1,1,1,1,0}; // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 bool HR[] = { 0,1,1,1,0,1,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0}; if(!DOW[DayOfWeek()] || !HR[Hour()])return;
Interestingly, using GetTickCount() over 100,000,000 iterations show the array method to be twice as slow as the method not accessing arrays. Which surprised me (I was bored). The arrays were declared outside of the loop.
Folks, thank you all for your input and help. Its much appreciated. :)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello
I'd be very grateful if someone could confirm that I have my logic correct here:
Sorry for such a basic query, but I'm still learning!
Thank you. :)