import numpy as np
import pandas as pd
import requests
def fetch_klines(symbol, interval, limit=500):
url = "https://fapi.binance.com/fapi/v1/klines"
params = {
'symbol': symbol,
'interval': interval,
'limit': limit
}
response = requests.get(url, params=params)
data = response.json()
return pd.DataFrame(data, columns=['Open Time', 'Open', 'High', 'Low', 'Close', 'Volume',
'Close Time', 'Quote Asset Volume', 'Number of Trades',
'Taker Buy Base Asset Volume', 'Taker Buy Quote Asset Volume', 'Ignore'])
def calculate_gann_levels(df, price_level=3):
close_prices = df['Close'].astype(float)
# Calculate the Gann Numbers
max_val = 20
gann_numbers = []
for min in range(max_val + 1):
for i in range(4):
gNum = 0 # Initialize gNum to zero
if min == 0 and i == 0:
gNum = min + (min + 2)
elif min > 0 and i == 0:
gNum = round(gann_numbers[-1]) + (min + 1) + min
else:
gNum = round(gann_numbers[-1]) + (min + 2) + min
gann_numbers.append(gNum)
# Calculate price and support/resistance levels
last_close = close_prices.iloc[-1]
# Set denominator based on last close price
if last_close >= 10000:
denominator = 0.01
elif last_close >= 1000:
denominator = 0.1
elif last_close >= 100:
denominator = 1
elif last_close >= 10:
denominator = 10
elif last_close >= 0.05:
denominator = 100
else:
denominator = 1000
price = last_close * denominator
resistance = 0.0
support = 0.0
# Find support and resistance levels
for i in range(len(gann_numbers) - 1):
if gann_numbers[i] <= price < gann_numbers[i + 1]:
resistance = gann_numbers[i + 1] / denominator
support = gann_numbers[i] / denominator
break
blue_gann_price = (support + resistance) / 2
return support, resistance, blue_gann_price
def main():
symbol = "BTCUSDT"
interval = "1h"
price_level = 3 # Change as needed (3 or 5)
# Fetch Kline data
df = fetch_klines(symbol, interval)
# Calculate Gann levels
support, resistance, blue_gann_price = calculate_gann_levels(df, price_level)
# Print the results
print(f"最低支撑价格: {support:.2f}")
print(f"阻力位: {resistance:.2f}")
print(f"当价格在 {blue_gann_price:.2f} 之上时,可能表示市场处于上涨趋势,而当价格在其下方时,可能表示下跌趋势: {blue_gann_price:.2f}")
if __name__ == "__main__":
main()
支撑与阻力位
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 交易实现稳定盈利并不如交易大师们说得天花乱坠,否则就不会有那么多交易者爆仓离场。建立在大量资金基础上的期货交易并不...
- 古语云“授人以鱼不如授人以渔”,说的是传授给人知识,不如传授给人学习知识的方法,一条鱼能解一时之饥,却不能解长久之...