Expert Advisor Programming by Andrew R. Young
Expert Advisor Programming by Andrew R. Young
Expert Advisor Programming by Andrew R. Young
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
EXPERT ADVISOR PROGRAMMING<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 />
// Init function<br />
int init()<br />
{<br />
UsePoint = PipPoint(Symbol());<br />
UseSlippage = GetSlippage(Symbol(),Slippage);<br />
}<br />
// Start Function<br />
int start()<br />
{<br />
// Moving Average<br />
double FastMA = iMA(NULL,0,FastMAPeriod,0,0,0,0);<br />
double SlowMA = iMA(NULL,0,SlowMAPeriod,0,0,0,0);<br />
// Calculate Lot Size<br />
double LotSize = CalcLotSize(DynamicLotSize,EquityPercent,StopLoss,FixedLotSize);<br />
LotSize = VerifyLotSize(LotSize);<br />
// Buy Order<br />
if(FastMA > SlowMA && BuyTicket == 0)<br />
{<br />
if(SellTicket > 0) int Closed = CloseSellOrder(Symbol(),SellTicket,UseSlippage);<br />
SellTicket = 0;<br />
BuyTicket = OpenBuyOrder(Symbol(),LotSize,UseSlippage,MagicNumber);<br />
if(BuyTicket > 0 && (StopLoss > 0 || TakeProfit > 0))<br />
{<br />
OrderSelect(BuyTicket,SELECT_BY_TICKET);<br />
double OpenPrice = OrderOpenPrice();<br />
76