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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      47 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      23 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      51 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X