I think I figured it out. I'd like to recommend that this function be added to MetaTrader. I'm using it with SetGlobalVariableOnCondition() function to sleep for a random amount of time instead of a fixed amount of time.
//+------------------------------------------------------------------+ //| Return a random number betwen x and y | //+------------------------------------------------------------------+ double MathRandRange(double x, double x) { return(x+MathMod(MathRand(),MathAbs(x-y))); }
Regards,
Loren
Oops, the declaration should read like this:
Removed because another silly error. See code in next message.
Regards,
Loren
Dang it, if I could hit the right letter, this would work better.
double MathRandRange(double x, double y)
You need to start randomization in the init function. see MathSrand function.
there is no problem with range. our range is known - from 0 to 32767. normalize to yor range.
for instance:
double rand1= MathRand()/32767.0;
double rand2=rand1/(high_range-low_range) + low_range;
or so on.
there is no problem with range. our range is known - from 0 to 32767. normalize to yor range.
for instance:
double rand1= MathRand()/32767.0;
double rand2=rand1/(high_range-low_range) + low_range;
or so on.
Sure, that's more or less what the function I wrote does. I just thought it would be nice if the function were included as part of MetaTrader so people wouldn't have to figure out how to get a random number in a certain range.
It's also a lot easier to read and understand the code when you just see a function call. Trying to figure out what the formula does is not always this easy. And some people can't figure out the formula at all. Alienating those people seems silly when the solution is adding a simple two line function to the platform.
btw, Thanks for the semaphore code. That was useful. I'd also recommend that that become a suite of functions. One to initialize, one to lock, and one to unlock the semaphore. But I already wrote my functions, so it's not my problem if you guys don't see the value of including such simple functions.
Regards,
Loren
It's also a lot easier to read and understand the code when you just see a function call. Trying to figure out what the formula does is not always this easy. And some people can't figure out the formula at all. Alienating those people seems silly when the solution is adding a simple two line function to the platform.
btw, Thanks for the semaphore code. That was useful. I'd also recommend that that become a suite of functions. One to initialize, one to lock, and one to unlock the semaphore. But I already wrote my functions, so it's not my problem if you guys don't see the value of including such simple functions.
Regards,
Loren
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
Regards,
Loren