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.

Working with Functions<br />

double BuyStopLoss = CalcBuyStopLoss(Symbol(),StopLoss,OpenPrice);<br />

if(BuyStopLoss > 0)<br />

{<br />

BuyStopLoss = AdjustBelowStopLevel(Symbol(),BuyStopLoss,5);<br />

}<br />

double BuyTakeProfit = CalcBuyTakeProfit(Symbol(),TakeProfit,OpenPrice);<br />

if(BuyTakeProfit > 0)<br />

{<br />

BuyTakeProfit = AdjustAboveStopLevel(Symbol(),BuyTakeProfit,5);<br />

}<br />

}<br />

}<br />

AddStopProfit(BuyTicket,BuyStopLoss,BuyTakeProfit);<br />

// Sell Order<br />

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

{<br />

if(BuyTicket > 0) Closed = CloseBuyOrder(Symbol(),BuyTicket,Slippage);<br />

BuyTicket = 0;<br />

SellTicket = OpenSellOrder(Symbol(),LotSize,UseSlippage,MagicNumber);<br />

if(SellTicket > 0 && (StopLoss > 0 || TakeProfit > 0))<br />

{<br />

OrderSelect(SellTicket,SELECT_BY_TICKET);<br />

OpenPrice = OrderOpenPrice();<br />

double SellStopLoss = CalcSellStopLoss(Symbol(),StopLoss,OpenPrice);<br />

if(SellStopLoss > 0)<br />

{<br />

SellStopLoss = AdjustAboveStopLevel(Symbol(),SellStopLoss,5);<br />

}<br />

double SellTakeProfit = CalcSellTakeProfit(Symbol(),TakeProfit,OpenPrice);<br />

if(SellTakeProfit > 0)<br />

{<br />

SellTakeProfit = AdjustBelowStopLevel(Symbol(),SellTakeProfit,5);<br />

}<br />

AddStopProfit(SellTicket,SellStopLoss,SellTakeProfit);<br />

}<br />

}<br />

return(0);<br />

}<br />

77

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

Saved successfully!

Ooh no, something went wrong!