Advertisement
retesere20

--temp-nt-34324

Aug 26th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.81 KB | None | 0 0
  1.  
  2. public class PValue : Indicator
  3. {
  4. protected override void OnStateChange()
  5. {
  6. if (State == State.SetDefaults)
  7. {
  8. Calculate = Calculate.OnEachTick;
  9. IsOverlay = false;
  10. DisplayInDataBox = true;
  11. DrawOnPricePanel = true;
  12. DrawHorizontalGridLines = true;
  13. DrawVerticalGridLines = true;
  14. PaintPriceMarkers = true;
  15. ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
  16. //Disable this property if your indicator requires custom values that cumulate with each new market data event.
  17. //See Help Guide for additional information.
  18. IsSuspendedWhileInactive = true;
  19.  
  20. //
  21. Show_Total = true;
  22. Show_Bid_Ask = true;
  23. AddPlot(new Stroke(Brushes.Orange, 3), PlotStyle.Bar, "Volume");
  24. AddPlot(new Stroke(Brushes.Lime, 1), PlotStyle.Line, "Bid");
  25. AddPlot(new Stroke(Brushes.Pink, 1), PlotStyle.Line, "Ask");
  26. //AddPlot(new Stroke(Brushes.Cyan, 1), PlotStyle.Line, "Ask2");
  27. //AddPlot(new Stroke(Brushes.White, 1), PlotStyle.Line, "Ask3");
  28. ShowTransparentPlotsInDataBox = true;
  29. }
  30. else if (State == State.Configure)
  31. {
  32. //AddDataSeries(Data.BarsPeriodType.Tick, 100);
  33. if (use_dataseries_approach)
  34. {
  35. AddDataSeries(Instrument.FullName, BarsPeriod.BarsPeriodType, BarsPeriod.Value, MarketDataType.Bid);
  36. AddDataSeries(Instrument.FullName, BarsPeriod.BarsPeriodType, BarsPeriod.Value, MarketDataType.Ask);
  37. }
  38. }
  39. }
  40.  
  41. double vol_A, vol_B;
  42.  
  43. double
  44. ask_mtf, ask_current, ask_got, ask_OMD,
  45. bid_mtf, bid_current, bid_got, bid_OMD
  46. ;
  47. long
  48. askVol_mtf, askVol_current, askVol_got, askVol_OMD, askVol_Last_OMD,
  49. bidVol_mtf, bidVol_current, bidVol_got, bidVol_OMD, bidVol_Last_OMD
  50. ;
  51.  
  52. // on realtime, mtf and GetCurrent are almost same always
  53. // mtf obtained value is absolutely same as obtained from OnMarketData, the advantage of historical values too
  54. protected override void OnBarUpdate()
  55. {
  56. if (!Allowed_()) return;
  57.  
  58. if (CurrentBar <= 1) return;
  59. if (BarsInProgress != 0)
  60. {
  61. if (BarsInProgress == 1)
  62. Values[1][0] = Volume[0];
  63. if (BarsInProgress == 2)
  64. Values[2][0] = Volume[0];
  65.  
  66. return;
  67. }
  68.  
  69. int displace = State == State.Realtime ? 0 : 1;
  70. double multiplier = Show_Premium ? Close[0] : 1;
  71.  
  72. if (Show_Total)
  73. {
  74. Values[0][0] = Volume[0] * multiplier;
  75. }
  76.  
  77. //p("OBU---", CurrentBar, IsFirstTickOfBar, BarsInProgress);
  78. if (use_dataseries_approach)
  79. {
  80. if (Show_Bid_Ask)
  81. {
  82. if (CurrentBars[1] > 1) Values[1][0] = Volumes[1][0] * multiplier; // BarsArray[1].GetVolume(CurrentBars[1]); //
  83. if (CurrentBars[2] > 1) Values[2][0] = Volumes[2][0] * multiplier; // BarsArray[2].GetVolume(CurrentBars[2]); //
  84. }
  85. }
  86. else
  87. {
  88. if (State != State.Realtime)
  89. {
  90. if (Show_Bid_Ask)
  91. {
  92. Values[1][0] = (askVol_OMD) * multiplier;
  93. Values[2][0] = (bidVol_OMD) * multiplier;
  94. }
  95. }
  96. }
  97. }
  98.  
  99. int omd__currentbar;
  100. // bidVol_Last_OMD+askVol_Last_OMD is exactly same as main Volumes[0][index] of that bar
  101. protected override void OnMarketData(MarketDataEventArgs e)
  102. {
  103. if (!Allowed_()) return;
  104.  
  105. if (BarsInProgress != 0) return;
  106. if (CurrentBar <= 1) return;
  107.  
  108.  
  109. bool omd__newbar = omd__currentbar != CurrentBar; //More robust then IsFirstTickOfBar
  110. if (omd__newbar)
  111. {
  112. omd__currentbar = CurrentBar;
  113. askVol_OMD = 0;
  114. bidVol_OMD = 0;
  115. askVol_Last_OMD = 0;
  116. bidVol_Last_OMD = 0;
  117. }
  118. //if (e.Ask == null || e.Bid == null) return;
  119.  
  120. if (e.MarketDataType == MarketDataType.Bid)
  121. {
  122. bid_OMD = e.Price; //same as e.Bid
  123. bidVol_OMD += e.Volume;
  124. }
  125. else if (e.MarketDataType == MarketDataType.Ask)
  126. {
  127. ask_OMD = e.Price; //same as e.Ask
  128. askVol_OMD += e.Volume;
  129. }
  130. else if (e.MarketDataType == MarketDataType.Last)
  131. {
  132. if (ask_OMD > 0 && e.Price >= ask_OMD)
  133. {
  134. askVol_Last_OMD += e.Volume;
  135. }
  136. else if (bid_OMD > 0 && e.Price <= bid_OMD)
  137. {
  138. bidVol_Last_OMD += e.Volume;
  139. }
  140. else
  141. {
  142. bidVol_Last_OMD += e.Volume;
  143. askVol_Last_OMD += e.Volume;
  144. }
  145. }
  146.  
  147. if (use_dataseries_approach) return;
  148.  
  149. if (State == State.Realtime)
  150. {
  151. double multiplier = Show_Premium ? Close[0] : 1;
  152. if (Show_Bid_Ask)
  153. {
  154. Values[1][0] = (bidVol_Last_OMD) * multiplier;
  155. Values[2][0] = (askVol_Last_OMD) * multiplier;
  156. }
  157. }
  158. }
  159.  
  160.  
  161.  
  162.  
  163.  
  164. protected override void OnMarketDepth(MarketDepthEventArgs marketDepthUpdate)
  165. {
  166.  
  167. }
  168.  
  169. #region Properties
  170.  
  171. [NinjaScriptProperty]
  172. [Display(Name = "Show Volume", Order = 1, GroupName = "Parameters")]
  173. public bool Show_Total
  174. { get; set; }
  175.  
  176. [NinjaScriptProperty]
  177. [Display(Name = "Show BID ASK volume", Order = 5, GroupName = "Parameters")]
  178. public bool Show_Bid_Ask
  179. { get; set; }
  180.  
  181. [NinjaScriptProperty]
  182. [Display(Name = "Show Premium (instead of volume)", Order = 10, GroupName = "Parameters")]
  183. public bool Show_Premium
  184. { get; set; }
  185.  
  186.  
  187. [NinjaScriptProperty]
  188. [Display(Name = "Use dataseries volume", Order = 10, GroupName = "z_ Data-method")]
  189. public bool use_dataseries_approach
  190. { get; set; }
  191.  
  192.  
  193. [Browsable(false)]
  194. [XmlIgnore]
  195. public Series<double> Premium_Value
  196. {
  197. get { return Values[0]; }
  198. }
  199. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement