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

Formula computation always returns ZERO

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

    Formula computation always returns ZERO

    Hi

    Been really scratching my head on this one
    I have a very simple formula
    all of the values are none ZERO ( see the attached screenshot of the OUTOUT Window)
    but my computed value is always ZERO.
    I even multiplied by 10000 instead of 100 and i get the same results

    I would be truly grateful if someone could tell me why...
    is it a c# variable issue?
    is it a problem with the INT and DOUBLE?

    Thank you kindly in advance

    Sammy

    //variables

    private double Average1=0;
    private int a=0, b=0;


    protected override void OnBarUpdate()

    .....

    Average1 = ((a-b)/(a+b))*100;

    Print("average1 = "+Average1);
    Print("a= "+a);
    Print("b= "+b);
    Print("(a-b)= "+(a-b));
    Print("(a+b)= "+(a+b));
    Attached Files

    #2
    Sammy, this is indeed a precision issue you run into, try for example this -

    Average1 = ((double)a - (double)b)/((double)a + (double)b);
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thank you Bertrand...
      the double in front fixed the problem
      Sammy

      Comment


        #4
        Maybe this would have worked as an alternative:

        private double Average1=0;
        private double a=0, b=0;
        eDanny
        NinjaTrader Ecosystem Vendor - Integrity Traders

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by mattbsea, Today, 05:44 PM
        0 responses
        3 views
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        31 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Started by tkaboris, Today, 05:13 PM
        0 responses
        2 views
        0 likes
        Last Post tkaboris  
        Started by GussJ, 03-04-2020, 03:11 PM
        16 responses
        3,282 views
        0 likes
        Last Post Leafcutter  
        Started by WHICKED, Today, 12:45 PM
        2 responses
        20 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Working...
        X