CodeBerries:
Hi I have tried to implement a time filter to turn off trading during high spread times, my broker is in Greenwich mean time (GMT+3), I want to turn off the ea 1 hour before New York close, and continue to untill 2 hours after the asian open. Basically it does not turn off. Any ideas? Thanks.
//Code// bool eaRun=false; // SHOULD BE TRUE void OnTick() { if(Hour()>=23 || Hour()<=2) { eaRun=false; } else { //ea code should run otherwise } }
1. Use Code (Alt+S)
2. earun should be true
if(Hour()>=23 && Hour()<=2)
There is no number which is at the same time greater than 23 AND less than 2.
You should use logical OR instead, or change the operators.
if(Hour()>=23 || Hour()<=2) { eaRun = false; } else { //ea code should run otherwise }
or this:
if(Hour()< 23 && Hour()>2) { eaRun = true; } else { //ea code should not run in this case }
- You set the variable to false, but A) never use it, and B) never set it to true.
Simplify if(Hour()< 23 && Hour()>2) run();
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
Hi I have tried to implement a time filter to turn off trading during high spread times, my broker is in Greenwich mean time (GMT+3), I want to turn off the ea 1 hour before New York close, and continue to untill 2 hours after the asian open. Basically it does not turn off. Any ideas? Thanks.
//Code//
bool eaRun=false;
void OnTick()
{
if(Hour()>=23 && Hour()<=2)
{
eaRun=false;
}
else
{
//ea code should run otherwise
}
}