How to get list prices from IEnumerable<double> source?

FranK Duc 121 Reputation points


Will it be possible to resuse this code to list all double in a new list call listCan and use the values in my class.

private int MinIndex ( IEnumerable<double> source )

    var minimumIndex = -1;
    var minimumValue = Double.MaxValue;
    var index = 0;
    foreach (var value in source)
        //If we haven't set a minimum yet OR the current value is less than our previous minimum
        if (value.CompareTo(minimumValue) < 0)
            minimumIndex = index;
            minimumValue = value;

    return minimumIndex;

I created a private list to manipulate data from class OnBarUpdate.
I try to use listCan in OnRender class but if i try:

foreach(var item in listCan)

It return CANSystem.Collections.Generic.List`1[System.Double] and i am unable to find the bug i have.

By doing var sumP = listCan.Skip(foundIndex).Take(Trest); i thought i could get only the prices after foundIndex (500) so price 500 to ----> 1000

But var sumP = listCan.Skip(foundIndex).Take(Trest); return the wrong prices. That means listCan prices are wrong too.

So somewhere the prices have gone throught some transformation i am not aware.

Any idea what i could do?

Thank you

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,449 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Alberto Poblacion 1,551 Reputation points

    The bug is in Print("CAN"+listCan);

    You want to do Print("CAN"+item);

    In other words, on each iteration of the loop you want to print the current item, not the whole list each time. If you try to print the whole list, the method ToString of the list gets called internally, and its default behavior is to print the class name, which is what you are seeing.

    And yes, sumP = listCan.Skip(foundIndex).Take(Trest); should get only the prices after foundIndex. Note "after" not "greater". If it is not returning the values that you think it should be returning, I suspect that it may be due to a wrong interpretation of the meaning of "index". The index here represents the current position in the list. This means that Skip(500) simply discards the first 500 items in the list, in whatever order they happen to exist inside the list at that time. If you expected to get certain particular prices, you will need to first sort the list. Or use "Where" instead of "Skip", depending on what you are trying to achieve.

  2. FranK Duc 121 Reputation points

    This thread was part of a larger discussion that begun here:

    I also ask about my issue with the creators of the software, here:

    The issue is not with var sumP = listCan.Skip(foundIndex).Take(Trest); the issue is with how the list process the values in the actual context.

    Read the ninjatrader thread for a better understanding and than you can read the first one from docs.micr.

    The part of the issue solve by Cooldadtx was about forlooping the listCan to get lowest value of the list and its index.
    The reason why i posted the code above, is to know how to reuse it for sumP. Instead of using Skip i would for loop listCan to introduce foundIndex.

    As you can read in NT forum the result of my list change from one class to another without reasons i can explain.

    Maybe if i dont use Skip it will solve the problem?