Forex



Go Back   Forex Trading > Programming > MetaTrader
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-12-2008, 02:45 AM
Member
 
Join Date: Sep 2007
Posts: 69
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 02-12-2008, 07:55 AM
Senior Member
 
Join Date: Feb 2006
Posts: 587
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 02-12-2008, 08:13 AM
Senior Member
 
Join Date: Nov 2006
Posts: 308
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 03-11-2008, 05:34 AM
Member
 
Join Date: Dec 2006
Location: Minnesota, USA
Posts: 83
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 03:23 PM
Random Walk Index? WNW Indicators - Metatrader 4 28 04-22-2008 04:02 PM
How do u use random data (custom charts) in MT4?? HellGungrave_777 Metatrader 4 2 12-28-2007 01:33 AM
Random Walk indicator raff1410 Indicators - Metatrader 4 21 08-23-2007 10:57 AM


All times are GMT. The time now is 02:53 PM.



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