Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unable to call values from past bars.

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

    Unable to call values from past bars.

    I am unable to get Volume from prior bar to plot on my screen. If I change Cvol = Volume[0] then current bars volume will plot anything else other that [0] will not plot. I am sure That the error is on my part. Thanks in advance.

    double Cvol = 0;

    if (Bars.IsFirstBarOfSession)
    {
    Cvol = Volume[0];
    }

    else
    {
    Cvol = Volume[1]];
    }

    Values[0] [0] = ( Cvol ) ;

    #2
    Hello FXMIKE,

    Thanks for your post.

    Do you get any compile errors with your code? If not, do you get any errors at run time when you apply the indicator to a chart(these errors would show in the "log" tab of the control center?

    Your code would show the previous bar volume.

    (Note, There is a typo here: Cvol = Volume[1]];

    Comment


      #3
      No error when i compile.

      Comment


        #4
        Hello FXMIKE,

        Thanks for your reply.

        Okay great, no compile error, can you advise regarding my second question, " If not, do you get any errors at run time when you apply the indicator to a chart(these errors would show in the "log" tab of the control center?"

        If you are not getting any run time errors, then please post your full code starting with the AddPlot statement.

        Comment


          #5
          #region Using declarations
          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.ComponentModel.DataAnnotations;
          using System.Linq;
          using System.Text;
          using System.Threading.Tasks;
          using System.Windows;
          using System.Windows.Input;
          using System.Windows.Media;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Gui;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Gui.SuperDom;
          using NinjaTrader.Gui.Tools;
          using NinjaTrader.Data;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.Core.FloatingPoint;
          using NinjaTrader.NinjaScript.DrawingTools;
          #endregion

          //This namespace holds Indicators in this folder and is required. Do not change it.
          namespace NinjaTrader.NinjaScript.Indicators
          {
          public class Vwap : Indicator
          {
          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"";
          Name = "Vwap";
          Calculate = Calculate.OnBarClose;
          IsOverlay = true;
          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;
          AddPlot(Brushes.White, "Vwap1");
          }
          else if (State == State.Configure)
          {
          }
          }

          protected override void OnBarUpdate()

          {
          double Cvol = 0;
          double Cprice = 0;





          if (Bars.IsFirstBarOfSession)


          {
          Cvol = Volume[0];
          Cprice = Volume[0] * ((High[0] + Low[0] + Close[0]) / 3);}
          else
          {
          Cvol = Close[0];
          Cprice = Cprice + (Volume[0] * ((High[0] + Low[0] + Close[0]) / 3));
          }



          Values[0] [0] = ( Cvol ) ;



          }

          #region Properties

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

          }
          }

          #region NinjaScript generated code. Neither change nor remove.

          namespace NinjaTrader.NinjaScript.Indicators
          {
          public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
          {
          private Vwap[] cacheVwap;
          public Vwap Vwap()
          {
          return Vwap(Input);
          }

          public Vwap Vwap(ISeries<double> input)
          {
          if (cacheVwap != null)
          for (int idx = 0; idx < cacheVwap.Length; idx++)
          if (cacheVwap[idx] != null && cacheVwap[idx].EqualsInput(input))
          return cacheVwap[idx];
          return CacheIndicator<Vwap>(new Vwap(), input, ref cacheVwap);
          }
          }
          }

          namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
          {
          public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
          {
          public Indicators.Vwap Vwap()
          {
          return indicator.Vwap(Input);
          }

          public Indicators.Vwap Vwap(ISeries<double> input )
          {
          return indicator.Vwap(input);
          }
          }
          }

          namespace NinjaTrader.NinjaScript.Strategies
          {
          public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
          {
          public Indicators.Vwap Vwap()
          {
          return indicator.Vwap(Input);
          }

          public Indicators.Vwap Vwap(ISeries<double> input )
          {
          return indicator.Vwap(input);
          }
          }
          }

          #endregion

          Comment


            #6
            Hello FXMIKE,

            Thanks for your reply.

            Your code as posted does produce a plot. However, it is not the VWAP. This line: Cvol = Close[0]; make the indicator plot the value of the close of the bar.

            There is a VWAP indicator in the NT8 downloads, here is a link: http://ninjatrader.com/support/forum...hp?&linkid=746

            Comment


              #7
              Thanks. This saves me a bunch of time I see where I was making the mistake in my code now after looking at the Vwap in your link.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              566 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              330 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
              547 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              548 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X