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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Appendix A<br />

// Buy order<br />

if(FastMA > SlowMA && BuyTicket == 0)<br />

{<br />

OrderSelect(SellTicket,SELECT_BY_TICKET);<br />

// Close order<br />

if(OrderCloseTime() == 0 && SellTicket > 0)<br />

{<br />

double CloseLots = OrderLots();<br />

double ClosePrice = Ask;<br />

}<br />

bool Closed = OrderClose(SellTicket,CloseLots,ClosePrice,UseSlippage,Red);<br />

double OpenPrice = Ask;<br />

// Calculate stop loss and take profit<br />

if(StopLoss > 0) double BuyStopLoss = OpenPrice - (StopLoss * UsePoint);<br />

if(TakeProfit > 0) double BuyTakeProfit = OpenPrice + (TakeProfit * UsePoint);<br />

// Open buy order<br />

BuyTicket = OrderSend(Symbol(),OP_BUY,LotSize,OpenPrice,UseSlippage,<br />

BuyStopLoss,BuyTakeProfit,"Buy Order",MagicNumber,0,Green);<br />

}<br />

SellTicket = 0;<br />

// Sell Order<br />

if(FastMA < SlowMA && SellTicket == 0)<br />

{<br />

OrderSelect(BuyTicket,SELECT_BY_TICKET);<br />

if(OrderCloseTime() == 0 && BuyTicket > 0)<br />

{<br />

CloseLots = OrderLots();<br />

ClosePrice = Bid;<br />

}<br />

Closed = OrderClose(BuyTicket,CloseLots,ClosePrice,UseSlippage,Red);<br />

OpenPrice = Bid;<br />

if(StopLoss > 0) double SellStopLoss = OpenPrice + (StopLoss * UsePoint);<br />

if(TakeProfit > 0) double SellTakeProfit = OpenPrice - (TakeProfit * UsePoint);<br />

SellTicket = OrderSend(Symbol(),OP_SELL,LotSize,OpenPrice,UseSlippage,<br />

SellStopLoss,SellTakeProfit,"Sell Order",MagicNumber,0,Red);<br />

}<br />

BuyTicket = 0;<br />

155

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

Saved successfully!

Ooh no, something went wrong!