Before we hop right into it I want to give you a little bit of information on how an EA works. So go read the following introduction to MQL4, the programming language we use to write these things. Now that you understand the basics, lets create a simple EA that buys every time the market drops 20 pips, with a stoploss of 15 pips and a take profit of 10 pips. To begin, right click on Expert Advisors, in the Navigator window, and choose create. We should be looking at the following screen.
Click next, give our EA a name then click finish. We should now be looking at
Click next, give our EA a name then click finish. We should now be looking at
I coded up the program for you so all you have to do is replace your Start() function with this one.
double currentHigh=0.0;
double pipsDown=0.0020;
double stopLoss=0.0015;
double takeProfit=0.0010;
double volume=0.1;
double slippage=5;
int start()
{
//keep track of the current high of the market
if(Ask>currentHigh){
currentHigh=Ask;
}
//If we have dropped 20 pips down place a buy Order
if((currentHigh-Ask)>pipsDown){
OrderSend(Symbol(),OP_BUY,volume,Ask,slippage,Ask-stopLoss,Ask+takeProfit);
currentHigh=Ask;
}
return(0);
}
Hit compile and make sure there are no errors then click Terminal. To backtest this guy you want to click View then strategy tester. We should now be looking at
In the bottom portion of the window click on drop down next to Expert Advisor: and select the one we just created. Make sure Use data is checked and that the date is set from 2010.01.01 to 2010.12.31. Click start. After it finishes click graph from the tabs at the bottom of the screen. We should see the following graph
Congratulations!!
You have successfully coded up and backtested your first Automated Forex trading robot. This particular robot is pretty terrible. But using what we learned as a blueprint our new goal is to build something that actually makes a profit!
No comments:
Post a Comment