Pending Order Placement Function
To place pending orders, we'll need to pass parameters for the pending order price as well as the order expiration time.
The PendingPrice and Expiration arguments will be added to the function.
We'll assume that the pending order price, as well as the stop loss and take profit, have been calculated and verified prior to calling this function.
The pending order placement functions will place the stop loss and take profit with the pending order, so no separate order modification function is required.
Note that we've specified a default value of 0 for Expiration. If you are not using a pending order expiration time, and you wish to use the default order comment,you can simply omit the arguments for Expiration and Comment when calling the function.
The following example will place a buy stop order with no expiration time and the default order comment, "Buy Stop Order":
To place pending orders, we'll need to pass parameters for the pending order price as well as the order expiration time.
The PendingPrice and Expiration arguments will be added to the function.
We'll assume that the pending order price, as well as the stop loss and take profit, have been calculated and verified prior to calling this function.
The pending order placement functions will place the stop loss and take profit with the pending order, so no separate order modification function is required.
Inserted Code
int OpenBuyStopOrder(string Symbol(), double LotSize, double PendingPrice, double StopLoss, double TakeProfit, double slippage, double MagicNumber, datetime Expiration = 0, string Comment = "Buy Stop Order") { while(IsTradeContextBusy()) Sleep(10); // Place Buy Stop Order int Ticket = OrderSend(Symbol(),OP_BUYSTOP,LotSize,PendingPrice,Slippage,StopLoss,TakeProfit,Comment,MagicNumber, Expiration,Green); // Error Handling if(Ticket == -1) { int ErrorCode = GetLastError(); string ErrDesc = ErrorDescription(ErrorCode); string ErrAlert = StringConcatenate("Open Buy Stop Order - Error ",ErrorCode,": ",ErrDesc); Alert(ErrAlert); string ErrLog = StringConcatenate("Ask: ",MarketInfo(Symbol(),MODE_ASK)," Lots: ",LotSize," Price: ",PendingPrice," Stop: ",StopLoss," Profit: ",TakeProfit," Expiration: ",TimeToStr(Expiration)); Print(ErrLog); } return(Ticket); }
Note that we've specified a default value of 0 for Expiration. If you are not using a pending order expiration time, and you wish to use the default order comment,you can simply omit the arguments for Expiration and Comment when calling the function.
The following example will place a buy stop order with no expiration time and the default order comment, "Buy Stop Order":
Inserted Code
int Ticket = OpenBuyStopOrder(Symbol(),LotSize,PendingPrice,StopLoss,TakeProfit,UseSlippage,MagicNumber);