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

using decimals

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

    using decimals

    Hi,

    I have a problem with an indicator I'm working on.

    Basically, my indicator formula looks like following :

    Myindicator.Set(varA*varB)

    where varA and varB are double types(very basic). The thing is when I'm running it , it does not plot anything. I've checked the output window to point out the problem and it appears that it comes from my varA which is always equal to 0.

    I think the problem comes from the type of varA .Since the formula looks like Constant/(Period*(Period-1)*(Period+1)), it obviously returns 0.0 when Period is set to 20 for example. The correct value is 0.00000xxx.

    So I tried to change the value type to decimal in order to get the precision I need but when I do it, I'm forced to change the type of varB (also to decimal) and of course my indicator won't compile since Dataseries only holds double values.

    I don't know what to do anymore. Could anyone help me ?

    By the way ,why can't I print the values in the output window with my variables defined as decimals ?

    #2
    kuroro13,

    You should be able to print them.

    Print(var1.ToString());

    Please check your variables through these prints first to see what values they are really at. Would have imagined doubles to work with your values to begin with. If you are using such a small decimal value you may consider normalizing it by removing some zeros.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thank you Josh for your answer.

      I've checked all the code through the prints and i still have the same problem.
      Here is the first part of the code :

      public class filtre1 : Indicator
      {
      #region Variables
      // Wizard generated variables
      private int length = 20; // Default setting for Length
      // User defined variables (add any user defined variables below)
      private double f18=0.00;
      private double f20;
      private int f48=0;
      private int f38=0;
      #endregion

      /// <summary>
      /// This method is used to configure the indicator and is called once before any bar data is loaded.
      /// </summary>
      protected override void Initialize()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Plot0"));
      Add(new Line(Color.FromKnownColor(KnownColor.ControlDark), 0, "Zero"));
      CalculateOnBarClose = true;
      Overlay = false;
      PriceTypeSupported = false;
      arr0 = new double [301];
      arr1 = new double [301];
      arr2 = new int [301];
      arr3 = new int [301];
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>

      protected override void OnBarUpdate()
      {




      if (f38 == 0)
      {
      f38=1;
      f40=0;
      if ((Length-1)>=2)
      {
      f30=Length-1;
      }
      else {f30=2;}

      f48=f30+1;

      f10=Close[0];

      f18=12/(f48*(f48-1)*(f48+1));
      Print(f18.ToString());
      double f20=(f48+1)*0.5;
      Print(f20.ToString());
      }


      When Length is set to 20 the output window shows me :
      0
      10.5

      my f18 is always equal to 0 . I tried to normalize it by multipying it by a 1000 factor but then it returns me 1.

      I'm a little bit lost there....

      Comment


        #4
        You could try this: f18=12.0/(f48*(f48-1)*(f48+1));

        Comment


          #5
          Thank you Ralph !!!

          It works smoothly now...but now you should give me a little explanation on why ?!!! :-)

          Comment


            #6
            Hi kuroro13,

            12 is an integer and if divided by a double, the double is converted to integer obviously, so your result is: 12/7980.0 -> 0.
            12.0 is a double and so is the result: 12.0/7980.0 -> 0.0015

            Regards
            Ralph

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Rapine Heihei, 04-23-2024, 07:51 PM
            2 responses
            30 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by Shansen, 08-30-2019, 10:18 PM
            24 responses
            943 views
            0 likes
            Last Post spwizard  
            Started by Max238, Today, 01:28 AM
            0 responses
            9 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by rocketman7, Today, 01:00 AM
            0 responses
            7 views
            0 likes
            Last Post rocketman7  
            Started by wzgy0920, 04-20-2024, 06:09 PM
            2 responses
            28 views
            0 likes
            Last Post wzgy0920  
            Working...
            X