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.
Appendix C<br />
// Calculate lot size<br />
double LotSize = CalcLotSize(DynamicLotSize,EquityPercent,StopLoss,FixedLotSize);<br />
LotSize = VerifyLotSize(LotSize);<br />
// Begin trade block<br />
if(NewBar == true)<br />
{<br />
// Buy order<br />
if(FastMA > SlowMA && BuyTicket == 0 && BuyMarketCount(Symbol(),MagicNumber)<br />
== 0 && BuyStopCount(Symbol(),MagicNumber) == 0)<br />
{<br />
// Close sell order<br />
if(SellMarketCount(Symbol(),MagicNumber) > 0)<br />
{<br />
CloseAllSellOrders(Symbol(),MagicNumber,Slippage);<br />
}<br />
// Delete sell stop order<br />
if(SellStopCount(Symbol(),MagicNumber) > 0)<br />
{<br />
CloseAllSellStopOrders(Symbol(),MagicNumber);<br />
}<br />
SellTicket = 0;<br />
double PendingPrice = High[BarShift] + (PendingPips * UsePoint);<br />
PendingPrice = AdjustAboveStopLevel(Symbol(),PendingPrice,5);<br />
double BuyStopLoss = CalcBuyStopLoss(Symbol(),StopLoss,PendingPrice);<br />
if(BuyStopLoss > 0) BuyStopLoss = AdjustBelowStopLevel(Symbol(),BuyStopLoss,<br />
5,PendingPrice);<br />
double BuyTakeProfit = CalcBuyTakeProfit(Symbol(),TakeProfit,PendingPrice);<br />
if(BuyTakeProfit > 0) BuyTakeProfit = AdjustAboveStopLevel(Symbol(),<br />
BuyTakeProfit,5,PendingPrice);<br />
}<br />
BuyTicket = OpenBuyStopOrder(Symbol(),LotSize,PendingPrice,BuyStopLoss,<br />
BuyTakeProfit,UseSlippage,MagicNumber);<br />
// Sell Order<br />
if(FastMA < SlowMA && SellTicket == 0<br />
&& SellMarketCount(Symbol(),MagicNumber) == 0<br />
&& SellStopCount(Symbol(),MagicNumber) == 0)<br />
{<br />
if(BuyMarketCount(Symbol(),MagicNumber) > 0)<br />
{<br />
CloseAllBuyOrders(Symbol(),MagicNumber,Slippage);<br />
}<br />
177