Login / Join

Technical analysis by peymanchart about Symbol BTC on 7 hour ago

https://sahmeto.com/message/3700048
،Technical،peymanchart

import yfinance as yf import pandas as pd import talib import matplotlib.pyplot as plt # دانلود داده 6 ماه اخیر بیت کوین 1 ساعته data = yf.download("BTC-USD", period="6mo", interval="1h") # محاسبه EMA50 و EMA200 روزانه برای روند daily = data.resample('1D').agg({'Open':'first', 'High':'max', 'Low':'min', 'Close':'last'}) daily ['EMA50'] = talib.EMA(daily ['Close'], timeperiod=50) daily ['EMA200'] = talib.EMA(daily ['Close'], timeperiod=200) # تابع روند روزانه def get_trend(date): if date not in daily.index: return 0 row = daily.loc [date] if row ['EMA50'] > row ['EMA200']: return 1 elif row ['EMA50'] < row ['EMA200']: return -1 return 0 # اضافه کردن ستون روند به دیتای 1 ساعته data ['date'] = data.index.floor('D') data ['trend'] = data ['date'].apply(get_trend) # محاسبه EMA50 و RSI ساعتی data ['EMA50'] = talib.EMA(data ['Close'], timeperiod=50) data ['RSI'] = talib.RSI(data ['Close'], timeperiod=14) balance = 10000 position = 0 # 1=خرید، -1=فروش، 0=خالی entry_price = 0 stop_loss_pct = 0.01 risk_reward = 2 trades = [] for i in range(1, len(data)): row = data.iloc prev = data.iloc [i-1] if position == 0: if row ['trend'] == 1: # روند صعودی if prev ['RSI'] < 50 and row ['RSI'] >= 35 and abs(row ['Close'] - row ['EMA50'])/row ['EMA50'] < 0.01: position = 1 entry_price = row ['Close'] stop_loss = entry_price * (1 - stop_loss_pct) take_profit = entry_price + (entry_price - stop_loss)*risk_reward trades.append(('buy', row.name, entry_price)) elif row ['trend'] == -1: # روند نزولی if prev ['RSI'] > 50 and row ['RSI'] <= 65 and abs(row ['Close'] - row ['EMA50'])/row ['EMA50'] < 0.01: position = -1 entry_price = row ['Close'] stop_loss = entry_price * (1 + stop_loss_pct) take_profit = entry_price - (stop_loss - entry_price)*risk_reward trades.append(('sell', row.name, entry_price)) else: if position == 1: if row ['Low'] <= stop_loss: balance -= (entry_price - stop_loss) trades.append(('stop_loss', row.name, stop_loss)) position = 0 elif row ['High'] >= take_profit: balance += (take_profit - entry_price) trades.append(('take_profit', row.name, take_profit)) position = 0 elif position == -1: if row ['High'] >= stop_loss: balance -= (stop_loss - entry_price) trades.append(('stop_loss', row.name, stop_loss)) position = 0 elif row ['Low'] <= take_profit: balance += (entry_price - take_profit) trades.append(('take_profit', row.name, take_profit)) position = 0 print(f"Final balance: {balance}") print("Trades:") for t in trades: print(t) # نمودار ساده plt.figure(figsize=(15,7)) plt.plot(data.index, data ['Close'], label='Price') for t in trades: if t [0] == 'buy': plt.scatter(t [1], t [2], marker='^', color='green') elif t [0] == 'sell': plt.scatter(t [1], t [2], marker='v', color='red') plt.legend() plt.show()

Translated from: English
Show Original Message
Signal Type: Neutral
Time Frame:
30 minutes
Price at Publish Time:
$119,597.03
Share
Signals
Top Traders
Feed
Alerts