How to pass in a foreach the result from 2 different list?

FranK Duc 121 Reputation points
2021-06-02T13:38:09.237+00:00

Hello,

I am having a foreach statement:

foreach (var item in listm)
    {   
fibo2 = (item - lowPrice0) / (Ncma - lowPrice0);

     }

Inside my list i have the current trading price:

var listm = new List<double>();
listm.Add(Close.GetValueAt(CurrentBar));

Later in the code i have a variable call nearclose. That variable return the equivalent of a new Close price.

Than i have another list:

var listN = new List<double>();
listN.Add(nearclose));

I want to be able to pass the result of listN into the foreach, replace listm by listN. But nearclose wont return a value until listm has been process first.

Than nearclose will return a second value that will return in listN to be pass into the foreach again, and a third value, and a fourth...

It should return in listm: 10
than listN: 10, 11, 12 ...

Is there a way to do that?

Thank you

Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. FranK Duc 121 Reputation points
    2021-06-07T11:55:00.393+00:00

    I get an error message: NinjaScript File Error Code Line Column
    NEWSDBA.cs Operator '-' cannot be applied to operands of type 'void' and 'double' CS0019 159 14

    var listm = new List<double>();
                listm.Add(Close.GetValueAt(CurrentBar));
    
                var listf = new List<double>();
                listf.Add(nearclose);
    
    
                 var list = new List<double>();
    
        var listmAndlistf = listm.Zip(listf, (m, n) => new { item1 = m, item2= n });
                         foreach (var mn in listmAndlistf)
                         {
    
    fibo2 = (list.Add(mn.item1 + mn.item1) - lowPrice0) / (Ncma - lowPrice0);
    
                    Print("num"+mn);
                    }
    
    
    
    I thought it could be possible by using a combination of foreach and while loop:
    

    while (listm.Count <= 4)
    { }

    Cant figure out how to solve this one.

    I just want to iterate both of my list seperatly throught the foreach. Than reiterate once more the result of nearclose into fibo2 multiple times.

    The 9.5 and 10 are just examples, its the result of the variables that need to be fix.

    What you dont understand is that i cant iterate listN in the foreach until listm has iterated first, otherwise nearclose get no result and listN is empty.

    Than once nearclose has a result, listN has too and can be iterated thought the foreach to produce a new result.
    Than you can use a for loop or while loop to reproduce a chain of iteration for listN and produce multiple results of nearclose.

    ty


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.