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 D<br />

// Modify Stop<br />

if(OrderMagicNumber() == argMagicNumber && OrderSymbol() == argSymbol<br />

&& OrderType() == OP_SELL && (CurrentStop > MaxStopLoss || CurrentStop == 0)<br />

&& PipsProfit >= MinProfit)<br />

{<br />

bool Trailed = OrderModify(OrderTicket(),OrderOpenPrice(),MaxStopLoss,<br />

OrderTakeProfit(),0);<br />

// Error Handling<br />

if(Trailed == false)<br />

{<br />

int ErrorCode = GetLastError();<br />

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

string ErrAlert = StringConcatenate("Sell Trailing Stop - Error ",<br />

ErrorCode,": ",ErrDesc);<br />

Alert(ErrAlert);<br />

}<br />

}<br />

}<br />

}<br />

string ErrLog = StringConcatenate("Ask: ",<br />

MarketInfo(argSymbol,MODE_ASK), " Ticket: ",OrderTicket()," Stop: ",<br />

OrderStopLoss()," Trail: ",MaxStopLoss);<br />

Print(ErrLog);<br />

197

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

Saved successfully!

Ooh no, something went wrong!