Part of my EA looks like this.
If I run it as it is, IT DOES NOTHING.However if I remove the datetime t if clause completely, I get the message " Invalid tick volume. "
What am I doing wrong?
-ssn
int start() { static datetime t; if(t!=Time[0]){t=Time[0];Sleep(3000);start();} //Code... if(Volume[0]>1){Print(" Invalid tick volume. ");return;} //Code... return(0); }What am I missing
-ssn
How are you testing this?
First off, if I remove the datetime clause, the code does not compile.
Anyway, what is happening is that on the first run of the script, the variable t is initialised as 0, which the takes you into the if loop. Since this is the first iteration of the loop, the volume is only 1 which does not trigger your "Invalid Volume" message, since you have told it to look for volume > 1. Try looking for volume > 0 and it should work. Essensially you will have to wait for the next bar to open before you get the message.
Also, you cannot call the start function from within itself. In fact I don't think you can call it ever, as it is a special MT4 reserved function.
Here's another tip......try placing Print statments in the code to try and follow the program flow and allow you to inspect the variables.
Don't put if statements in the middle of code.
If you are new to programming dont compound your statement on one line ; x=0 ; y=0 ; if(x=0){Print("hi");};y=1;
is unreadable
In the second code you wrote you do a call to start() so the code would never reach your if(Volume[0]>1) statement.
the return statement after the Print is not needed
My personal preference is to define static variables globally that is before the init() statement
How are you testing this?
First off, if I remove the datetime clause, the code does not compile.
Anyway, what is happening is that on the first run of the script, the variable t is initialised as 0, which the takes you into the if loop. Since this is the first iteration of the loop, the volume is only 1 which does not trigger your "Invalid Volume" message, since you have told it to look for volume > 1. Try looking for volume > 0 and it should work. Essensially you will have to wait for the next bar to open before you get the message.
Also, you cannot call the start function from within itself. In fact I don't think you can call it ever, as it is a special MT4 reserved function.
Here's another tip......try placing Print statments in the code to try and follow the program flow and allow you to inspect the variables.
Regarding your feedback, if I atually omitted the Volume[0]>1 if-clause from my code, the EA would still not run! I have not tried Volume[0]>0 though...
Don't put if statements in the middle of code.
If you are new to programming dont compound your statement on one line ; x=0 ; y=0 ; if(x=0){Print("hi");};y=1;
is unreadable
In the second code you wrote you do a call to start() so the code would never reach your if(Volume[0]>1) statement.
the return statement after the Print is not needed
My personal preference is to define static variables globally that is before the init() statement
volume does not have to be one at the start of a new bar and does not necessary increment by one each tick (sometimes it won't change at all.)
My personal preference is to define static variables when the variable is used only within a routine and globally when it's used in multiple functions.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Part of my EA looks like this.
If I run it as it is, IT DOES NOTHING.However if I remove the datetime t if clause completely, I get the message " Invalid tick volume. "
What am I doing wrong?
-ssn