Forex
Google
New signals service!

Go Back   Forex Trading > Programming > Metatrader Programming


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-12-2008, 01:45 AM
Member
 
Join Date: Sep 2007
Posts: 68
Ronald Raygun is on a distinguished road
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-12-2008, 06:55 AM
Senior Member
 
Join Date: Feb 2006
Posts: 525
Michel is on a distinguished road
Quote:
Originally Posted by Ronald Raygun View Post
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-12-2008, 07:13 AM
Senior Member
 
Join Date: Nov 2006
Posts: 185
luxinterior is on a distinguished road
Look at MathRand and MathMod. Your looking for odd or even numbers. Not too difficult.

Lux
__________________
Build An Expert Advisor. FREE E-course As Seen On TV
ForexArea.com
Users of Gap Trader from 'Forex-Assistant' MUST Read This
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-11-2008, 03:34 AM
Member
 
Join Date: Dec 2006
Location: Minnesota, USA
Posts: 84
mrebersv is on a distinguished road
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-
__________________
I'm open to professionally developing EAs. PM me if you're interested.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Profit Generator EA holyguy7 Expert Advisors - Metatrader 4 841 04-29-2008 02:23 PM
Random Walk Index? WNW Indicators - Metatrader 4 28 04-22-2008 03:02 PM
How do u use random data (custom charts) in MT4?? HellGungrave_777 Metatrader 4 2 12-28-2007 12:33 AM
Random Walk indicator raff1410 Indicators - Metatrader 4 21 08-23-2007 09:57 AM


All times are GMT. The time now is 04:59 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.