Advertisement
retesere20

Untitled

Apr 19th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. //
  2. // Copyright (C) 2016, NinjaTrader LLC <www.ninjatrader.com>.
  3. // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
  4. //
  5. #region Using declarations
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.ComponentModel.DataAnnotations;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Xml.Serialization;
  17. using NinjaTrader.Cbi;
  18. using NinjaTrader.Gui;
  19. using NinjaTrader.Gui.Chart;
  20. using NinjaTrader.Gui.SuperDom;
  21. using NinjaTrader.Data;
  22. using NinjaTrader.NinjaScript;
  23. using NinjaTrader.Core.FloatingPoint;
  24. using NinjaTrader.NinjaScript.Indicators;
  25. using NinjaTrader.NinjaScript.DrawingTools;
  26. #endregion
  27.  
  28. //This namespace holds strategies in this folder and is required. Do not change it.
  29. namespace NinjaTrader.NinjaScript.Strategies.AlanStrategies
  30. {
  31. public class Buy3with3Pts3Sl : Strategy
  32. {
  33.  
  34. /*
  35. Written by Alan Palmer
  36. */
  37.  
  38. private double xPrice1;
  39. private double xPrice2;
  40. private double xPrice3;
  41. private Order myEntryOrder1 = null;
  42. private Order myEntryOrder2 = null;
  43. private Order myEntryOrder3 = null;
  44.  
  45.  
  46. protected override void OnStateChange()
  47. {
  48. if (State == State.SetDefaults)
  49. {
  50. Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDescriptionSampleMACrossOver;
  51. Name = "Buy3with3Pts3Sl";
  52.  
  53. EntriesPerDirection = 1;
  54. EntryHandling = EntryHandling.UniqueEntries;
  55. IsInstantiatedOnEachOptimizationIteration = false;
  56. }
  57. else if (State == State.Configure)
  58. {
  59.  
  60. }
  61. }
  62.  
  63. protected override void OnBarUpdate()
  64. {
  65. if(State==State.Historical) return;
  66. if (CurrentBar < 20) return;
  67.  
  68. if(Close[0] != Close[5] && Position.MarketPosition == MarketPosition.Flat)
  69. {
  70.  
  71. EnterLong(1, "Buy Long A");
  72. EnterLong(1, "Buy Long B");
  73. EnterLong(1, "Buy Long C");
  74. }
  75.  
  76. if (Close[0] > xPrice1+3*TickSize)
  77. {
  78. ExitLongLimit(0, true, 1, xPrice1 + 4 * TickSize, "Sell 1a", "Buy Long A");
  79. }
  80.  
  81.  
  82. }
  83. protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
  84. {
  85. Print(execution.Order.Name.ToString());
  86. if (execution.Order.Name == "Buy Long A" && execution.Order.OrderState == OrderState.Filled)
  87. {
  88. xPrice1 = Position.AveragePrice;
  89. ExitLongLimit(0, true, 1, xPrice1 + 20 * TickSize, "Sell 1a", "Buy Long A");
  90. ExitLongStopMarket(0, true, 1, xPrice1 - 12 * TickSize, "Sell Stop A", "Buy Long A");
  91. }
  92. if (execution.Order.Name == "Buy Long B" && execution.Order.OrderState == OrderState.Filled)
  93. {
  94. xPrice2 = Position.AveragePrice;
  95. ExitLongLimit(0, true, 1, xPrice2 + 5 * TickSize, "Sell 1b", "Buy Long B");
  96. ExitLongStopMarket(0, true, 1, xPrice2 - 12 * TickSize, "Sell Stop B", "Buy Long B");
  97. }
  98. if (execution.Order.Name == "Buy Long C" && execution.Order.OrderState == OrderState.Filled)
  99. {
  100. xPrice3 = Position.AveragePrice;
  101. ExitLongLimit(0, true, 1, xPrice3 + 6 * TickSize, "Sell 1c", "Buy Long C");
  102. ExitLongStopMarket(0, true, 1, xPrice3 - 12 * TickSize, "Sell Stop C", "Buy Long C");
  103. }
  104.  
  105.  
  106. // xPrice1 = Position.AveragePrice;
  107.  
  108. //ExitLongLimit(0, true, 1, xPrice+4*TickSize, "Sell 1a", "Buy Long A");
  109. //ExitLongLimit(0, true, 1, xPrice+5*TickSize, "Sell 1b", "Buy Long B");
  110. //ExitLongLimit(0, true, 1, xPrice+6*TickSize, "Sell 1c", "Buy Long C");
  111.  
  112. //ExitLongStopMarket(0, true, 1, xPrice-12*TickSize, "Sell Stop A", "Buy Long A");
  113. //ExitLongStopMarket(0, true, 1, xPrice-12*TickSize, "Sell Stop B", "Buy Long B");
  114. //ExitLongStopMarket(0, true, 1, xPrice-12*TickSize, "Sell Stop C", "Buy Long C");
  115.  
  116. }
  117.  
  118. #region Properties
  119. // [Range(1, int.MaxValue), NinjaScriptProperty]
  120. // [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
  121. // public int Fast
  122. // { get; set; }
  123.  
  124. // [Range(1, int.MaxValue), NinjaScriptProperty]
  125. // [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
  126. // public int Slow
  127. // { get; set; }
  128. #endregion
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement