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

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<doublevalue;
    private 
    Series<doublemacdVal;
    private 
    Series<doublemacdAvg;

    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(353).K[0];

    macdVal[0] = MACD(12269)[0];
    macdAvg[0] = MACD(12269).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(), false0Close[0] + TickSizeBrushes.Orange);
    }
    }

    if (
    macdVal[0] > macdAvg[0]) {
    if (
    positiveBarClose negativeStochClose) {
    Draw.Diamond(this"Up" CurrentBar.ToString(), false0Close[0] - TickSizeBrushes.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 benmarkal, Yesterday, 12:52 PM
      3 responses
      22 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by helpwanted, Today, 03:06 AM
      1 response
      17 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      11 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      6 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      244 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Working...
      X