Setting up an automated trading system may seem difficult to understand at first glance. However, new and sophisticated tools make it easier to automate even the most complex trading strategies. Whether your trading strategy involves a simple moving average cross or a complex mix of indicators, I will show you how to get started.
Ok. Let's learn how to get started. First, you will need a software platform to help carry out the different trading tasks. My platform of choice is MetaTrader. MetaTrader has built a wrapper, so to speak, around their trading tools so you can automate any trading action including open/close/limit/stop orders, calculating indicator values, inspecting historical data, etc. For example, lets' say you always open a trade when the 5-day simple moving crosses the 12-day simple moving average. MetaTrader has a function to lookup the 5-day and 12-day moving averages. Then you can write a "robot" applied to a currency pair's chart that will automatically enter a buy/sell order, exit a position, or send you an email when the moving averages cross. I like MetaTrader because it can be used for simple strategies as well as very complex strategies.
You must first signup for free with InterbankFx by
clicking here. Select MT 4.0. Then you can download MetaTrader. Install it and setup a free demo account. Once you've done that you will see a few currency pair charts. Now click on the "Tools" menu and click "MetaQuotes Language Editor" (MetaEditor) or just hit F4 on your keyboard. This brings up the editor you will use to code your automated "robot" or "Expert Advisor" as MetaTrader calls it.
Now let's look at an example Expert Advisor to get familiar with how it works. On the right side of the MetaEditor screen double-click on the "Moving Average.mq4" file. This brings up the Moving Average example. Now don't get overwhelmed by the code. I'll explain what's happening here. Find the line that starts "void start()" (it's one of the last lines) and looks like this:
void start()
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
//----
}
if(Bars<100>I'll explain in english what each command does and in parathesis I'll quote the code above I'm describing in the two "if" statements. The first "if" line reads: if the current symbol (currency pair) has less than 100 bars to use in the calculation (Bars<100).
Now here's where it gets a little tricky. Find the code for "CalculateCurrentOrders", "CheckForOpen", and "CheckForClose." This is where the guts of the trading strategy is defined. "CalculateCurrentOrders" is very easy to understand since all it does is check to see if there is are any outstanding orders in play. All it does is loop through your brokerage account looking for BUY or SELL orders that are currently in the market. "CheckForOpen" is a little more in-depth. Here you will notice that it calls the iMA function to retrieve the moving average from the symbols' chart and creates orders accordingly. A similar thing is happening in "CheckForClose" where the iMA (moving average) is checked and current open orders will be closed accordingly.
Notice how in "CheckForOpen" there's an OrderSend and in "CheckForClose" there's an OrderClose. These are MetaTrader functions used to control trading. The iMA function is also a MetaTrader function to inspect values from an indicator. You do not have to code the logic for the indicator, it's already done for you. A sampling of indicators include: Awesome Oscillator, Bollinger Bands, Fractals, Momentum, On Balance Volume, RSI, Stochastic, MACD, Volume, and Williams' % R. You can even code your own indicator.
To apply this example to a currency pair chart, go back to the InterbankFX MetaTrader main window. Click on a currency pair chart. On the far left under "Expert Advisors" double-click on the one that says "Moving Average" and click the checkbox "Allow Live Trading." Now on every price change the "Moving Average" Expert Advisor will be run to decide when to trade or exit. Although, I do not recommend using this Expert Advisor as it does not produce consistent profits. It's used for example only.
So that's it to get started. All you have to do to start coding your own strategy is to change the "CheckForOpen" and "CheckForClose" routines in the "Moving Average" example, click the "Compile" button on the top menu and you're off and running.
For more information go to
The Profitable Traders website.