Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PValue : Indicator
- {
- protected override void OnStateChange()
- {
- if (State == State.SetDefaults)
- {
- Calculate = Calculate.OnEachTick;
- IsOverlay = false;
- DisplayInDataBox = true;
- DrawOnPricePanel = true;
- DrawHorizontalGridLines = true;
- DrawVerticalGridLines = true;
- PaintPriceMarkers = true;
- ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
- //Disable this property if your indicator requires custom values that cumulate with each new market data event.
- //See Help Guide for additional information.
- IsSuspendedWhileInactive = true;
- //
- Show_Total = true;
- Show_Bid_Ask = true;
- AddPlot(new Stroke(Brushes.Orange, 3), PlotStyle.Bar, "Volume");
- AddPlot(new Stroke(Brushes.Lime, 1), PlotStyle.Line, "Bid");
- AddPlot(new Stroke(Brushes.Pink, 1), PlotStyle.Line, "Ask");
- //AddPlot(new Stroke(Brushes.Cyan, 1), PlotStyle.Line, "Ask2");
- //AddPlot(new Stroke(Brushes.White, 1), PlotStyle.Line, "Ask3");
- ShowTransparentPlotsInDataBox = true;
- }
- else if (State == State.Configure)
- {
- //AddDataSeries(Data.BarsPeriodType.Tick, 100);
- if (use_dataseries_approach)
- {
- AddDataSeries(Instrument.FullName, BarsPeriod.BarsPeriodType, BarsPeriod.Value, MarketDataType.Bid);
- AddDataSeries(Instrument.FullName, BarsPeriod.BarsPeriodType, BarsPeriod.Value, MarketDataType.Ask);
- }
- }
- }
- double vol_A, vol_B;
- double
- ask_mtf, ask_current, ask_got, ask_OMD,
- bid_mtf, bid_current, bid_got, bid_OMD
- ;
- long
- askVol_mtf, askVol_current, askVol_got, askVol_OMD, askVol_Last_OMD,
- bidVol_mtf, bidVol_current, bidVol_got, bidVol_OMD, bidVol_Last_OMD
- ;
- // on realtime, mtf and GetCurrent are almost same always
- // mtf obtained value is absolutely same as obtained from OnMarketData, the advantage of historical values too
- protected override void OnBarUpdate()
- {
- if (!Allowed_()) return;
- if (CurrentBar <= 1) return;
- if (BarsInProgress != 0)
- {
- if (BarsInProgress == 1)
- Values[1][0] = Volume[0];
- if (BarsInProgress == 2)
- Values[2][0] = Volume[0];
- return;
- }
- int displace = State == State.Realtime ? 0 : 1;
- double multiplier = Show_Premium ? Close[0] : 1;
- if (Show_Total)
- {
- Values[0][0] = Volume[0] * multiplier;
- }
- //p("OBU---", CurrentBar, IsFirstTickOfBar, BarsInProgress);
- if (use_dataseries_approach)
- {
- if (Show_Bid_Ask)
- {
- if (CurrentBars[1] > 1) Values[1][0] = Volumes[1][0] * multiplier; // BarsArray[1].GetVolume(CurrentBars[1]); //
- if (CurrentBars[2] > 1) Values[2][0] = Volumes[2][0] * multiplier; // BarsArray[2].GetVolume(CurrentBars[2]); //
- }
- }
- else
- {
- if (State != State.Realtime)
- {
- if (Show_Bid_Ask)
- {
- Values[1][0] = (askVol_OMD) * multiplier;
- Values[2][0] = (bidVol_OMD) * multiplier;
- }
- }
- }
- }
- int omd__currentbar;
- // bidVol_Last_OMD+askVol_Last_OMD is exactly same as main Volumes[0][index] of that bar
- protected override void OnMarketData(MarketDataEventArgs e)
- {
- if (!Allowed_()) return;
- if (BarsInProgress != 0) return;
- if (CurrentBar <= 1) return;
- bool omd__newbar = omd__currentbar != CurrentBar; //More robust then IsFirstTickOfBar
- if (omd__newbar)
- {
- omd__currentbar = CurrentBar;
- askVol_OMD = 0;
- bidVol_OMD = 0;
- askVol_Last_OMD = 0;
- bidVol_Last_OMD = 0;
- }
- //if (e.Ask == null || e.Bid == null) return;
- if (e.MarketDataType == MarketDataType.Bid)
- {
- bid_OMD = e.Price; //same as e.Bid
- bidVol_OMD += e.Volume;
- }
- else if (e.MarketDataType == MarketDataType.Ask)
- {
- ask_OMD = e.Price; //same as e.Ask
- askVol_OMD += e.Volume;
- }
- else if (e.MarketDataType == MarketDataType.Last)
- {
- if (ask_OMD > 0 && e.Price >= ask_OMD)
- {
- askVol_Last_OMD += e.Volume;
- }
- else if (bid_OMD > 0 && e.Price <= bid_OMD)
- {
- bidVol_Last_OMD += e.Volume;
- }
- else
- {
- bidVol_Last_OMD += e.Volume;
- askVol_Last_OMD += e.Volume;
- }
- }
- if (use_dataseries_approach) return;
- if (State == State.Realtime)
- {
- double multiplier = Show_Premium ? Close[0] : 1;
- if (Show_Bid_Ask)
- {
- Values[1][0] = (bidVol_Last_OMD) * multiplier;
- Values[2][0] = (askVol_Last_OMD) * multiplier;
- }
- }
- }
- protected override void OnMarketDepth(MarketDepthEventArgs marketDepthUpdate)
- {
- }
- #region Properties
- [NinjaScriptProperty]
- [Display(Name = "Show Volume", Order = 1, GroupName = "Parameters")]
- public bool Show_Total
- { get; set; }
- [NinjaScriptProperty]
- [Display(Name = "Show BID ASK volume", Order = 5, GroupName = "Parameters")]
- public bool Show_Bid_Ask
- { get; set; }
- [NinjaScriptProperty]
- [Display(Name = "Show Premium (instead of volume)", Order = 10, GroupName = "Parameters")]
- public bool Show_Premium
- { get; set; }
- [NinjaScriptProperty]
- [Display(Name = "Use dataseries volume", Order = 10, GroupName = "z_ Data-method")]
- public bool use_dataseries_approach
- { get; set; }
- [Browsable(false)]
- [XmlIgnore]
- public Series<double> Premium_Value
- {
- get { return Values[0]; }
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement