locked
Return a value into a method. RRS feed

  • Question

  • Hello,

    I am looking to return a value from a variable to my main method. I tried this:

    var numbers = new List<double> {}; numbers.Add(nearclose); numbers.Add(Close.GetValueAt(CurrentBar)); while (numbers.Count <= 3) { var previous = numbers[numbers.Count-1]; var previous2 = numbers[numbers.Count-2]; numbers.Add((previous *0) + (previous2*1)); } foreach (var item in numbers) { fibo2 = (item - lowPrice0) / (Ncma - lowPrice0);


    }

    The idea is once 

    fibo2 = (Close.GetValueAt(CurrentBar)- lowPrice0) / (Ncma - lowPrice0);

    nearclose return a value 10

    fibo2 = (10- lowPrice0) / (Ncma - lowPrice0);

    the value of nearclose 10 replace Close.GetValueAt.

    and nearclose return a new value 11 and than 11 replace 10 in fibo2

    fibo2 = (11- lowPrice0) / (Ncma - lowPrice0);

    and it goes on. 

    but if i replace Close.GetValueAt by nearclose it will cause an internal loop and i wont access the next values.

    How do i split the value from the variable, and return the value of nearclose in fibo2 to get a list of values?

    TY

    Thursday, October 22, 2020 7:11 PM

All replies

  • Hi Frankdot,

    Thank you for posting here.

    If we analyze the problem based on your description, then it should look like this:

                List<double> result = new List<double>();
                double nearclose = 3;
                while (xxx)
                {
                    var fibo2 = (nearclose - lowPrice0) / (Ncma - lowPrice0);
                    result.Add(fibo2);
                    numbers.Remove(fibo2);
                    nearclose = fibo2;
                }

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 23, 2020 6:10 AM
  • Hello Timon,

    List<double> result = new List<double>(); double nearclose = 0; double close = 4; while (xxx) { var fibo2 = (close - lowPrice0) / (Ncma - lowPrice0); //than close is replaced by nearclose result 5 result.Add(fibo2); // fibo is not involved numbers.Remove(fibo2); // is part of the equation you're not seeing because code nearclose = fibo2; // is too big

    }

    
    //nearclose = 6 when nearclose = 5 has replaced close = 4

    If i punch the number manually it will return the right answer.

    For example var fibo2 = (4 - lowPrice0) / (Ncma - lowPrice0); nearclose = 5

    var fibo2 = (5 - lowPrice0) / (Ncma - lowPrice0); nearclose = 6

    but if i just put var fibo2 = (nearclose - lowPrice0) / (Ncma - lowPrice0); nearclose = 0

    i just want to return the new value of nearclose in fibo2 and not the variable.

    Ty


    Friday, October 23, 2020 12:09 PM