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

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 ChastiJose, Today, 03:37 AM
              0 responses
              3 views
              0 likes
              Last Post ChastiJose  
              Started by Klaus Hengher, Today, 03:13 AM
              0 responses
              3 views
              0 likes
              Last Post Klaus Hengher  
              Started by ewileznwpods, Today, 02:57 AM
              0 responses
              1 view
              0 likes
              Last Post ewileznwpods  
              Started by 1001111, Today, 01:35 AM
              0 responses
              6 views
              0 likes
              Last Post 1001111
              by 1001111
               
              Started by ETFVoyageur, Yesterday, 07:05 PM
              1 response
              16 views
              0 likes
              Last Post ETFVoyageur  
              Working...
              X