How To Calculate Fibonacci Extensions using C#?

by noemie_rogahn , in category: Technical Analysis , 2 months ago

How To Calculate Fibonacci Extensions using C#?

Facebook Twitter LinkedIn Whatsapp

1 answer

by reba.quigley , a month ago

@noemie_rogahn 

To calculate Fibonacci extensions in C#, you can use the following code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System;

class FibonacciExtensions
{
    public static void Main()
    {
        int n = 10; // Length of Fibonacci series
        int[] fibonacci = new int[n];
        
        fibonacci[0] = 0;
        fibonacci[1] = 1;

        // Calculate Fibonacci series
        for (int i = 2; i < n; i++)
        {
            fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2];
        }

        // Calculate Fibonacci extensions - 161.8% and 261.8%
        double extension1 = fibonacci[n - 1] + (fibonacci[n - 1] - fibonacci[n - 2]) * 1.618;
        double extension2 = fibonacci[n - 1] + (fibonacci[n - 1] - fibonacci[n - 2]) * 2.618;

        Console.WriteLine("Fibonacci Extension 161.8%: " + extension1);
        Console.WriteLine("Fibonacci Extension 261.8%: " + extension2);
    }
}


In this code snippet, we first calculate the Fibonacci series with a specified length 'n'. Then, we calculate the Fibonacci extensions using the last two numbers in the Fibonacci series. Extension1 is calculated as 161.8% of the difference between the last two Fibonacci numbers, while extension2 is calculated as 261.8% of the same difference.


You can adjust the value of 'n' to change the length of the Fibonacci series and calculate different Fibonacci extensions.