Advertisement
Guest User

Untitled

a guest
May 14th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. //=========================================================
  2. // HANDLES OCO (One-Cancels-the-Other)
  3. //---------------------------------------------------------
  4. // BUY Order EXISTS, cancels all SellStops
  5. if( viBuyOrderTicket != -1 ) {
  6. for( int i=OrdersTotal()-1; i>=0; i-- ) {
  7. if(OrderSelect( i, SELECT_BY_POS, MODE_TRADES ))
  8. if( OrderSymbol() == Symbol() )
  9. if( OrderMagicNumber() == viMagicId)
  10. if( OrderType() == OP_SELLSTOP )
  11. OrderDelete(OrderTicket());
  12. 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
  13.  
  14. }
  15. }
  16. // SELL Order EXISTS, cancels all BuyStops
  17. if( viSellOrderTicket != -1 ) {
  18. for( int i=OrdersTotal()-1; i>=0; i-- ) {
  19. if(OrderSelect( i, SELECT_BY_POS, MODE_TRADES ))
  20. if( OrderSymbol() == Symbol() )
  21. if( OrderMagicNumber() == viMagicId)
  22. if( OrderType() == OP_BUYSTOP )
  23. OrderDelete(OrderTicket());
  24. 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
  25. }
  26. }
  27.  
  28. //=========================================================
  29. //OPEN STOP ORDERS IF NOT EXISTS and NO BUY/SELL ORDERS
  30. //---------------------------------------------------------
  31. // Do NOT execute (place new orders) if it is past the trading window.
  32. if(TimeGMT() >= (vdTradeStartInGMT+viDeleteStopOrderAfterInSec))
  33. {
  34. Comment("[GMT " + TimeToStr(TimeGMT()) + "] " + "Already passed execution time.");
  35. return(0);
  36. }
  37. // Place BuyStop if not exists; and no executed Buy order
  38. if( (viBuyStopTicket == -1) && (viBuyOrderTicket == -1)) { // this condition causes recreation of deleted order
  39. viFixLots = NormalizeDouble(viFixLots, 2);
  40. double viPrice = NormalizeDouble(Ask + (viStopOrderLevelInPip*viPipsToPrice), Digits);
  41. double viSL = viPrice - (viStopLossInPip*viPipsToPrice);
  42. double viTP = viPrice + (viTargetProfitInPip*viPipsToPrice);
  43. viBuyStopTicket = OrderSend(Symbol(), OP_BUYSTOP, viFixLots
  44. , viPrice
  45. , int(viMaxSlippageInPip*viPipsToPoint)
  46. , viSL, viTP
  47. , vsEAComment, viMagicId, 0, Blue);
  48.  
  49. }
  50. // Place SellStop if not exists; and no executed Sell order
  51. if( (viSellStopTicket == -1) && (viSellOrderTicket == -1) ) { // this condition causes recreation of deleted order RefreshRates();
  52. viFixLots = NormalizeDouble(viFixLots, 2);
  53. double viPrice = NormalizeDouble(Bid - (viStopOrderLevelInPip*viPipsToPrice), Digits);
  54. double viSL = viPrice + (viStopLossInPip*viPipsToPrice);
  55. double viTP = viPrice - (viTargetProfitInPip*viPipsToPrice);
  56. viSellStopTicket = OrderSend(Symbol(), OP_SELLSTOP, viFixLots
  57. , viPrice
  58. , int(viMaxSlippageInPip*viPipsToPoint)
  59. , viSL, viTP
  60. , vsEAComment, viMagicId, 0, Red);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement