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.

Appendix D<br />

}<br />

Print(ErrLog);<br />

}<br />

return(Ticket);<br />

int OpenBuyLimitOrder(string argSymbol, double argLotSize, double argPendingPrice,<br />

double argStopLoss, double argTakeProfit, double argSlippage, double argMagicNumber,<br />

datetime argExpiration, string argComment = "Buy Limit Order")<br />

{<br />

while(IsTradeContextBusy()) Sleep(10);<br />

// Place Buy Limit Order<br />

int Ticket = OrderSend(argSymbol,OP_BUYLIMIT,argLotSize,argPendingPrice,argSlippage,<br />

argStopLoss,argTakeProfit,argComment,argMagicNumber,argExpiration,Green);<br />

// Error Handling<br />

if(Ticket == -1)<br />

{<br />

int ErrorCode = GetLastError();<br />

string ErrDesc = ErrorDescription(ErrorCode);<br />

string ErrAlert = StringConcatenate("Open Buy Limit Order - Error ",ErrorCode,<br />

": ",ErrDesc);<br />

Alert(ErrAlert);<br />

}<br />

string ErrLog = StringConcatenate("Bid: ",MarketInfo(argSymbol,MODE_BID),<br />

" Lots: ",argLotSize," Price: ",argPendingPrice," Stop: ",argStopLoss,<br />

" Profit: ",argTakeProfit," Expiration: ",TimeToStr(argExpiration));<br />

Print(ErrLog);<br />

}<br />

return(Ticket);<br />

int OpenSellLimitOrder(string argSymbol, double argLotSize, double argPendingPrice,<br />

double argStopLoss, double argTakeProfit, double argSlippage, double argMagicNumber,<br />

datetime argExpiration, string argComment = "Sell Limit Order")<br />

{<br />

while(IsTradeContextBusy()) Sleep(10);<br />

// Place Sell Limit Order<br />

int Ticket = OrderSend(argSymbol,OP_SELLLIMIT,argLotSize,argPendingPrice,argSlippage,<br />

argStopLoss,argTakeProfit,argComment,argMagicNumber,argExpiration,Red);<br />

// Error Handling<br />

if(Ticket == -1)<br />

{<br />

int ErrorCode = GetLastError();<br />

string ErrDesc = ErrorDescription(ErrorCode);<br />

183

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

Saved successfully!

Ooh no, something went wrong!