Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

for loops dont return right answer

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

    for loops dont return right answer

    Hello,

    I cant tell if its Ninjatrader related or C# related but ill ask anyway.


    Code:
    for(int barIndex = index; barIndex <= ChartBars.ToIndex; barIndex++)
    {
    
    volumeValue += Bars.GetVolume(barIndex);
    }
    // return all the volume between index and ChartBars.ToIndex

    Code:
    for (dq = 1.61D; dq < 2; dq+= 0.01D)
    {
    
    sumvolfibo = (volumeValue / dq);
    // dq return 1.61, 1.62, 1.61 till it get to 2. Than volumeValue is didvided by each dq value.
    }
    How come volumeValue return the wrong number. Right answer should be 4000 and the for loop return 65 875.

    But if i change for
    Code:
     sumvolfibo = (volumeValue /= dq);
    Than the answer is right 4000 but the returned division gives the wrong answer?

    Frank

    Thank you

    #2
    Ok i found the solution.

    To anyone who encounter that problem. It is link to operator overloading.

    Overloading


    The / Operator (Visual Basic) can be overloaded, which means that a class or structure can redefine its behavior when an operand has the type of that class or structure. Overloading the / operator affects the behavior of the /= operator. If your code uses /= on a class or structure that overloads /, be sure you understand its redefined behavior.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    649 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    370 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    109 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    574 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    576 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X