How To Calculate Fibonacci Extensions using PHP?

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

How To Calculate Fibonacci Extensions using PHP?

Facebook Twitter LinkedIn Whatsapp

1 answer

by francisco , a month ago

@bridie_mante 

To calculate Fibonacci extensions using PHP, you can follow these steps:

  1. Define a function to calculate Fibonacci numbers:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
function fibonacci($n) {
    $a = 0;
    $b = 1;

    for ($i = 0; $i < $n; $i++) {
        $temp = $a;
        $a = $b;
        $b = $temp + $b;
    }

    return $a;
}


  1. Calculate the Fibonacci numbers:
1
2
3
4
5
6
7
8
9
$n = 10; // number of Fibonacci numbers to calculate
$fibonacci_numbers = array();

for ($i = 0; $i < $n; $i++) {
    $fibonacci_numbers[$i] = fibonacci($i);
}

// Print the Fibonacci numbers
print_r($fibonacci_numbers);


  1. Calculate the Fibonacci extensions using the calculated Fibonacci numbers:
1
2
3
4
5
6
7
8
9
$extension_ratio = 1.618; // extension ratio for Fibonacci extensions

$extension_numbers = array();
for ($i = 0; $i < $n; $i++) {
    $extension_numbers[$i] = $fibonacci_numbers[$i] * $extension_ratio;
}

// Print the Fibonacci extensions
print_r($extension_numbers);


  1. You can now customize the extension ratio and the number of Fibonacci numbers to calculate to get the desired Fibonacci extensions.


Note: This is a basic example of calculating Fibonacci extensions using PHP. You can further optimize and enhance the code based on your requirements.