Wednesday, October 8, 2008

How to add a Magic Number to a FOREX AUTOPILOT EA

How to add a Magic Number to a FOREX AUTOPILOT EA
By Cubesteak
Hey ya’ll,
www.cubesteak.net/2006/10/adding-a-magic-number-to-an-ea/

Emre asked me if there was a manual on how to add a Magic Number to an Forex Autopilot EA. Since I haven’t seen one, I put together the following steps and thought that others may find it useful too. These steps can also be used to verify that an Forex Autopilot EA properly uses a Magic Number, as some don’t! Anyway, here you go:

1) On a global level in the Forex Autopilot EA add:

int MagicNumber = 233423; // where 233423 is any old number that is unique from any of your other running Forex Autopilot EA’s

The easiest way to describe declaring on the "global level" of the autopilot EA is a variable that is declared outside of the Start, Init and Deinit functions. The easiest way to ensure that you are on the global level of the Forex Autopilot EA is to put the MagicNumber declaration immediately after the top comments and any #property, #include or #import statements and BEFORE the Init, Deinit and Start functions.

2) Next, make sure that the OrderSend function uses this magic number. OrderSend uses the following form:

int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)

So, you want to make sure that it is called with the MagicNumber in it, e. g:

OrderSend(Symbol(), OP_BUY, 1. 0, Ask, 2, 10, 20, "My Buy", MagicNumber, 0, Lime)

3) Then, search the Forex Autopilot EA for each instance of OrderClose, OrderModify or OrderDelete. Usually these are sandwiched by at least one IF statement. Add to that IF statement the following condition: (OrderMagicNumber() == MagicNumber)

So, something like this:

if (OrderSymbol == Symbol())

{

OrderClose(blah blah. . . );

}

Becomes:

if (OrderSymbol == Symbol() && OrderMagicNumber() == MagicNumber)

{

OrderClose(blah blah blah);

}

Voila! Your Forex Autopilot EA now uses a magic number and should be able to trade with other Forex Autopilot EAs.

Please note that any money management that an Forex Autopilot EA uses, like lot optimization based on available margin or equity, etc. will also "interfere" with each other. This is either desirable or undesirable based upon how you want to trade with the specific Forex Autopilot EA's.

Hope that helps for Forex Autopilot!

Cheers,

CS

If you look at many of the Forex Autopilot EAs I post you will find that I use several functions to calculate the MagicNumber. Just copy and paste into your Forex Autopilot EA. You still need to add the declaration at the global level using

int MagicNumber;
int BaseMagic = 4000; // Make this one unique to each forex EA

I plan to make that a complete function eventually so it just becomes a single funtion call like

MagicNumber = GetMagicNumber(BaseMagic);

That way you can test the same expert live on different timeframes without interference.

An assignment is made in the init function that calls other functions that use a base number, the Symbol and the Period to calculate the number. This gives a unique number for each currency pair and timeframe.
Robert

Searches: Forex Autopilot Forex Automated

No comments:

Post a Comment

Blog Archive