Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

Python 3 data analyst

$
0
0

I have a problem with my script I am trying to plot a triangle marker v or ^ at the candles following my divergence on rsi or ao how to do it?

My code countain this logic:

def detect_divergences(df):    # Calcul des différences pour le RSI    df['rsi_diff'] = df['rsi'].diff()    df['price_diff'] = df['close'].diff()    df['bull_div_rsi'] = np.where((df['rsi_diff'] > 0) & (df['price_diff'] < 0), df['rsi'], np.nan)    df['bear_div_rsi'] = np.where((df['rsi_diff'] < 0) & (df['price_diff'] > 0), df['rsi'], np.nan)    # Retourner les indices des bougies de divergence    bull_div_rsi_indices = df[df['bull_div_rsi'].notnull()].index    bear_div_rsi_indices = df[df['bear_div_rsi'].notnull()].indexdef plot_divergence_markers(df, indices, ax):for index in indices:Récupérer l'index de la bougie suivantenext_index = index + 1if next_index \< len(df):Ploter un marqueur sur la bougie suivantenext_candle = df.loc\[next_index\]fplt.plot(next_candle\['time'\], next_candle\['close'\], ax=ax, marker='^', color='green', markersize=10)def main():historical_data = get_historical_data()if not historical_data.empty:ax, ax_rsi, ax_ao = fplt.create_plot('EUR/USD Price, RSI, and AO', rows=3)fplt.candlestick_ochl(historical_data\[\['time', 'open', 'close', 'high', 'low'\]\], ax=ax)plot_rsi(historical_data, ax=ax_rsi)plot_ao(historical_data, ax=ax_ao)        # Ajout de la moyenne mobile simple (SMA)        plot_sma(historical_data, ax=ax)        # Détecter les divergences        bull_div_rsi_indices, bear_div_rsi_indices = detect_divergences(historical_data)        # Ploter les marqueurs de divergence        plot_divergence_markers(historical_data, bull_div_rsi_indices, ax=ax_rsi)        plot_divergence_markers(historical_data, bear_div_rsi_indices, ax=ax_rsi)        fplt.show()    else:        print("Impossible de récupérer les données historiques.")if __name__ == "__main__":main()

Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>