Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=========================================================
- // HANDLES OCO (One-Cancels-the-Other)
- //---------------------------------------------------------
- // BUY Order EXISTS, cancels all SellStops
- if( viBuyOrderTicket != -1 ) {
- for( int i=OrdersTotal()-1; i>=0; i-- ) {
- if(OrderSelect( i, SELECT_BY_POS, MODE_TRADES ))
- if( OrderSymbol() == Symbol() )
- if( OrderMagicNumber() == viMagicId)
- if( OrderType() == OP_SELLSTOP )
- OrderDelete(OrderTicket());
- Comment("viSellOrderTicket is "+ viSellOrderTicket); //this is always -1 at this point, so it satisfies the condition for creation of a new Sell Order after deletion
- }
- }
- // SELL Order EXISTS, cancels all BuyStops
- if( viSellOrderTicket != -1 ) {
- for( int i=OrdersTotal()-1; i>=0; i-- ) {
- if(OrderSelect( i, SELECT_BY_POS, MODE_TRADES ))
- if( OrderSymbol() == Symbol() )
- if( OrderMagicNumber() == viMagicId)
- if( OrderType() == OP_BUYSTOP )
- OrderDelete(OrderTicket());
- Comment("viBuyOrderTicket is "+ viBuyOrderTicket); //this is always -1 at this point, so it satisfies the condition for creation of a new Buy Order after deletion
- }
- }
- //=========================================================
- //OPEN STOP ORDERS IF NOT EXISTS and NO BUY/SELL ORDERS
- //---------------------------------------------------------
- // Do NOT execute (place new orders) if it is past the trading window.
- if(TimeGMT() >= (vdTradeStartInGMT+viDeleteStopOrderAfterInSec))
- {
- Comment("[GMT " + TimeToStr(TimeGMT()) + "] " + "Already passed execution time.");
- return(0);
- }
- // Place BuyStop if not exists; and no executed Buy order
- if( (viBuyStopTicket == -1) && (viBuyOrderTicket == -1)) { // this condition causes recreation of deleted order
- viFixLots = NormalizeDouble(viFixLots, 2);
- double viPrice = NormalizeDouble(Ask + (viStopOrderLevelInPip*viPipsToPrice), Digits);
- double viSL = viPrice - (viStopLossInPip*viPipsToPrice);
- double viTP = viPrice + (viTargetProfitInPip*viPipsToPrice);
- viBuyStopTicket = OrderSend(Symbol(), OP_BUYSTOP, viFixLots
- , viPrice
- , int(viMaxSlippageInPip*viPipsToPoint)
- , viSL, viTP
- , vsEAComment, viMagicId, 0, Blue);
- }
- // Place SellStop if not exists; and no executed Sell order
- if( (viSellStopTicket == -1) && (viSellOrderTicket == -1) ) { // this condition causes recreation of deleted order RefreshRates();
- viFixLots = NormalizeDouble(viFixLots, 2);
- double viPrice = NormalizeDouble(Bid - (viStopOrderLevelInPip*viPipsToPrice), Digits);
- double viSL = viPrice + (viStopLossInPip*viPipsToPrice);
- double viTP = viPrice - (viTargetProfitInPip*viPipsToPrice);
- viSellStopTicket = OrderSend(Symbol(), OP_SELLSTOP, viFixLots
- , viPrice
- , int(viMaxSlippageInPip*viPipsToPoint)
- , viSL, viTP
- , vsEAComment, viMagicId, 0, Red);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement