Someone asked me if there was a manual on how to add a Magic Number to an automated forex trading EA. Since I haven’t seen one, I put together the following basic steps & thought that others may find it useful too. These steps can also be used to verify that an automated forex trading EA properly uses a Magic Number, as some don’t!
First off, to the completely uninitiated, a Magic Number is simply an arbitrary number that can be added to an automated forex trading EA that is used to uniquely identify forex trades that are made from that automated forex trading EA with an eye towards differentiating them from trading made by any other automated forex trading EA. Without a Magic Number, a automated forex trading EA that closes all orders will not only close orders that it has made, but it will also close any orders made by a different forex EA, and it will even close orders that were made manually, as it has no way of telling which orders came from which automated forex trading EA.
This obviously is not an optimal situation. The Magic Number lets you differentiate these orders programmatically so that you can run multiple automated EA’s on multiple charts from within the same MT4 instance and still be able to forex trade manually as well.
Anyway, now on to the steps:
1) On a global level in the automated forex trading EA add:
int MagicNumber = 233423; // where 233423 is any old number that is unique from any of your other running automated forex trading EA’s
The easiest way to describe declaring on the “global level” of the trading 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 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 automated forex trading 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 automated forex trading EA now uses a magic number and should be able to trade with other automated forex trading EAs.
Please note that any money management that an automated forex trading 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 automated forex trading EA’s.
Hope that helps!
Categories: forex tracer automated forex trading
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2008
(63)
-
▼
October
(46)
- Forex Trading Indicator - MACD Dots - Forex Signals
- Forex Signals - Pac_Man - Forex Trading System EA
- Enhanced BASIC Synergy FOREX EXPERT ADVISOR
- Profit Forex trading method #2
- Forex Trading Method Number ONE
- Forex Trading - Forex Live -on- the - News Webinar...
- Free Forex Signals - Final offer - Is it possible ...
- Easy forex trading MA System
- How to use Presets for your forex expert.
- To refresh forex EAs and or forex Indicators witho...
- How to tell forex Experts from forex Indicators
- Handy hedge free forex strategy
- EuroX2 - Forex Automated trading
- The Importance of the Money Management
- MetaTrader 4 Forex Backtesting F.A.Q.
- MetaTrader Forex Brokers List
- How to put a forex Indicator in a chart.
- For all which want reliable backtest
- DOCUMENATION for WRR_ZUP_INFO_v02 .mq4 forex Indic...
- Forex Trading ECN Lesson
- RSI-R2 – SUPER RSI forex Expert Advisors Frequentl...
- Intersection of fast and slow lines. forex lessons
- NoahDePhan, 10Pips
- A New Exit Strategy - The ATR Ratchet By Chuck LeBeau
- Elder Stops
- Forex Education - Forex EA Testing Setup and Proce...
- How to Insert and activate an forex Exper Advisor?...
- Forex Automated EA - Forex strategy ...
- How to trade Heikin-Ashi - Forex Signals
- How to tell forex trading Experts from forex Indic...
- TRANSCRIPT OF AUDIO FILE #4496 OF PHILLIP - FOREX ...
- 4H MACD PRICE MOVEMENT RULES – FOREX SIGNALS
- THE BALANCE LINE TRADES
- Adding a Magic Number to an automated forex tradin...
- How to add a Magic Number to a FOREX AUTOPILOT EA
- How to add alarm to any forex trading indicator
- How I use Murrey Math
- forex trading strategies - HAS Forex Trading Scalp...
- 3 Simple moving average Fractal forex system
- Here I will give you a description of the simple t...
- Forex Trading - ATCF forex trading System
- The 4 Hour MOMENTUM TUNNEL FOREX TRADING METHOD
- MACD Forex Indicator
- Forex Trading Criticial Points
- Forex Trading Strategies
- Forex Trading System - 1 HOUR TUNNEL METHOD BY VEGAS
-
▼
October
(46)
No comments:
Post a Comment