Random Generator

 

Does anyone know how I can set a random variable?

I'm trying to simulate a coin toss, so if variable = true, then buy, and if variable = false, then sell.

I would imagine MathSrand and MathRand is used, but how?

 
Ronald Raygun:
Does anyone know how I can set a random variable?

I'm trying to simulate a coin toss, so if variable = true, then buy, and if variable = false, then sell.

I would imagine MathSrand and MathRand is used, but how?

See the mq4 doc about MathSRand(), it is used to initiate the pseudo-random serie generated by MathRand().

MathRand() return a number integer between 0 and 32767. So you can decide that if(MathRan() > 16383.5) buy else sell

 

Look at MathRand and MathMod. Your looking for odd or even numbers. Not too difficult.

Lux

 

Random number generation will work just fine, but you can do it with time as well.

if (CurrentTime() % 2 == 0)

openLong;

else

openShort;

Instead of CurrentTime(), you could also use Seconds() or really anything that returns the same number of odd as even values (I'm counting zero as an even value here).

-MRE-

Reason: