Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Help Please: Indicator To Plot Different Symbol's Delta

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

    Help Please: Indicator To Plot Different Symbol's Delta

    Hello,

    I'm successfully using the below indicator script on an NQ chart while additionally having an ES 1 tick chart open. The code works fine for a short period of time but then typically freezes up within the hour and I'll have to reboot the system. What's intended to be accomplished using OnBarUpdate is to plot ES's cumulative delta in the form of a line on another instrument (NQ, YM, ETY, etc.(. Can you please advise if there's a way to better capture plotting this which isn't as system intensive?

    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
    {
        public class TickCloseNQCurrentBarESNormalize : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "TickCloseNQCurrentBarESNormalize";
                    Calculate                                    = Calculate.OnBarClose;
                    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;
                    AddPlot(Brushes.DarkGreen, "Line");
                    IsAutoScale                    = false;
                    IsOverlay                    = false;
                    IsSuspendedWhileInactive    = true;
                    IsChartOnly                    = true;
                    BarsRequiredToPlot = 20;
                }
                else if (State == State.Configure)
                {
                    AddDataSeries("ES 06-24", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
                    
                }
            }
    
            protected override void OnBarUpdate()
            {
                
                    if (BarsInProgress != 0)
                    return;
    
                if (CurrentBars[0] < BarsRequiredToPlot ||CurrentBars[1] < BarsRequiredToPlot )
                    return;
                
                Value[0] = OrderFlowCumulativeDelta(BarsArray[1], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[0];
                
                
            }
    public Series<double> Upper
    {
      get { return Values[0]; }
    
    }
    
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private TickCloseNQCurrentBarESNormalize[] cacheTickCloseNQCurrentBarESNormalize;
            public TickCloseNQCurrentBarESNormalize TickCloseNQCurrentBarESNormalize()
            {
                return TickCloseNQCurrentBarESNormalize(Input);
            }
    
            public TickCloseNQCurrentBarESNormalize TickCloseNQCurrentBarESNormalize(ISeries<double> input)
            {
                if (cacheTickCloseNQCurrentBarESNormalize != null)
                    for (int idx = 0; idx < cacheTickCloseNQCurrentBarESNormalize.Length; idx++)
                        if (cacheTickCloseNQCurrentBarESNormalize[idx] != null &&  cacheTickCloseNQCurrentBarESNormalize[idx].EqualsInput(input))
                            return cacheTickCloseNQCurrentBarESNormalize[idx];
                return CacheIndicator<TickCloseNQCurrentBarESNormalize>(new TickCloseNQCurrentBarESNormalize(), input, ref cacheTickCloseNQCurrentBarESNormalize);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.TickCloseNQCurrentBarESNormalize TickCloseNQCurrentBarESNormalize()
            {
                return indicator.TickCloseNQCurrentBarESNormalize(Input);
            }
    
            public Indicators.TickCloseNQCurrentBarESNormalize TickCloseNQCurrentBarESNormalize(ISeries<double> input )
            {
                return indicator.TickCloseNQCurrentBarESNormalize(input);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.TickCloseNQCurrentBarESNormalize TickCloseNQCurrentBarESNormalize()
            {
                return indicator.TickCloseNQCurrentBarESNormalize(Input);
            }
    
            public Indicators.TickCloseNQCurrentBarESNormalize TickCloseNQCurrentBarESNormalize(ISeries<double> input )
            {
                return indicator.TickCloseNQCurrentBarESNormalize(input);
            }
        }
    }
    
    #endregion
    ​
    Thanks!

    #2
    Hello jeh007258,

    Thank you for your post.

    As far as performance, I don't see anything in the code that is particularly complex or resource intensive. It may that your current PC has low resources. Are you able to test on a different PC, with no other charts or workspaces open?

    I would like to note that you do need to call update from BarsInProgress 1. This is demonstrated in a code snippet from the Help Guide page for OFCD:



    Please let us know if you have any further questions.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_Gaby thank you. BarsInProgress did the trick

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by itrader46, Today, 10:22 AM
      0 responses
      9 views
      0 likes
      Last Post itrader46  
      Started by NM_eFe, Today, 10:13 AM
      0 responses
      3 views
      0 likes
      Last Post NM_eFe
      by NM_eFe
       
      Started by hdge4u, Yesterday, 12:23 PM
      1 response
      10 views
      0 likes
      Last Post hdge4u
      by hdge4u
       
      Started by 1001111, Today, 09:45 AM
      0 responses
      10 views
      0 likes
      Last Post 1001111
      by 1001111
       
      Started by DTSSTS, 01-28-2024, 12:07 PM
      11 responses
      559 views
      0 likes
      Last Post bmo111
      by bmo111
       
      Working...
      X