Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

High NinjaScript Utilization

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

    High NinjaScript Utilization

    Hi,

    I created an indicator that tracks the Max Min Middle and extensions based off the 9:30 to 10:30am timeframe. It is calculating everything correctly but this indicator is the highest on the NinjaScript Utilization and takes longer than most indicators to load (about 5 minutes).

    I'm hoping to get an idea of where I am calculating too much unnecessarily.

    Thanks for any help.

    Code:
    namespace NinjaTrader.NinjaScript.Indicators.Dhonn
    {
    public class ArangeGuide: Indicator
    {
    
    private int period;
    private int bar1;
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "ArangeGuide";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = false;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = false;
    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(new Stroke(Brushes.Lime),PlotStyle.Hash, "h");
    AddPlot(new Stroke(Brushes.Magenta),PlotStyle.Hash, "l");
    AddPlot(new Stroke(Brushes.Green),PlotStyle.Line, "ibH");
    AddPlot(new Stroke(Brushes.Red),PlotStyle.Line, "ibL");
    AddPlot(new Stroke(Brushes.Goldenrod),PlotStyle.Dot, "ibM");
    AddPlot(new Stroke(Brushes.Green),PlotStyle.Hash, "extH1");
    AddPlot(new Stroke(Brushes.Green),PlotStyle.Hash, "extH2");
    AddPlot(new Stroke(Brushes.Green),PlotStyle.Hash, "extH3");
    AddPlot(new Stroke(Brushes.Red),PlotStyle.Hash, "extL1");
    AddPlot(new Stroke(Brushes.Red),PlotStyle.Hash, "extL2");
    AddPlot(new Stroke(Brushes.Red),PlotStyle.Hash, "extL3");
    }
    
    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Second,30);
    }
    
    }
    
    protected override void OnBarUpdate()
    {
    
    if (BarsInProgress != 0)
    return;
    if (CurrentBar > 10)
    {
    if ((ToTime(Time[0]) < 093000 ))
    return;
    if (h[1] != 0
    && ibH[1] != 0)
    {
    h[0] = h[1];
    l[0] = l[1];
    ibH[0] = ibH[1];
    ibL[0] = ibL[1];
    ibM[0] = ibM[1];
    extH1[0] = extH1[1];
    extH2[0] = extH2[1];
    extH3[0] = extH3[1];
    extL1[0] = extL1[1];
    extL2[0] = extL2[1];
    extL3[0] = extL3[1];
    }
    if ((ToTime(Time[0]) == 093000 ))
    {
    bar1 = CurrentBar;
    }
    
    if ((ToTime(Time[0]) >= 093029 ) && (ToTime(Time[0]) <= 103000 ))
    {
    if (CurrentBar > bar1)
    {
    period = CurrentBar - bar1;
    }
    if ( (ToTime(Time[0]) <= 093030))
    {
    h[0] = Highs[1][0];
    l[0] = Lows[1][0];
    }
    else
    {
    h[0] = h[1];
    l[0] = l[1];
    ibH[0] = MAX(High,period)[0];
    ibL[0] = MIN(Low,period)[0];
    ibM[0] = (ibH[0] + ibL[0]) /2;
    extH1[0] = ibH[0] + 15;
    extL1[0] = ibL[0] - 21;
    if( ibL[0] + 34 > ibH[0])
    extH2[0] = ibL[0] + 34;
    if( ibL[0] + 10.5 > ibH[0])
    extH3[0] = ibL[0] + 10.5;
    if( ibH[0] - 10.5 < ibL[0])
    extL3[0] = ibH[0] - 10.5;
    if( ibH[0] - 34 < ibL[0])
    extL2[0] = ibH[0] - 34;
    
    }
    }
    else
    {
    h[0] = h[1];
    l[0] = l[1];
    ibH[0] = ibH[1];
    ibL[0] = ibL[1];
    ibM[0] = ibM[1];
    extH1[0] = extH1[1];
    extH2[0] = extH2[1];
    extH3[0] = extH3[1];
    extL1[0] = extL1[1];
    extL2[0] = extL2[1];
    extL3[0] = extL3[1];
    
    
    }
    }
    }
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> h
    {
    get { return Values[0]; }
    }
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> l
    {
    get { return Values[1]; }
    }
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> ibH
    {
    get { return Values[2]; }
    }
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> ibL
    {
    get { return Values[3]; }
    }
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> ibM
    {
    get { return Values[4]; }
    }
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> extH1
    {
    get { return Values[5]; }
    }
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> extH2
    {
    get { return Values[6]; }
    }
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> extH3
    {
    get { return Values[7]; }
    }
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> extL1
    {
    get { return Values[8]; }
    }
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> extL2
    {
    get { return Values[9]; }
    }
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> extL3
    {
    get { return Values[10]; }
    }
    }
    }

    #2
    Hello mlprice12,

    The issue is probably loading the historical tick data for the added 30 second bar type. Historical tick data takes longer to load as there is more of it.

    Less days to load will load faster.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_ChelseaB

      Thank you for helping. I am running the indicator with 0 days to load and I removed the 30 second secondary series and I am still having the same performance issue.

      Comment


        #4
        Hello mlprice12,

        As a tip, to export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
        1. Click Tools -> Export -> NinjaScript...
        2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
        3. Click the 'Export' button
        4. Enter a unique name for the file in the value for 'File name:'
        5. Choose a save location -> click Save
        6. Click OK to clear the export location message
        By default your exported file will be in the following location:
        • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
        Below is a link to the help guide on Exporting NinjaScripts.
        http://ninjatrader.com/support/helpG...-us/export.htm

        I've copied and pasted this into a new indicator, but I am not able to reproduce the behavior. The indicator loads in about 20 seconds which is reasonable to download the necessary historical tick data.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        63 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        90 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        47 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        105 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        63 views
        0 likes
        Last Post PaulMohn  
        Working...
        X