Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save normanlmfung/6171c4f3f682a84f94ed81f11a80d1a3 to your computer and use it in GitHub Desktop.
Save normanlmfung/6171c4f3f682a84f94ed81f11a80d1a3 to your computer and use it in GitHub Desktop.
test_fibonacci_example_1
MAGIC_FIB_LEVELS = [0, 0.236, 0.382, 0.5, 0.618, 0.786, 1.00, 1.618, 2.618, 3.618, 4.236]
# https://blog.quantinsti.com/fibonacci-retracement-trading-strategy-python/
def estimate_fib_retracement(
swing_low: float,
swing_low_idx: int,
swing_high: float,
swing_high_idx: int,
target_fib_level: float = 0.618 # Magic 618
):
price_range = swing_high - swing_low
if swing_low_idx < swing_high_idx: # high came first? Or low?
retracement_price = swing_high - (price_range * target_fib_level)
else:
retracement_price = swing_low + (price_range * target_fib_level)
return retracement_price
# Example 1, Big pump from Feb 2024
swing_low = 42590 # 20240201
swing_high = 73082 # 20240314
retracement_level = estimate_fib_retracement(swing_low, 1, swing_high, 2)
# Fibonacci predicted market would have chop to 54237.944 (vs actual was 56.6k on 1 May 2024, so didn't quite chop to 618)
print(f"Fibonacci predicted, after market pumped from {swing_low} to {swing_high}, market will chop to {retracement_level}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment