I am running an EA that puts every hour an order wiht random direction and close it one hour later again. I want to run it 1000 times to show that the results are normal distributed.
if( iVolume(Symbol(),Period(),0) == 1)
int num = 2*MathRand()/32768;
if( num == 0)
if( num == 1)
before MathRand(), I get 1000 times the same testing results as MathRand() is always seeded in the same way. Right?
Now I am running the optimization without MathSRand(TimeCurrent()) and the results seem do be different. I just need to know if I am right as I do not exactly know how the random function is working.
1) TimeCurrent() is the broker-time in backtesting and MathRand() is placed in init() it should be always the same, but if this is intended to be sure try to use: MathSrand(1);?
2) If this is not intended follow the recommendation of mt4's reference: MathSrand(GetTickCount()); (or at least TimeLocal())
3) To have a random 0 or 1 simply use MathRand()%2 - this is either 0 or 1.
1) + 2) lead to the same result for every test run in the optimization process. That makes sense as the seed is always the same and so all trade runs are the same.
What seems to work is to use MathSrand(run) ; where run is the opimized parameter. If the optimization is done a second time, run has to be multiplied with an integer value or the random values in the second optimization process are the same like in the first.
1) + 2) I think in this case the (local) time variables are set at test-begin. I might be good for other reasons but not for rand number - I think.
So for a rand-seed one has to use a real Windows-function: "kernel32.dll" has a timefunction:
to use this look here https://www.mql5.com/en/forum/45792. May be just use the milliseconds?
To add comments, please log in or register