duongphuoc - Sonic R EMA & Price Action Channel

thieunamgiang92 · study · 291 行 · 点赞 17 · TradingView 原页

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

Pine Script

//@version=6
indicator(
     title = "duongphuoc - Sonic R EMA & Price Action Channel",
     shorttitle = "duongphuoc - Sonic R & PAC",
     overlay = true
)
 
//====================================================
// TREND EMA
//====================================================
 
trendEMAPeriod = input.int(
     63,
     title = "Trend EMA Period",
     minval = 1,
     group = "Trend EMA"
)
 
showTrendEMA = input.bool(
     true,
     title = "Show Trend EMA",
     group = "Trend EMA"
)
 
trendEMAColor = input.color(
     #B20003,
     title = "Trend EMA Color",
     group = "Trend EMA"
)
 
//====================================================
// PRICE ACTION CHANNEL
//====================================================
 
priceActionChannelPeriod = input.int(
     32,
     title = "Price Action Channel Period",
     minval = 2,
     group = "Price Action Channel"
)
 
showPriceActionChannel = input.bool(
     true,
     title = "Show Price Action Channel",
     group = "Price Action Channel"
)
 
priceActionChannelCloseColor = input.color(
     #11FF14,
     title = "Close EMA Color",
     group = "Price Action Channel"
)
 
priceActionChannelEdgeColor = input.color(
     color.new(#149454, 50),
     title = "High / Low EMA Color",
     group = "Price Action Channel"
)
 
priceActionChannelFillColor = input.color(
     color.new(#27FFEA, 90),
     title = "Fill Color",
     group = "Price Action Channel"
)
 
//====================================================
// WAVE CROSS
//====================================================
 
showWaveCross = input.bool(
     true,
     title = "Show Wave Cross",
     group = "Wave Cross"
)
 
//====================================================
// MARKERS
//====================================================
 
markerDistanceATR = input.float(
     0.35,
     title = "Marker Distance (ATR)",
     minval = 0.0,
     step = 0.05,
     group = "Markers"
)
 
bullishMarkerColor = input.color(
     color.lime,
     title = "Bullish Marker Color",
     group = "Markers"
)
 
bearishMarkerColor = input.color(
     color.red,
     title = "Bearish Marker Color",
     group = "Markers"
)
 
//====================================================
// LABELS
//====================================================
 
showLabels = input.bool(
     true,
     title = "Show EMA Labels",
     group = "Labels"
)
 
//====================================================
// CALCULATIONS
//====================================================
 
trendEMA = ta.ema(close, trendEMAPeriod)
 
priceActionChannelHigh = ta.ema(high, priceActionChannelPeriod)
priceActionChannelClose = ta.ema(close, priceActionChannelPeriod)
priceActionChannelLow = ta.ema(low, priceActionChannelPeriod)
 
atr = ta.atr(14)
 
//====================================================
// PLOTS
//====================================================
 
plot(
     showTrendEMA ? trendEMA : na,
     title = "Trend EMA",
     linewidth = 2,
     color = trendEMAColor
)
 
priceActionChannelHighPlot = plot(
     showPriceActionChannel ? priceActionChannelHigh : na,
     title = "Price Action Channel High EMA",
     linewidth = 1,
     color = priceActionChannelEdgeColor
)
 
plot(
     showPriceActionChannel ? priceActionChannelClose : na,
     title = "Price Action Channel Close EMA",
     linewidth = 2,
     color = priceActionChannelCloseColor
)
 
priceActionChannelLowPlot = plot(
     showPriceActionChannel ? priceActionChannelLow : na,
     title = "Price Action Channel Low EMA",
     linewidth = 1,
     color = priceActionChannelEdgeColor
)
 
fill(
     priceActionChannelHighPlot,
     priceActionChannelLowPlot,
     color = showPriceActionChannel ? priceActionChannelFillColor : na,
     title = "Price Action Channel Fill"
)
 
//====================================================
// WAVE CROSS LOGIC
//====================================================
 
belowChannel = close < priceActionChannelLow
aboveChannel = close > priceActionChannelHigh
 
//  1 = waiting for bullish completion
// -1 = waiting for bearish completion
//  0 = no active wave
var int waveState = 0
 
bool bullishWaveCross = false
bool bearishWaveCross = false
 
// Start bullish wave
if waveState == 0 and belowChannel
    waveState := 1
 
// Start bearish wave
else if waveState == 0 and aboveChannel
    waveState := -1
 
// Bullish completion
if waveState == 1
    if close > priceActionChannelHigh and close > trendEMA
        bullishWaveCross := true
        waveState := 0
 
// Bearish completion
if waveState == -1
    if close < priceActionChannelLow and close < trendEMA
        bearishWaveCross := true
        waveState := 0
 
//====================================================
// MARKER POSITIONS
//====================================================
 
bullishMarkerY = low - atr * markerDistanceATR
bearishMarkerY = high + atr * markerDistanceATR
 
plotshape(
     showWaveCross and bullishWaveCross ? bullishMarkerY : na,
     title = "Bullish Wave Cross",
     style = shape.triangleup,
     location = location.absolute,
     size = size.tiny,
     color = bullishMarkerColor
)
 
plotshape(
     showWaveCross and bearishWaveCross ? bearishMarkerY : na,
     title = "Bearish Wave Cross",
     style = shape.triangledown,
     location = location.absolute,
     size = size.tiny,
     color = bearishMarkerColor
)
 
//====================================================
// LABELS
//====================================================
 
var label trendLabel = na
var label priceActionChannelLabel = na
 
if barstate.islast
 
    if showLabels and showTrendEMA
        if na(trendLabel)
            trendLabel := label.new(
                 bar_index,
                 trendEMA,
                 "",
                 style = label.style_label_left,
                 color = color.new(color.black, 100),
                 textcolor = trendEMAColor
            )
 
        label.set_xy(
             trendLabel,
             bar_index,
             trendEMA
        )
 
        label.set_text(
             trendLabel,
             "EMA " + str.tostring(trendEMAPeriod)
        )
 
        label.set_textcolor(
             trendLabel,
             trendEMAColor
        )
 
    else if not na(trendLabel)
        label.delete(trendLabel)
        trendLabel := na
 
    if showLabels and showPriceActionChannel
        if na(priceActionChannelLabel)
            priceActionChannelLabel := label.new(
                 bar_index,
                 priceActionChannelClose,
                 "",
                 style = label.style_label_left,
                 color = color.new(color.black, 100),
                 textcolor = priceActionChannelCloseColor
            )
 
        label.set_xy(
             priceActionChannelLabel,
             bar_index,
             priceActionChannelClose
        )
 
        label.set_text(
             priceActionChannelLabel,
             "Price Action Channel " +
             str.tostring(priceActionChannelPeriod)
        )
 
        label.set_textcolor(
             priceActionChannelLabel,
             priceActionChannelCloseColor
        )
 
    else if not na(priceActionChannelLabel)
        label.delete(priceActionChannelLabel)
        priceActionChannelLabel := na

← 返回列表