Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Display Historic Histogram values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Display Historic Histogram values

    Hi, looking around for references all morning on this & not finding an answer.

    Building a tape reader style indicator and using histograms. Fairly simple calculation & my current version is working but doesn't plot historical data. Specifically, I load it onto a chart, and it begins working, but doesn't show histogram plots prior to time of initialization on the chart. Not sure how to implement this. Properties issue ? Get Set ??

    If so, the Value is "Tape"; I currently have:

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Tape
    {
    get { return Values[0]; }
    }

    Add a set value??

    Or if elsewise thanx in advance ...






    #2
    Hello johnMoss,

    Thank you for your post.

    To clarify, you've created a histogram plot using AddPlot with PlotStyle.Bar correct?

    This should still be able to plot historically as any other plot style.

    Are you assigning values to the plot historically?

    Comment


      #3
      Yes, using PlotStyle.Bar. As noted above, everything is working just fine.

      Tell you what, to simplify this have a look at the Ninjatrader system indicator buy/sell volume, as shown below. This indicator also doesn't plot historic values. Anything in the code below that's either included or perhaps missing that's causing this?

      namespace NinjaTrader.NinjaScript.Indicators
      {
      public class BuySellVolume : Indicator
      {
      private double buys;
      private double sells;
      private int activeBar = 0;

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionBuySellVolume;
      Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meBuySellVolume;
      BarsRequiredToPlot = 1;
      Calculate = Calculate.OnEachTick;
      DrawOnPricePanel = false;
      IsOverlay = false;
      DisplayInDataBox = true;

      // Plots will overlap each other no matter which one of these comes first
      // in NT8, we would add the Sells first in code and then Buys, and the "Sells" was always in front of the buys.
      AddPlot(new Stroke(Brushes.DarkCyan, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.BuySellVolumeBuys);
      AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.BuySellVolumeSells);
      }
      else if (State == State.Historical)
      {
      if (Calculate != Calculate.OnEachTick)
      {
      Draw.TextFixed(this, "NinjaScriptInfo", string.Format(NinjaTrader.Custom.Resource.NinjaScr iptOnBarCloseError, Name), TextPosition.BottomRight);
      Log(string.Format(NinjaTrader.Custom.Resource.Ninj aScriptOnBarCloseError, Name), LogLevel.Error);
      }
      }
      }

      protected override void OnMarketData(MarketDataEventArgs e)
      {
      if(e.MarketDataType == MarketDataType.Last)
      {
      if(e.Price >= e.Ask)
      buys += (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume(e.Volume) : e.Volume);
      else if (e.Price <= e.Bid)
      sells += (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume(e.Volume) : e.Volume);
      }
      }

      protected override void OnBarUpdate()
      {
      if (CurrentBar < activeBar || CurrentBar <= BarsRequiredToPlot)
      return;

      // New Bar has been formed
      // - Assign last volume counted to the prior bar
      // - Reset volume count for new bar
      if (CurrentBar != activeBar)
      {
      Sells[1] = sells;
      Buys[1] = buys + sells;
      buys = 0;
      sells = 0;
      activeBar = CurrentBar;
      }

      Sells[0] = sells;
      Buys[0] = buys + sells;
      }

      region Properties
      [Browsable(false)]
      [XmlIgnore]
      public Series<double> Sells
      {
      get { return Values[1]; }
      }

      [Browsable(false)]
      [XmlIgnore]
      public Series<double> Buys
      {
      get { return Values[0]; }
      }
      #endregion

      }
      }​

      Comment


        #4
        Hello johnMoss,

        Buy/Sell volume only plots on realtime bars because it's getting its values from OnMarketData(), which only works in realtime.

        Why your script isn't working in historical would depend on how its coded. I suggest using prints to debug the script if you're not sure.

        Below is a quick sample script demonstrating a histogram plot, which works on both historical and realtime bars. The plot is assigned a value on every single bar, historical bars are colored red while realtime bars are colored green.

        Attached Files

        Comment


          #5
          Thank you Gaby... GTG

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          558 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X