Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

My indicator isn't working anymore

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

    My indicator isn't working anymore

    This is my first time developing an indicator, I got it working and next thing tomorrow I opened up ninjatrader and it was no longer working!
    I don't know what I did wrong, it's stil the same code as I wrote when it was working.

    Can anyone please can look into the code and see what I have done wrong?

    PHP Code:
    public class TSDivergence : Indicator
    {
    private bool positiveBarClose;
    private bool negativeBarClose;
    private bool positiveStochClose;
    private bool negativeStochClose;
    private int periodD;
    private int periodK;
    private int smooth;
    private Series<double> value;
    private Series<double> macdVal;
    private Series<double> macdAvg;
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "TS Divergence";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    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;
    }
    else if (State == State.DataLoaded)
    {
    value = new Series<double>(this);
    macdVal = new Series<double>(this);
    macdAvg = new Series<double>(this);
    }
    }
    
    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    
    value[0] = Stochastics(3, 5, 3).K[0];
    
    macdVal[0] = MACD(12, 26, 9)[0];
    macdAvg[0] = MACD(12, 26, 9).Avg[0];
    
    positiveBarClose = Close[0] > Close[1];
    negativeBarClose = Close[0] < Close[1];
    
    positiveStochClose = value[0] > value[1];
    negativeStochClose = value[0] < value[1];
    
    if (macdVal[0] < macdAvg[0]) {
    if (negativeBarClose & positiveStochClose) {
    Draw.Diamond(this, "Down " + CurrentBar.ToString(), false, 0, Close[0] + 0 * TickSize, Brushes.Orange);
    }
    }
    
    if (macdVal[0] > macdAvg[0]) {
    if (positiveBarClose & negativeStochClose) {
    Draw.Diamond(this, "Up" + CurrentBar.ToString(), false, 0, Close[0] - 0 * TickSize, Brushes.Cyan);
    }
    }
    }
    } 
    

    #2
    Anytime an indicator does not perform as expected check the "Log" tab of the NinjaTrader control center for any related error messages.

    Typically you would want to prevent your code from processing until the indicator had passed x number of bars.

    I would suggest using a check of the current bar and returning if the bar is less than [1] which is what you are referencing.

    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.

    if (CurrentBar < 1) return;

    value[0] = Stochastics(3, 5, 3).K[0];


    Reference: https://ninjatrader.com/support/help...tml?alerts.htm

    Comment


      #3
      Thank you so much! I didn't about the log thing! and your solution worked for me.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, Yesterday, 10:06 AM
      0 responses
      17 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      16 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      14 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      9 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      36 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X