MACD + Stochastic + RSI by X001TK

x001tk · strategy · 58 行 · 点赞 1,962 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=2
strategy("MACD + Stochastic + RSI by X001TK", shorttitle="MACD_Stoch_RSI_Strat", overlay=true)
 
// X001TK MACD + Stochastic + RSI Strategy
//
// 
// This strategy combines the special approach in stochastic and rsi
// strategy to buy once stochastic and rsi closes above center line "50" level 
// with a MACD strategy to buy when the MACD value goes above Signal line.
//
//
// This strategy goes long if the MACD goes above Signal and stochastic 
// goes above 50 level and rsi goes above 50 level.
//
// This pure strategy does not have any
// stop loss or take profit money management logic.
//
// Exit rule is simple. We close the position once MACD goes below Signal line
//
// 
// 
//
// Input
fastMAlen = input(12, minval=1, title="MACD fast moving average")
slowMAlen=input(26,minval=1, title="MACD slow moving average")
signalMACDlen = input(9,minval=1, title="MACD signal line moving average")
StochLength = input(14, minval=1, title="Stochastic Length")
switch=input(true, title="Enable MACD Bar Color?")
 
// MACD Calculation
MACD = ema(close, fastMAlen) - ema(close, slowMAlen)
signalMACD = ema(MACD, signalMACDlen)
delta = MACD - signalMACD
fastMA = ema(close,fastMAlen)
slowMA = ema(close,slowMAlen)
 
// Stochastic Calculation
smoothK = input(3, title="Smoothing of Stochastic %K ")
smoothD = input(3, title="Moving Average of Stochastic %K")
k = sma(stoch(close, high, low, StochLength), smoothK)
d = sma(k, smoothD)
 
//RSI Calculation
xRSI = rsi(close, 14)
 
// Colors
bartrendcolor = MACD > signalMACD and k > 50 and xRSI > 50? green : MACD < signalMACD and k < 50 and xRSI < 50? red : MACD < signalMACD? yellow : gray   
barcolor(switch?bartrendcolor:na)
 
// === STRATEGY ===
// conditions
longCond = MACD > signalMACD and k > 50 and xRSI > 50
shortCond = MACD < signalMACD 
 
strategy.entry("long", strategy.long,  when=longCond==true)
strategy.close("long", when=shortCond==true)
 
// === /STRATEGY ===

← 返回列表