搜索
产品
社区
市场
新闻
经纪商
更多
CN
开始
社区
/
指标和策略
/
Advanced Strategy: Buy and Sell
OPEN-SOURCE SCRIPT
Advanced Strategy: Buy and Sell
由spiritedMaster88189提供
关注
关注
前天
3
添加到收藏
添加到收藏
前天
//
version
=5
indicator("Advanced Strategy: Buy and Sell", overlay=true)
// User Inputs
ema_fast_length = input.int(12, title="EMA Fast Period")
ema_slow_length = input.int(26, title="EMA Slow Period")
rsi_period = input.int(14, title="RSI Period")
macd_fast = input.int(12, title="MACD Fast Period")
macd_slow = input.int(26, title="MACD Slow Period")
macd_signal = input.int(9, title="MACD Signal Period")
bb_length = input.int(20, title="Bollinger Bands Period")
bb_mult = input.float(2.0, title="Bollinger Bands Std Dev")
adx_period = input.int(14, title="ADX Period")
adx_threshold = input.int(20, title="Minimum ADX for Trend Validation")
// Indicator Calculations
ema_fast = ta.ema(close, ema_fast_length)
ema_slow = ta.ema(close, ema_slow_length)
rsi = ta.rsi(close, rsi_period)
[macd_line, signal_line, _] = ta.macd(close, macd_fast, macd_slow, macd_signal)
[bb_upper, bb_middle, bb_lower] = ta.bb(close, bb_length, bb_mult)
// ADX Calculation
true_range = ta.rma(ta.tr, adx_period)
plus_dm = ta.rma(ta.change(high) > ta.change(low) ? math.max(ta.change(high), 0) : 0, adx_period)
minus_dm = ta.rma(ta.change(low) > ta.change(high) ? math.max(ta.change(low), 0) : 0, adx_period)
plus_di = (plus_dm / true_range) * 100
minus_di = (minus_dm / true_range) * 100
dx = math.abs(plus_di - minus_di) / (plus_di + minus_di) * 100
adx = ta.rma(dx, adx_period)
// Buy Rules
buy_signal = ta.crossover(ema_fast, ema_slow) and rsi < 50 and macd_line > signal_line and close < bb_lower and adx > adx_threshold
// Sell Rules
sell_signal = ta.crossunder(ema_fast, ema_slow) and rsi > 50 and macd_line < signal_line and close > bb_upper and adx > adx_threshold
// Plot Indicators on the Chart
plot(ema_fast, color=color.green, title="EMA Fast")
plot(ema_slow, color=color.red, title="EMA Slow")
plot(bb_upper, color=color.orange, title="Bollinger Upper Band")
plot(bb_lower, color=color.orange, title="Bollinger Lower Band")
// Buy and Sell Signals
plotshape(buy_signal, style=shape.labelup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(sell_signal, style=shape.labeldown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")
// Alerts
alertcondition(buy_signal, title="Buy Alert", message="Buy Signal Detected!")
alertcondition(sell_signal, title="Sell Alert", message="Sell Signal Detected!")
Breadth Indicators
Candlestick analysis
Chart patterns
开源脚本
本着真正的TradingView精神,此脚本的作者已将其开源,以便交易者可以理解和验证它。向作者致敬!您可以免费使用它,但在出版物中重复使用此代码受
网站规则
约束。 您可以收藏它以在图表上使用。
想在图表上使用此脚本?
添加到收藏
spiritedMaster88189
关注
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在
使用条款
阅读更多信息。