Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with elementary code on averages..

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

    Help with elementary code on averages..

    why is this not returning anything on chart. i assume there might be a 0 in division but there shouldnt be.

    Series<double> CloseOpenDiff = new Series<double>(this);;
    if (Close[0] > Open[0])
    {
    CloseOpenDiff[0] = Close[0] - Open[0];
    }
    else
    {
    CloseOpenDiff[0]=0;

    }


    Series<double> OpenCloseDiff = new Series<double>(this);;
    if (Close[0] < Open[0])
    {
    OpenCloseDiff[0] = Open[0] - Close[0];
    }
    else
    {
    OpenCloseDiff[0]=0;

    }

    avgCloseOpen[0] = (SMA(CloseOpenDiff, Period)[0]);
    avgOpenClose[0] = (SMA(OpenCloseDiff, Period)[0]);

    double d=avgCloseOpen[0]/(avgCloseOpen[0]+avgOpenClose[0]);


    Value[0] = d;

    #2
    Hello rocketstock,

    Thanks for your message.

    Series<double>'s should be created in State.DataLoaded. If you use a New indicator Wizard in the NinjaScript Editor, you can create Series<double>'s in the Wizard under Additional Data > Custom Series and then the Wizard will create the Series<double> in State.DataLoaded.

    Using New NinjaScript Wizards - https://ninjatrader.com/support/help.../ns_wizard.htm

    You would then assign values to the Series<double> like you are.

    If you are still experiencing issues after making changes, please check the log tab of the Control Center for any errors and report those errors here. Please also include an export of this script's source code.

    Exporting as source code - https://ninjatrader.com/support/help...tAsSourceFiles

    If you think you are hitting a divide by 0 error, you can use debugging prints to observe what the denominator is and check what is being used. You can avoid divide by 0 errors by checking if your denominator is 0 and taking a different code path.

    Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

    We look forward to assisting.

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello rocketstock,

      Thanks for your message.

      Series<double>'s should be created in State.DataLoaded. If you use a New indicator Wizard in the NinjaScript Editor, you can create Series<double>'s in the Wizard under Additional Data > Custom Series and then the Wizard will create the Series<double> in State.DataLoaded.

      Using New NinjaScript Wizards - https://ninjatrader.com/support/help.../ns_wizard.htm

      You would then assign values to the Series<double> like you are.

      If you are still experiencing issues after making changes, please check the log tab of the Control Center for any errors and report those errors here. Please also include an export of this script's source code.

      Exporting as source code - https://ninjatrader.com/support/help...tAsSourceFiles

      If you think you are hitting a divide by 0 error, you can use debugging prints to observe what the denominator is and check what is being used. You can avoid divide by 0 errors by checking if your denominator is 0 and taking a different code path.

      Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

      We look forward to assisting.


      Thank you very much .NinjaTrader_Jim.. That worked.

      Comment

      Latest Posts

      Collapse

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