Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reading Volumetric info for Indicator Development

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

    Reading Volumetric info for Indicator Development

    Hi,
    I am trying to build an indicator using Volumetric info. I want to trace some levels on the POC of the given candles. While trying to code it in Script, I cannot get the righr "BarType" in the script.

    Any help into how to code it? I am aiming to draw some lines to the right using the POC, VAH, VAL of the candle volume profile.

    Appreciate the help.
    Attached Files

    #2
    Hello carlosgutierrez,

    The code you have shown is not valid, if you are learning from some other source besides the help guide that may be why. You can find a sample of the code required to access volumetric data here: https://ninjatrader.com/support/help...tric_bars2.htm

    Comment


      #3
      Yes, I was.
      Thanks for the guidance.


      I have been following the instructions and been doing well so far. But what I have not yet achieved is to be able for the indicator to read the type of chart it is in and plot as usual.
      Currently the code has the <AddVolumetric("MNQ 03-25", BarsPeriodType.Minute, 240, VolumetricDeltaType.BidAsk, 1);> But I need to be able to change time frame and chart types (volume, tick, etc.). On the <https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?order_flow_volumetri c_bars2.htm> I have not been able to achieve this.

      I can make a somewhat manual override and add properties and be able to edit the instrument name, PeriodTypeValue and Ticks per Level. But the BarType cannot be changed that way-

      Any snippets on how to get to that end?


      TIA!!

      Comment


        #4
        To use the chart the indicator is applied to you don't need to use AddVolumetric for that purpose, you would just use the code from the help guide sample without modification. That code targets the chart series so any changes to the charts data series would be picked up by the script.

        In regard to making AddVolumetric dynamic, that is not supported and is mentioned in the help guide page for AddVolumetric.

        •Arguments supplied to AddVolumetric() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided.

        Comment


          #5
          What I am trying to achieve is to have a naked 30 minute chart with my indicator. I don't want to get the Volumetric 30 minute chart as I want it to be as clean as possible, you know?
          I still want the indicator to read the Volumetric information for plotting in any chart type.

          Having some trouble achieving this... any additional guidance is appreciated.

          Comment


            #6
            Or will it only be able to be plotted in volumetric-based charts dynamically without changing the code?

            Comment


              #7
              Hello carlosgutierrez,

              If you have a 30 minute chart to get the volumetric chart for the same instrument you use null for the instrument name with AddVolumetric.

              Comment


                #8
                I haev this on my code so far:

                else if (State == State.Configure)
                {
                // Nothing here as I am trying to make it chart across all volumetric charts.


                }
                }


                protected override void OnBarUpdate()
                {
                // Add your custom indicator logic here

                // Indicates if the indicator is working and plotted when added to the chart
                Draw.TextFixed(this, "Square2", "INDICATOR ENABLED POC v500", TextPosition.BottomRight, Brushes.Green, title1, Brushes.Transparent, Brushes.Transparent, 50);

                if (CurrentBars[0] < 20 || CurrentBars[1] < 20) return;

                if (Bars == null) return;


                NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as
                NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;

                if (barsType == null) return;

                try
                {
                double pocPrice0, pocPrice1;
                double pocVolume0 = barsType.Volumes[CurrentBar].GetMaximumVolume(null, out pocPrice0);
                double pocVolume1 = barsType.Volumes[CurrentBar - 1].GetMaximumVolume(null, out pocPrice1);

                Print("=========================================== ==============================");
                Print("Bar: " + CurrentBar);
                Print("POC Volume (Bar 0): " + pocVolume0 + " at Price: " + pocPrice0);
                Print("POC Volume (Bar 1): " + pocVolume1 + " at Price: " + pocPrice1);

                // Plot POC dots and labels
                Draw.Dot(this, "POC" + CurrentBar, false, 0, pocPrice0, Brushes.Magenta);
                Draw.Text(this, "POCLabel" + CurrentBar, pocPrice0.ToString("F2"), 0, pocPrice0, Brushes.WhiteSmoke);​
                //rest of code
                }​



                Where am I getting it wrong?

                Comment


                  #9
                  Hello carlosgutierrez,

                  That will get the volumetric data assuming the primary series is a volumetric series. You are trying to cast the primary series to volumetric, if it fails that condition is false. If you are trying to use a secondary series you need to use the commented code in the sample in place of what you have

                  NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = BarsArray[1].BarsType as
                  NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;​

                  Comment


                    #10
                    Got it! Thanks.

                    I have another issue and have not found a way of getting through it.

                    The current script is plotting Horizontal Lines at certain levels. But I need those levels to do two things for resulting in invalidation:
                    1. if Price comes back (OHLC) at the level, then instead of plotting with a Solid Line, turn into a Dash Line
                    2. if Price comes back for a second time (OHLC) then delete the drawing


                    How can I achieve this?
                    The examples I have found are only if high or low breach the level then it gets invalidated; and this is happening with the reference bar, so many levels are being deleted prematurely.



                    I am drawing a Ray from two anchors which woulb give the intStartBarsAgo = CurrentBar - 1 and the startY = fibLevel50

                    // Draw the 50% Fibonacci ray
                    Draw.Line(this, fibRayTag, false, CurrentBar - 1, fibLevel50, CurrentBar, fibLevel50, Brushes.Yellow, DashStyleHelper.Dash, 2);​

                    The issue is at endY where it is the same 'CurrentBar', I'd like this to be dynamic as the plot can be trigger on say bar 450 (StartBar) and then the condition to be removed triggers 50 bars later (bar number 500). and i would like to end the plot at either 500 or 499.


                    Also having trouble with the StartBarsAgo, currently all my plots start in the first bar of the chart.

                    Click image for larger version

Name:	image.png
Views:	242
Size:	31.1 KB
ID:	1328892
                    Last edited by carlosgutierrez; 12-23-2024, 12:26 AM.

                    Comment


                      #11
                      Hello carlosgutierrez,

                      Using CurrentBar as the barsAgo value would result in the anchor being placed on the first bar of the chart.

                      If you are wanting to draw on the most recent bar use 0 as the barsAgo and use 1 for the previous bar.

                      You may want to use bools to track the behavior.

                      A bool would track the first time the condition is true. A second bool would track when the condition is no longer true. When both are set the 2nd action can be triggered.

                      In the sample code below I'll use Close[0] == fibLevel50 as a simple branch condition, you would replace this with whatever your condition you want checked twice is

                      private bool branchConditionsHasBeenTrue, branchConditionWasTrueThenBecameFalse;

                      if (/* reset conditions here, for example resetting on a new bar after both bools are true */ FirstTickOfBar == true && branchConditionsHasBeenTrue == true && branchConditionWasTrueThenBecameFalse == true)
                      {
                      branchConditionsHasBeenTrue = false;
                      branchConditionWasTrueThenBecameFalse = false;
                      }

                      if (/* branch conditions here */ Close[0] == fibLevel50)
                      {
                      branchConditionsHasBeenTrue = true;
                      // trigger action such as calling draw method with DashStyleHelper.Dash
                      }

                      if (branchConditionsHasBeenTrue == true && /* opposite of branch condition here */ Close[0] != fibLevel50)
                      {
                      branchConditionWasTrueThenBecameFalse = true; // this lets us know the condition was true but is now false
                      branchConditionsHasBeenTrue = false; // the branchConditionsHasBeenTrue will need to become true a second time
                      }

                      if (branchConditionsHasBeenTrue == true && branchConditionWasTrueThenBecameFalse == true)
                      {
                      // trigger action such as calling RemoveDrawObject()
                      }
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        I still can't get it to where I need. I think its a simple fix but can get it accross the finish line. Here goes my code and 2 images, one where it shows the current script and nother one with manual drawings showing how it should be plotted.

                        The drawinh should be changed to Draw.Line instead of the current Draw.HoriozntalLine. I am having trouble with the List & Dictionaries to store the data and invalidating the level once price trades back to it.

                        Indicator logic: on every candle close, draw Fib 50% from POC1 (Bar1) to POC0 (Bar0). draw line at 50% Fib level starting on Bar1 and all the way to the right. Then when price trades back to said Fib level, then stop the Line plot at the bar intersect.

                        This current script plots all POC 50% levels but does not delete them.

                        Appreciate the support and guidance.

                        Code:
                        #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.Charles
                        {
                            public class xPOCv72 : Indicator
                            {
                                
                                private List<double> fibonacciLevels = new List<double>();
                                private List<string> drawTags = new List<string>();
                                private string levelTagPrefix = "Fib50_";
                        
                                private DateTime currentSessionDate;
                        
                                [NinjaScriptProperty]
                                [Display(Name = "Plot Today's Levels Only", Description = "If true, only plot levels for today.", Order = 0, GroupName = "Parameters")]
                                public bool PlotTodaysLevelsOnly { get; set; }
                                
                                [NinjaScriptProperty]
                                [Display(Name = "Enable Global Lines", Description = "If true, lines will be global across all charts.", Order = 1, GroupName = "Parameters")]
                                public bool EnableGlobalLines { get; set; }
                        
                                [NinjaScriptProperty]
                                [Display(Name = "Today's Levels Color", Description = "Color of today's levels.", Order = 2, GroupName = "Today's Levels")]
                                public Brush TodayLineColor { get; set; }
                        
                                [NinjaScriptProperty]
                                [Display(Name = "Today's Dash Style", Description = "Dash style of today's levels.", Order = 3, GroupName = "Today's Levels")]
                                public DashStyleHelper TodayDashStyle { get; set; }
                        
                                [NinjaScriptProperty]
                                [Display(Name = "Previous Day Levels Color", Description = "Color of previous day's levels.", Order = 4, GroupName = "Previous Day Levels")]
                                public Brush PreviousDayLineColor { get; set; }
                        
                                [NinjaScriptProperty]
                                [Display(Name = "Previous Day Dash Style", Description = "Dash style of previous day's levels.", Order = 5, GroupName = "Previous Day Levels")]
                                public DashStyleHelper PreviousDayDashStyle { get; set; }
                                
                                NinjaTrader.Gui.Tools.SimpleFont title1 = new NinjaTrader.Gui.Tools.SimpleFont("Charles", 16) { Size = 20, Bold = true};
                                
                                protected override void OnStateChange()
                                {
                                    if (State == State.SetDefaults)
                                    {
                                        Description                                    = @"Script from v7 neat";
                                        Name                                        = "xPOCv72";
                                        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;
                                        
                                        // Default values
                                        PlotTodaysLevelsOnly = false;
                                        EnableGlobalLines = false; // Default is false
                                        TodayLineColor = Brushes.Yellow;
                                        TodayDashStyle = DashStyleHelper.Dash;
                                        PreviousDayLineColor = Brushes.Red;
                                        PreviousDayDashStyle = DashStyleHelper.Solid;
                        
                                        currentSessionDate = DateTime.MinValue;
                                        
                                        
                                    }
                                    else if (State == State.Configure)
                                    {[IMG2=JSON]{"data-align":"none","data-size":"full","title":"indicator plot","src":"https:\/\/forum.ninjatrader.com\/local+screenshot"}[/IMG2]
                            }
                        }​
                        Attached Files
                        Last edited by carlosgutierrez; 01-03-2025, 10:58 AM. Reason: added manual level draw photo.

                        Comment


                          #13
                          Hello carlosgutierrez,

                          While we cannot debug the script for you we can assist with specific questions you have. Regarding lists and dictionaries, I can only suggest using external C# educational resources if you are having difficulty on that topic. To use Draw.Line in your logic you would need to know a start and end anchor bars ago when you draw it to span the bars you wanted it to cross.

                          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