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

Indicator doesn't show up and no data in the data box are showing under the indicator

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

    Indicator doesn't show up and no data in the data box are showing under the indicator

    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.NinjaScript.Indicators;
    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 CustomLinesIndicator : Indicator
    {
    private Series<double> upperLine;
    private Series<double> lowerLine;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Custom Lines Indicator";
    Name = "CustomLinesIndicator";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;

    AddPlot(Brushes.Green, "UpperLine");
    AddPlot(Brushes.Red, "LowerLine");
    }
    else if (State == State.DataLoaded)
    {
    upperLine = new Series<double>(this);
    lowerLine = new Series<double>(this);
    }
    }

    protected override void OnBarUpdate()
    {
    double smoothingFactor = 2.0 / (14 + 1); // EMA smoothing factor
    double emaValue = Close[0]; // Initial EMA value
    double upperValue = 0;
    double lowerValue = 0;

    if (CurrentBar == 0) // Skip calculation for the first bar
    {
    upperLine[0] = upperValue;
    lowerLine[0] = lowerValue;
    return;
    }

    for (int i = 1; i < CurrentBar + 1; i++)
    {
    emaValue = Close[i] * smoothingFactor + emaValue * (1 - smoothingFactor);
    }

    upperValue = emaValue * 1.5 + High[0];
    lowerValue = Low[0] - emaValue * 1.5;

    upperLine[0] = upperValue;
    lowerLine[0] = lowerValue;
    }
    }
    }

    region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private CustomLinesIndicator[] cacheCustomLinesIndicator;
    public CustomLinesIndicator CustomLinesIndicator()
    {
    return CustomLinesIndicator(Input);
    }

    public CustomLinesIndicator CustomLinesIndicator(ISeries<double> input)
    {
    if (cacheCustomLinesIndicator != null)
    for (int idx = 0; idx < cacheCustomLinesIndicator.Length; idx++)
    if (cacheCustomLinesIndicator[idx] != null && cacheCustomLinesIndicator[idx].EqualsInput(input))
    return cacheCustomLinesIndicator[idx];
    return CacheIndicator<CustomLinesIndicator>(new CustomLinesIndicator(), input, ref cacheCustomLinesIndicator);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.CustomLinesIndicator CustomLinesIndicator()
    {
    return indicator.CustomLinesIndicator(Input);
    }

    public Indicators.CustomLinesIndicator CustomLinesIndicator(ISeries<double> input )
    {
    return indicator.CustomLinesIndicator(input);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.CustomLinesIndicator CustomLinesIndicator()
    {
    return indicator.CustomLinesIndicator(Input);
    }

    public Indicators.CustomLinesIndicator CustomLinesIndicator(ISeries<double> input )
    {
    return indicator.CustomLinesIndicator(input);
    }
    }
    }

    #endregion​

    #2
    Hello christopher512,

    Thanks for your post.

    When testing the code you shared it seems the plots are evaluating to n/a in the Data Box window which means they hold no value.

    Have you added debugging prints to your script to understand exactly how it is behaving and calculating values?

    To truly know what is causing the issue it would be necessary to use prints and debug by looking at all of the information the script is using for decisions. Add debugging prints to the indicator script that print out all the values being used for calculations and the Time[0] to see how it is calculating logic.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by GussJ, 03-04-2020, 03:11 PM
    15 responses
    3,271 views
    0 likes
    Last Post xiinteractive  
    Started by Tim-c, Today, 02:10 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Taddypole, Today, 02:47 PM
    0 responses
    2 views
    0 likes
    Last Post Taddypole  
    Started by chbruno, 04-24-2024, 04:10 PM
    4 responses
    51 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    10 responses
    403 views
    1 like
    Last Post beobast
    by beobast
     
    Working...
    X