Stephen Reynolds: In the following code why is it I cant get it to place stop loss and take profit onto the pending order after it has been placed? bool modify = OrderModify(gBuyTicket,0,stopLoss,takeProfit,0); |
|
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
In the following code why is it I cant get it to place stop loss and take profit onto the pending order after it has been placed?
int gBuyTicket; void OnTick() { //-------------- // Timer //-------------- int hour = Hour(); bool timer = (hour >= 0 && hour <= 23); // Buy Order if(timer && gBuyTicket == 0) { // Buy Objects double pendingBuyPriceAsk = extremhigh+(Bid - Ask); double pendingBuyPriceBid = extremhigh; RefreshRates(); double stopLevel = MarketInfo(_Symbol,MODE_STOPLEVEL) * _Point; double upperStopLevel = Ask + stopLevel; double stopLoss = 0.0; if(StopLoss > 0) stopLoss = pendingBuyPriceBid - (StopLoss * _Point); // Buy Order if(upperStopLevel < stopLoss) gBuyTicket = OrderSend(_Symbol,OP_BUYSTOP,lotSize,pendingBuyPriceAsk,Slippage,0,0,"BuyOrder",MagicNumber,0,clrBlue); buySwitch = true; } // Add stop loss & take profit to Buy order if(OrderType() == OP_BUYSTOP && (StopLoss > 0 || TakeProfit > 0)) { bool select = OrderSelect(gBuyTicket,SELECT_BY_TICKET); double pendingBuyPriceBid = OrderOpenPrice(); // Calculate stop loss & take profit double stopLoss = 0.0; double takeProfit = 0.0; if(StopLoss > 0) stopLoss = pendingBuyPriceBid - (StopLoss * _Point); if(TakeProfit > 0) takeProfit = pendingBuyPriceBid + (TakeProfit * _Point); // Modify order bool modify = OrderModify(gBuyTicket,0,stopLoss,takeProfit,0); } // Closed Outcome 2 - Cancel order if spread is above max spread if(hour == 23 && OrdersTotal() > 0) { for(int order = 0; order <= OrdersTotal() - 1; order++) { bool select = OrderSelect(order,SELECT_BY_POS); // Check buy order for stop placement if(OrderType() == OP_BUYSTOP && OrderMagicNumber() == MagicNumber && select) { bool buyclose = OrderDelete(gBuyTicket,clrBlue); if(buyclose) order--; gBuyTicket = 0; } } } }