25.10.2016 Views

Expert Advisor Programming by Andrew R. Young

Expert Advisor Programming by Andrew R. Young

Expert Advisor Programming by Andrew R. Young

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Advanced Order Placement<br />

Putting It All Together<br />

We're going to add all of the features we've covered in this section to the simple expert advisor we<br />

created on page 36. We'll be adding order modification, stop level verification, trade context<br />

checking, predefined variable refreshing and lot size verification to our EA. Here is our file, starting at<br />

the beginning:<br />

#property copyright "<strong>Andrew</strong> <strong>Young</strong>"<br />

#include <br />

// External variables<br />

extern bool DynamicLotSize = true;<br />

extern double EquityPercent = 2;<br />

extern double FixedLotSize = 0.1;<br />

extern double StopLoss = 50;<br />

extern double TakeProfit = 100;<br />

extern int Slippage = 5;<br />

extern int MagicNumber = 123;<br />

extern int FastMAPeriod = 10;<br />

extern int SlowMAPeriod = 20;<br />

// Global variables<br />

int BuyTicket;<br />

int SellTicket;<br />

double UsePoint;<br />

int UseSlippage;<br />

int ErrorCode;<br />

We've added the #include statement for the stdlib.mqh file that contains the<br />

ErrorDescription() function for our error handling routines. We've added three external variables<br />

for the lot sizing, and a global variable for the error code.<br />

The following code goes at the beginning of the start() function:<br />

// Moving averages<br />

double FastMA = iMA(NULL,0,FastMAPeriod,0,0,0,0);<br />

double SlowMA = iMA(NULL,0,SlowMAPeriod,0,0,0,0);<br />

57

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!