Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator does not plot once NT is restarted

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

    Indicator does not plot once NT is restarted

    Hello,
    the code below is a cumulative tick indicator. I experience 2 issues with it. 1: I can't drag and drop it to another panel, 2: it doesn't load to the chart after I restart Ninjatrader. I can't find any suspicious errors within the code, what can cause these errors?

    namespace NinjaTrader.NinjaScript.Indicators.BaluCustom
    {
    public class CumulativeTick : Indicator
    {

    private Brush positiveBrush;
    private Brush negativeBrush;


    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "CumulativeTick";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = false;
    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(new Stroke(Brushes.Transparent, 2), PlotStyle.Bar, "CTick");
    PositiveBrush = Brushes.GreenYellow; // Default positive color
    NegativeBrush = Brushes.Tomato; // Default negative color

    }
    else if (State == State.Configure)
    {
    AddDataSeries("^TICK", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
    }

    else if (State == State.DataLoaded)
    {
    CTick = new Series<double>(this, MaximumBarsLookBack.Infinite);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

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

    // Logic
    CTick[0] = (Closes[1][0] + (CTick[1])) ;

    Values[0][0]=CTick[0];

    // Set color based on CTick value
    PlotBrushes[0][0] = CTick[0] >= 0 ? positiveBrush : negativeBrush;

    // Reset EOD
    if (Bars.IsLastBarOfSession == true)
    {
    CTick[0] = 0;
    }
    }

    region Properties

    [Browsable(false)] // Hides the CTick plot from the properties UI
    [XmlIgnore] // Prevents the CTick plot from being serialized
    public Series<double> CTick { get; private set; }

    [NinjaScriptProperty]

    [Display(Name = "Positive Color", Order = 1, GroupName = "Plot Colors")]
    public Brush PositiveBrush
    {
    // get; set;
    get { return positiveBrush; }
    set { positiveBrush = value; }
    }

    [NinjaScriptProperty]
    [Display(Name = "Negative Color", Order = 2, GroupName = "Plot Colors")]
    public Brush NegativeBrush
    {
    // get; set;
    get { return negativeBrush; }
    set { negativeBrush = value; }
    }

    #endregion

    }
    }​

    #2
    Hello Balage0922,

    Thank you for your post.

    If the indicator isn't saving to the workspace, it is likely because some of your properties haven't been properly serialized, such as your Brush inputs.

    Below is a Help Guide page which includes sample code on serializing brushes.



    As far as dragging and dropping the indicator, try testing again after properly serializing all the inputs in the script.

    Comment


      #3
      Thank you!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      637 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      366 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      107 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      569 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      571 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X