OPEN-SOURCE SCRIPT

Advanced Support and Resistance Zones with Buy/Sell Signals

114
import ccxt
import pandas as pd
import numpy as np
import ta

# اتصال به بازار (مثال: Binance)
exchange = ccxt.binance()

# تنظیمات
symbol = 'BTC/USDT' # جفت معاملاتی
timeframe = '4h' # تایم‌فریم 4 ساعته

# دریافت داده‌های قیمتی
def fetch_data(symbol, timeframe, limit=100):
try:
ohlcv = exchange.fetch_ohlcv(symbol, timeframe=timeframe, limit=limit)
df = pd.DataFrame(ohlcv, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
return df
except Exception as e:
print(f"خطا در دریافت داده‌ها: {e}")
return None

# محاسبه EMA
def calculate_ema(data, period):
return ta.trend.ema_indicator(data['close'], window=period)

# محاسبه Fibonacci Retracement
def calculate_fibonacci_levels(data):
high = data['high'].max()
low = data['low'].min()
diff = high - low
levels = {
"0%": high,
"23.6%": high - 0.236 * diff,
"38.2%": high - 0.382 * diff,
"50%": high - 0.5 * diff,
"61.8%": high - 0.618 * diff,
"100%": low
}
return levels

# محاسبه Pivot Points
def calculate_pivot_points(data):
high = data['high'].max()
low = data['low'].min()
close = data['close'].iloc[-1]
pivot = (high + low + close) / 3
r1 = (2 * pivot) - low
s1 = (2 * pivot) - high
r2 = pivot + (high - low)
s2 = pivot - (high - low)
return {"R1": r1, "S1": s1, "R2": r2, "S2": s2}

# شناسایی مناطق حمایت و مقاومت
def identify_support_resistance(data, ema_period=20):
support_zones = {}
resistance_zones = {}

# محاسبه EMA
ema = calculate_ema(data, ema_period)
ema_value = ema.iloc[-1]

# محاسبه Fibonacci Levels
fib_levels = calculate_fibonacci_levels(data)

# محاسبه Pivot Points
pivot_points = calculate_pivot_points(data)

# ترکیب ابزارها برای شناسایی مناطق
all_levels = list(fib_levels.values()) + [ema_value] + list(pivot_points.values())
for level in all_levels:
count = 0
if level in fib_levels.values():
count += 1
if abs(level - ema_value) < 100: # اگر EMA نزدیک باشد
count += 1
if level in pivot_points.values():
count += 1

if count >= 2: # حداقل دو ابزار تایید کننده
if level < data['close'].iloc[-1]: # حمایت
support_zones[level] = count
else: # مقاومت
resistance_zones[level] = count

return support_zones, resistance_zones

# اجرای ربات
if __name__ == "__main__":
df = fetch_data(symbol, timeframe)
if df is not None:
support_zones, resistance_zones = identify_support_resistance(df)

print("مناطق حمایت:")
for zone, strength in support_zones.items():
print(f"قیمت: {zone}, قوت: {strength}")

print("\nمناطق مقاومت:")
for zone, strength in resistance_zones.items():
print(f"قیمت: {zone}, قوت: {strength}")

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.