Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

weird division problem

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

    weird division problem

    so i'm trying to build a simple ratio of the total volume of bids / total volume of asks with this code placed in OnMarketDepth:
    Code:
    for(idx = 0; idx < askRows.Count; idx++)
                    {
                        totalaskvol += askRows[idx].Volume;
                    }
                for(idx = 0; idx < bidRows.Count; idx++)
                    {
                        totalbidvol += bidRows[idx].Volume;
                    }
                Print("total bid vol:\t" + totalbidvol);
                Print("total ask vol:\t" + totalaskvol);
                
                if(totalbidvol != 0 && totalaskvol != 0)
                {
                    bidaskratio = totalbidvol/totalaskvol;
                    
                }
                Print("ratio:\t" + bidaskratio);
    but i'm getting weird results for the actual division in the line "bidaskratio = totalbidvol/totalaskvol;"

    the totals calculate right, but the ratio doesn't.
    see below for two examples:
    Code:
    total bid vol:    204
    total ask vol:    167
    ratio:    1
    [ratio should be 1.2215]
    
    total bid vol:    160
    total ask vol:    167
    ratio:    0
    [ratio should be 0.958]
    as you can see, the division simply returns 1 for when there is more ask volume than bid volume, and 0 for the opposite. i'd like a little more precision here... the variable, bidaskratio is of type double.

    what am i doing wrong here?

    #2
    I am terrible at math... so be forewarned

    but..

    I don't see where you've defined bidaskratio. It's not an int is it? should be a double.

    Edit: I see in last sentence of his post he said it was a double.

    Mike
    Last edited by ctrlbrk; 06-05-2009, 09:36 AM.

    Comment


      #3
      Thanks Mike, would have posted the same question...
      BertrandNinjaTrader Customer Service

      Comment


        #4
        auspiv,

        I am not a programmer. I just mess around until things work.

        But, this problem looks familiar. I had a similar situation about a year ago.

        I wish I could remember. When you defined your double, did you put a couple of extra zero's after the decimal point?

        If I could see the all code, that might help jog my memory.

        RJay
        RJay
        NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

        Comment


          #5
          i have the variable defined inside the variable section, and now i'm trying it with decimal, float and double, but with the same results:
          Code:
          double bidaskratio = 0.00000F;
          float baf = 0.00000D;
          decimal bad = 0.0000M;
          
          bidaskratio = totalbidvol/totalaskvol;
          baf = totalbidvol/totalaskvol;
          bad = totalbidvol/totalaskvol;
          none of the above work. and if i just declare, without setting a value it doesn't work either.

          Comment


            #6
            Does this change anything?

            Code:
            double bidAskRatio = totalBidVol/totalAskVol;
            Last edited by NinjaTrader_Bertrand; 06-05-2009, 12:20 PM.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              auspiv,

              Try making the numerator and denominator dataseries. Info may be gettting wiped out in the loops.

              RJay
              RJay
              NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

              Comment


                #8
                Originally posted by NinjaTrader_Bertrand View Post
                Does this change anything?

                Code:
                double bidaskratio = totalbidvol/totalaskvol;
                it didn't.. and i tried creating a function with the above idea, but with the same exact result. this is what i tried:
                Code:
                double Division(int one, int two)
                        {
                            double result = (one/two);
                            return result;
                        }
                Print(Division(totalbidvol, totalaskvol));
                i'm going to try the dataseries idea later on and see how that works.

                Comment


                  #9
                  Then try casting it to doubles this way -

                  Code:
                   
                  double bidAskRatio = (double) totalBidVol/ (double) totalAskVol;
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Bertrand View Post
                    Then try casting it to doubles this way -

                    Code:
                     
                    double bidAskRatio = (double) totalBidVol/ (double) totalAskVol;
                    this works.. thanks for the help!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by muratb35, Today, 03:36 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post muratb35  
                    Started by fernlicht, Today, 02:16 AM
                    2 responses
                    11 views
                    0 likes
                    Last Post fernlicht  
                    Started by fernlicht, 04-12-2021, 06:01 PM
                    1 response
                    28 views
                    0 likes
                    Last Post NinjaTrader_PaulH  
                    Started by memonolog, Today, 02:10 AM
                    3 responses
                    8 views
                    0 likes
                    Last Post memonolog  
                    Started by orenytz, Today, 12:25 AM
                    0 responses
                    9 views
                    0 likes
                    Last Post orenytz
                    by orenytz
                     
                    Working...
                    X