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.
Advanced Order Placement<br />
// Error handling<br />
if(Closed == false)<br />
{<br />
ErrorCode = GetLastError();<br />
string ErrDesc = ErrorDescription(ErrorCode);<br />
string ErrAlert = StringConcatenate("Close Sell Order - Error ",<br />
ErrorCode,": ",ErrDesc);<br />
Alert(ErrAlert);<br />
}<br />
}<br />
string ErrLog = StringConcatenate("Ask: ",Ask," Lots: ",LotSize,<br />
" Ticket: ",SellTicket);<br />
Print(ErrLog);<br />
// Open buy order<br />
while(IsTradeContextBusy()) Sleep(10);<br />
RefreshRates();<br />
BuyTicket = OrderSend(Symbol(),OP_BUY,LotSize,Ask,UseSlippage,0,0,<br />
"Buy Order",MagicNumber,0,Green);<br />
// Error handling<br />
if(BuyTicket == -1)<br />
{<br />
ErrorCode = GetLastError();<br />
ErrDesc = ErrorDescription(ErrorCode);<br />
ErrAlert = StringConcatenate("Open Buy Order - Error ",<br />
ErrorCode,": ",ErrDesc);<br />
Alert(ErrAlert);<br />
}<br />
ErrLog = StringConcatenate("Ask: ",Ask," Lots: ",LotSize);<br />
Print(ErrLog);<br />
// Order modification<br />
else<br />
{<br />
OrderSelect(BuyTicket,SELECT_BY_TICKET);<br />
double OpenPrice = OrderOpenPrice();<br />
// Calculate stop level<br />
double StopLevel = MarketInfo(Symbol(),MODE_STOPLEVEL) * Point;<br />
RefreshRates();<br />
double UpperStopLevel = Ask + StopLevel;<br />
double LowerStopLevel = Bid - StopLevel;<br />
double MinStop = 5 * UsePoint;<br />
59