Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plot Values

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

    Plot Values

    Hello,

    i have an Indicator who works fine. But there are many Values plotted on the Chart and i want make it a little better (see Picture)

    Click image for larger version

Name:	2023-05-09_08h37_00.png
Views:	247
Size:	396.7 KB
ID:	1250604

    This is my Code. Can anyone help to optimize my Indicator?

    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.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators._Dira
    {
        public class _DiraVolume : Indicator
        {
            private double longVolume;
            private double longVolumeAccumulated;
            private double shortVolume;
            private double shortVolumeAccumulated;
            private bool longTrend;
            private int BarstoDraw;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description = @"My custom indicator";
                    Name = "_DiraVolume";
                    Calculate = Calculate.OnBarClose;
                    IsOverlay = true;
                    DisplayInDataBox = true;
                    DrawOnPricePanel = true;
                    DrawHorizontalGridLines = false;
                    DrawVerticalGridLines = false;
                    PaintPriceMarkers = false;
                    ScaleJustification = 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;
                    BarstoDraw = CurrentBar;
                }
                else if (State == State.Configure)
                {
                    AddPlot(Brushes.Red, "LongTrend");
                    AddPlot(Brushes.Green, "ShortTrend");
                    AddPlot(Brushes.Transparent, "TotalVolumeLong");
                    AddPlot(Brushes.Transparent, "TotalVolumeShort");
    
                }
            }
    
            protected override void OnBarUpdate()
            {
    
                if (CurrentBar < 1000)
                    return;
    
                        //if (Low[0] < Low[1] && High[0] == Close[0])
                        if ((High[0] == Close[0] && High[1] == Close[1]) || (High[0] > High[1] && High[1] > High[2] && Close[2] != Low[2]))
                        {
                            longTrend = true;
                            shortVolumeAccumulated = 0;
                            longVolume += Volume[0];
                        }
                        else if ((Low[0] == Close[0] && Low[1] == Close[1]) || (Low[0] < Low[1] && Low[1] < Low[2] && Close[2] != High[2]))
                        {
                            longTrend = false;
                            longVolumeAccumulated += longVolume;
    
                            shortVolume += Volume[0];
                        }
    
                        if (longTrend)
                        {
                            longVolumeAccumulated += Volume[0];
                            shortVolumeAccumulated = 0;
                            PlotBrushes[0][0] = Brushes.Transparent;
                            PlotBrushes[1][0] = Brushes.Transparent;
                        }
                        else
                        {
                            shortVolumeAccumulated += Volume[0];
                            longVolumeAccumulated = 0;
                            PlotBrushes[0][0] = Brushes.Transparent;
                            PlotBrushes[1][0] = Brushes.Transparent;
                        }
    
                        Values[0][0] = longTrend ? High[0] : double.NaN;
                        Values[1][0] = !longTrend ? Low[0] : double.NaN;
                        Values[2][0] = longVolumeAccumulated;
                        Values[3][0] = shortVolumeAccumulated;
    
    
                        if (longTrend)
                            {
                            Draw.Text(this, "L" + CurrentBar, "L " + longVolumeAccumulated, 0, High[0] + TickSize, Brushes.Blue);
                            }
                        else
                            {
                            Draw.Text(this, "S" + CurrentBar, "S " + shortVolumeAccumulated, 0, Low[0] - TickSize, Brushes.Blue);
                            }
                //Print(Time[0] + "   High " + Values[2][0] +  "           "  + Values[2][1] + "     " + CurrentBar);
            }
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private _Dira._DiraVolume[] cache_DiraVolume;
            public _Dira._DiraVolume _DiraVolume()
            {
                return _DiraVolume(Input);
            }
    
            public _Dira._DiraVolume _DiraVolume(ISeries<double> input)
            {
                if (cache_DiraVolume != null)
                    for (int idx = 0; idx < cache_DiraVolume.Length; idx++)
                        if (cache_DiraVolume[idx] != null &&  cache_DiraVolume[idx].EqualsInput(input))
                            return cache_DiraVolume[idx];
                return CacheIndicator<_Dira._DiraVolume>(new _Dira._DiraVolume(), input, ref cache_DiraVolume);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators._Dira._DiraVolume _DiraVolume()
            {
                return indicator._DiraVolume(Input);
            }
    
            public Indicators._Dira._DiraVolume _DiraVolume(ISeries<double> input )
            {
                return indicator._DiraVolume(input);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators._Dira._DiraVolume _DiraVolume()
            {
                return indicator._DiraVolume(Input);
            }
    
            public Indicators._Dira._DiraVolume _DiraVolume(ISeries<double> input )
            {
                return indicator._DiraVolume(input);
            }
        }
    }
    
    #endregion
    ​
    Attached Files

    #2
    Hello Dirales,

    In what way are you trying to make it better? Are you trying to plot only the circled texts?

    Comment


      #3
      Hello Jesse,

      yes i want only plot the circled text and i want it in a <series> to calculate with the last values.

      Comment


        #4
        Hello Dirales,

        You could certainly put a result like that into a series for later use. The first step though would be to make a condition which identifies the bars you circled. Do you currently have a condition or goal that lets you find the circled bars? If there is a certain price condition that results in that bar that could be used as a condition at that time to store values you need or execute logic like setting a series.

        Comment


          #5
          Iam not a programmer, but with enough if else i found a way.

          Click image for larger version

Name:	2023-05-10_12h51_45.png
Views:	142
Size:	354.3 KB
ID:	1250816 If anyone want this... see below

          [ATTACH]n1250817[/ATTACH]

          Comment


            #6
            Don`t know why i cant insert the zip. Here is the Code for this Volume Indicator

            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.Data;
            using NinjaTrader.NinjaScript;
            using NinjaTrader.Core.FloatingPoint;
            using NinjaTrader.NinjaScript.DrawingTools;
            #endregion
            
            //This namespace holds all indicators and is required. Do not change it.
            namespace NinjaTrader.NinjaScript.Indicators._Dira
            {
                public class _DiraVolume3 : Indicator
                {
                    private double longVolume;
                    private Series<double> longVolumeAccumulated;
                    private double shortVolume;
                    private Series<double> shortVolumeAccumulated;
                    private bool longTrend;
                    private int BarstoDraw;
                    public double lasthighVol; double lasthighVol2;
                    double lastlowVol; double lastlowVol2;
                    private int tickabstand = 4;
                    private double CalcProzentVol;
            
                    protected override void OnStateChange()
                    {
                        if (State == State.SetDefaults)
                        {
                            Description = @"_DiraVolume, zeigt das Volumen je Trendrichtung + % an";
                            Name = "_DiraVolume3";
                            Calculate = Calculate.OnEachTick;
                            IsOverlay = true;
                            DisplayInDataBox = true;
                            DrawOnPricePanel = true;
                            DrawHorizontalGridLines = false;
                            DrawVerticalGridLines = false;
                            PaintPriceMarkers = false;
                            ScaleJustification = 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;
                            BarstoDraw = CurrentBar;
                        }
                        else if (State == State.Configure)
                        {
                            AddPlot(Brushes.Transparent, "LongTrend");
                            AddPlot(Brushes.Transparent, "ShortTrend");
                            AddPlot(Brushes.Transparent, "TotalVolumeLong");
                            AddPlot(Brushes.Transparent, "TotalVolumeShort");
                        }
                         else if (State == State.DataLoaded)
                        {
                            // "this" refers to the NinjaScript object itself. This syncs the Series object to historical data bars
                            // MaximumBarsLookBack determines how many values the Series<double> will have access to
                            longVolumeAccumulated = new Series<double>(this, MaximumBarsLookBack.Infinite);
                             shortVolumeAccumulated = new Series<double>(this, MaximumBarsLookBack.Infinite);
                        }
                    }
            
                    protected override void OnBarUpdate()
                    {
            
                        if (CurrentBar < 1000)
                            return;
                            //Berechnungen OncLose
                            //if (BarsInProgress == 0 && CurrentBar > 10 && IsFirstTickOfBar)
                                if (IsFirstTickOfBar)
                            {
                                if ((High[0] == Close[0] && High[1] == Close[1]) || (High[0] > High[1] && High[1] > High[2] && Close[2] != Low[2]))
                                {
                                    longTrend = true;
                                    //shortVolumeAccumulated[0] = 0;
                                    longVolume += Volume[0];
                                }
                                if ((Low[0] == Close[0] && Low[1] == Close[1]) || (Low[0] < Low[1] && Low[1] < Low[2] && Close[2] != High[2]))
                                {
                                    longTrend = false;
                                    longVolumeAccumulated[0] += longVolume;
                                    shortVolume += Volume[0];
                                }
            
                                if (longTrend)
                                {
                                    longVolumeAccumulated[0] = longVolumeAccumulated[1] + Volume[0];
                                    shortVolumeAccumulated[0] = 0;
                                }
                                else
                                {
                                    shortVolumeAccumulated[0] = shortVolumeAccumulated[1] + Volume[0];
                                    longVolumeAccumulated[0] = 0;
                                }
            
                                Values[0][0] = longTrend ? High[0] : 0;
                                Values[1][0] = !longTrend ? Low[0] : 0;
                                Values[2][0] = longVolumeAccumulated[0];
                                Values[3][0] = shortVolumeAccumulated[0];
                                ForceRefresh();
                                Print(Time[0] + "H1 " + Values[0][0]+  "  H2 "  + Values[0][1] );
            
                                if (longTrend && ((Values[0][0] > 0) && (Values[0][1] > 0) && (Values[0][2] == 0)))
                                    {
                                        //RemoveDrawObject("S1");
                                        lastlowVol2 = lastlowVol;
                                        lastlowVol= shortVolumeAccumulated[2];
                                        CalcProzentVol = ((lastlowVol / lastlowVol2) * 100);
                                        Draw.Text(this, "S" + CurrentBar, "" + shortVolumeAccumulated[2] + " (" + CalcProzentVol.ToString("N0") + " %)", 2, Low[2] - TickSize * tickabstand, Brushes.Blue);
                                        //Draw.Text(this, "L" + CurrentBar, "" + longVolumeAccumulated[1] + " (" + CalcProzentVol.ToString("N0") + " %)", 1, High[1] + TickSize * tickabstand, Brushes.Blue);
                                        RemoveDrawObject("S1");
                                    }
                                if (!longTrend && ((Values[1][0] > 0) && (Values[1][1] > 0) && (Values[1][2] == 0)))
                                    {
                                        lasthighVol2 = lasthighVol;
                                        lasthighVol = longVolumeAccumulated[2];
                                        CalcProzentVol = ((lasthighVol / lasthighVol2) * 100);
                                        Draw.Text(this, "L" + CurrentBar, "" + longVolumeAccumulated[2] + " (" + CalcProzentVol.ToString("N0") + " %)", 2, High[2] + TickSize * tickabstand, Brushes.Blue);    
                                        //Draw.Text(this, "S" + CurrentBar, "" + shortVolumeAccumulated[1] + " (" + CalcProzentVol.ToString("N0") + " %)", 1, Low[1] - TickSize * tickabstand, Brushes.Blue);
                                        RemoveDrawObject("L1");
                                    }
            
                                //Print(Time[0] + "H1 " + lasthighVol+  "  H2 "  + lasthighVol2 + "L1 " + lastlowVol+  "  L2 "  + lastlowVol2);
                            }
            
                            //OnEachTick Volume-Anzeige
                            if (!longTrend )
                                    {
                                        shortVolumeAccumulated[0] = shortVolumeAccumulated[1] + Volume[0];
                                        CalcProzentVol = ((shortVolumeAccumulated[0] / lastlowVol) * 100);
                                        Draw.Text(this, "S1", "S " + shortVolumeAccumulated[0] + " (" + CalcProzentVol.ToString("N0") + " %)", 0, Low[0] - TickSize*2, Brushes.Red);
                                        //RemoveDrawObject("L1");
                                    }
                                else
                                    {
                                        longVolumeAccumulated[0] = longVolumeAccumulated[1] + Volume[0];
                                        CalcProzentVol = ((longVolumeAccumulated[0] / lasthighVol) * 100);
                                        Draw.Text(this, "L1", "L " + longVolumeAccumulated[0] + " (" + CalcProzentVol.ToString("N0") + " %)", 0, High[0] + TickSize*2, Brushes.Red);
                                        //RemoveDrawObject("S1");
                                    }
                        //Print(Time[0] + "H1 " + lasthighVol+  "  H2 "  + lasthighVol + "L1 " + lastlowVol+  "  L2 "  + lastlowVol+ "       " + Values[0][1]);
                    }
                }
            }
            
            #region NinjaScript generated code. Neither change nor remove.
            
            namespace NinjaTrader.NinjaScript.Indicators
            {
                public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
                {
                    private _Dira._DiraVolume3[] cache_DiraVolume3;
                    public _Dira._DiraVolume3 _DiraVolume3()
                    {
                        return _DiraVolume3(Input);
                    }
            
                    public _Dira._DiraVolume3 _DiraVolume3(ISeries<double> input)
                    {
                        if (cache_DiraVolume3 != null)
                            for (int idx = 0; idx < cache_DiraVolume3.Length; idx++)
                                if (cache_DiraVolume3[idx] != null &&  cache_DiraVolume3[idx].EqualsInput(input))
                                    return cache_DiraVolume3[idx];
                        return CacheIndicator<_Dira._DiraVolume3>(new _Dira._DiraVolume3(), input, ref cache_DiraVolume3);
                    }
                }
            }
            
            namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
            {
                public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
                {
                    public Indicators._Dira._DiraVolume3 _DiraVolume3()
                    {
                        return indicator._DiraVolume3(Input);
                    }
            
                    public Indicators._Dira._DiraVolume3 _DiraVolume3(ISeries<double> input )
                    {
                        return indicator._DiraVolume3(input);
                    }
                }
            }
            
            namespace NinjaTrader.NinjaScript.Strategies
            {
                public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
                {
                    public Indicators._Dira._DiraVolume3 _DiraVolume3()
                    {
                        return indicator._DiraVolume3(Input);
                    }
            
                    public Indicators._Dira._DiraVolume3 _DiraVolume3(ISeries<double> input )
                    {
                        return indicator._DiraVolume3(input);
                    }
                }
            }
            
            #endregion
            ​
            ​
            Last edited by Dirales; 05-11-2023, 02:30 AM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            647 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X