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.

EXPERT ADVISOR PROGRAMMING<br />

Fig. 8.4 – The Email settings under Tools – Options.<br />

Here's an example of SendMail() usage:<br />

string EmailSubject = "Buy order placed";<br />

string EmailBody = "Buy order "+Ticket+" placed on "+Symbol()+" at "+Ask;<br />

// Sample output: "Buy order 12584 placed on EURDUSD at 1.4544"<br />

SendMail(EmailSubject,EmailBody);<br />

Retry on Error<br />

Throughout this book, we've tried to verify order parameters before attempting to place an order, so<br />

as to avoid common error messages due to incorrect settings or prices. However, errors may still<br />

occur due to requotes, trade context busy or server issues. These errors can't always be avoided, but<br />

we can attempt to place the order again when this happens.<br />

To retry an order on an error, we will place the OrderSend() function inside a while loop. If<br />

OrderSend() does not return a ticket number, we will retry the order again:<br />

128

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

Saved successfully!

Ooh no, something went wrong!