aaryamangumber400

EMA Crossover with RSI


ChatGPT
Certainly! Here's a TradingView Pine Script that combines EMA crossover with RSI to generate buy and sell signals. The script will give a buy signal when the 20 EMA crosses above the 50 EMA and the RSI is below a certain threshold (indicating it's not overbought). Similarly, it will give a sell signal when the 20 EMA crosses below the 50 EMA and the RSI is above a certain threshold (indicating it's not oversold).

pinescript
Copy code
//@version=5
indicator("EMA Crossover with RSI", overlay=true)

// Input for EMAs
ema20_length = input.int(20, title="20 EMA Length")
ema50_length = input.int(50, title="50 EMA Length")

// Input for RSI
rsi_length = input.int(14, title="RSI Length")
rsi_overbought = input.int(70, title="RSI Overbought Level")
rsi_oversold = input.int(30, title="RSI Oversold Level")

// Calculating EMAs
ema20 = ta.ema(close, ema20_length)
ema50 = ta.ema(close, ema50_length)

// Calculating RSI
rsi = ta.rsi(close, rsi_length)

// Plotting EMAs
plot(ema20, title="20 EMA", color=color.blue, linewidth=2)
plot(ema50, title="50 EMA", color=color.red, linewidth=2)

// Conditions for buy and sell signals
buy_condition = ta.crossover(ema20, ema50) and rsi < rsi_overbought
sell_condition = ta.crossunder(ema20, ema50) and rsi > rsi_oversold

// Plotting buy and sell signals on the chart
plotshape(series=buy_condition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sell_condition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// Adding background color to highlight buy and sell zones
bgcolor(buy_condition ? color.new(color.green, 90) : na, title="Buy Background Highlight")
bgcolor(sell_condition ? color.new(color.red, 90) : na, title="Sell Background Highlight")
Explanation:
Input Parameters:

ema20_length and ema50_length to set the lengths for the EMAs.
rsi_length for the length of the RSI calculation.
rsi_overbought and rsi_oversold to set the levels for overbought and oversold conditions respectively.
Calculations:

ema20 and ema50 are calculated using ta.ema.
rsi is calculated using ta.rsi.
Conditions:

buy_condition checks for the crossover of ema20 above ema50 and that the RSI is below the overbought threshold.
sell_condition checks for the crossover of ema20 below ema50 and that the RSI is above the oversold threshold.
Plotting:

The EMAs are plotted on the chart.
Buy and sell signals are plotted using plotshape.
Background colors are added to highlight the buy and sell zones for better visual interpretation.
开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?