maybe
int num = 100*MathRand()/32767; // random number between 0 to 100 if (num <= 30) Alert ("Go for The 30 Percent"); else Alert ("Go for The 70 Percent");
Thanks. However somethimes it does not produce any result, but I need every time one of 2 option to be selected.
MathSrand(TimeLocal()); double num = NormalizeDouble((100*MathRand()/32767),0); // random number between 0 to 100 if (num <= 20) Print ("Go for The 30 Percent"); else if (num> 80) Print ("Go for The 70 Percent");
How can this be rosolved?
Thanks. However somethimes it does not produce any result, but I need every time one of 2 option to be selected.
How can this be rosolved?
In your version you will sometimes get a value between 21 and 80 which is skipped because your conditional tests are not correct. The code posted by gjol will always return one or the other results.
Regards, Paul.
sir, y u use NormalizeDouble()
what's the difference between
double num = NormalizeDouble((100*MathRand()/32767),0); // random number between 0 to 100
&
int num = 100*MathRand()/32767; // random number between 0 to 100
what do u mean by "somethimes it does not produce any result" ?
& y u use 20
if (num <= 20
u said 30%
BTW
if (num <= 20) Print ("Go for The 30 Percent"); else if (num> 80) Print ("Go for The 70 Percent");
is the same has
if (num <= 20) Print ("Go for The 30 Percent"); else Print ("Go for The 70 Percent");
- qjol:
maybe not
int num = 100*MathRand()/32767; // random number between 0 to 100
MathRand returns an int. int/32767 will be zero. Dividing by 32767. will result is equal probability from 0 to 99 and only a 1/327.7 probability of generating 100.
int num = 100*MathRand()/32768.; // random number from 0 through 99 with equal probability.
- MINTA:
probability: 70% opens a new order against 30% likely not to open a new order?double fraction = MathRand()/32768.; if (fraction < 0.30) ..

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How to get the EA to choose between two randomly selecting choices with certain probability. Example: I want EA "to decide" whether or not to open a new order with the following probability: 70% opens a new order against 30% likely not to open a new order?
Of course "decision" is not static, but varibale with probability that changes from bar to bar.