Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bug

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

    Bug

    I am new to Ninja script.

    I have a simple indicator I want to put on the chart but can't.

    It seems so simple I don't understand what is going on. What I want to do is take the ATR 15 period and multiply that by 1.6. When I am trying to multiple I get no value in the indicator windown.

    Here is my code :

    protectedoverridevoid Initialize()
    {
    Add(
    new Plot(Color.Green, "emdtATRX"));
    }



    protectedoverridevoid OnBarUpdate()
    {
    if (CurrentBar == 0)
    Value.Set(High[
    0] - Low[0]);
    else
    {
    double trueRange = High[0] - Low[0];
    trueRange = Math.Max(Math.Abs(Low[
    0] - Close[1]), Math.Max(trueRange, Math.Abs(High[0] - Close[1])));
    Value.Set((((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period)) * Multiplier);
    }
    }

    Obviously multiplier is a variable set to 1.6 and Multiplier a Property


    What could be wrong ?


    Thanks



    #2
    blarouche,

    Please check the Control Center logs for errors. What message, if any, do you see?
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Overflow

      Here is the message I get from the log :


      Error on plotting 'emdtATRX'. Please check the 'OnBarUpdate' or the 'Plot' method. Overflow error

      Comment


        #4
        blarouche,

        You will need to debug your lines to find out which one is causing the overflow error.

        Break up these lines and evaluate each component individually to find which one is causing the problem. You can use Print() or try-catch blocks to debug.

        trueRange = Math.Max(Math.Abs(Low[0] - Close[1]), Math.Max(trueRange, Math.Abs(High[0] - Close[1])));
        Value.Set((((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period)) * Multiplier);
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Multiply

          Josh

          That's the last line causing the problem. If I don't multiply by 1.6 there is no error !!



          How can I multiply this by 1.6 without error ?

          Comment


            #6
            Here is my variable and property declaration :

            #region Properties
            [Description("")]
            [Category(
            "Parameters")]
            publicdouble Multiplier
            {
            get { return multiplier; }
            set { multiplier = Math.Max(1, value); }
            }
            [Description(
            "")]
            [Category(
            "Parameters")]
            publicint Period
            {
            get { return period; }
            set { period = Math.Max(1, value); }
            }
            #endregion



            #region Variables
            // Wizard generated variables
            privatedouble multiplier = 1.6; // Default setting for Multiplier
            privateint period = 15; // Default setting for Period
            // User defined variables (add any user defined variables below)
            #endregio

            Comment


              #7
              So you are saying this line works?

              Value.Set((((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period)));

              Replace Multiplier with 1.6. Does that cause problems also? Print the calculation out completely. What value is it trying to set if you multiply by 1.6? Is it messing up when the calculation is done outside of Value.Set()?
              Josh P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              580 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              335 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              102 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              554 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              552 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X