Morning Star & Evening Star - Pullback Confirmation System

Quants_HK · study · 166 行 · 点赞 22 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Quants_HK
 
//@version=6
indicator(" Morning Star & Evening Star - Pullback Confirmation System", shorttitle="N7 Star Confirmation", overlay=true)
 
groupDisplay = "01 - Display Settings"
groupColors = "02 - Color Settings"
groupPanel = "03 - Status Dashboard"
 
showPatterns = input.bool(true, "Show Morning / Evening Star", group=groupDisplay)
showReferences = input.bool(true, "Show Reference Candles", group=groupDisplay)
showSignals = input.bool(true, "Show BUY / SELL Signals", group=groupDisplay)
showLevels = input.bool(true, "Show Reference Price Levels", group=groupDisplay)
 
morningColor = input.color(color.aqua, "Morning Star Color", group=groupColors)
eveningColor = input.color(color.orange, "Evening Star Color", group=groupColors)
referenceColor = input.color(color.yellow, "Reference Candle Color", group=groupColors)
buyColor = input.color(color.lime, "BUY Signal Color", group=groupColors)
sellColor = input.color(color.red, "SELL Signal Color", group=groupColors)
buyLevelColor = input.color(color.lime, "BUY Reference Level", group=groupColors)
sellLevelColor = input.color(color.red, "SELL Reference Level", group=groupColors)
 
showDashboard = input.bool(true, "Enable Status Dashboard", group=groupPanel)
 
firstOpen = open[2]
firstClose = close[2]
 
secondOpen = open[1]
secondClose = close[1]
 
thirdOpen = open
thirdClose = close
 
firstBody = math.abs(firstClose - firstOpen)
secondBody = math.abs(secondClose - secondOpen)
firstMidpoint = (firstOpen + firstClose) / 2
 
firstBearish = firstClose < firstOpen
firstBullish = firstClose > firstOpen
secondSmallBody = secondBody < firstBody * 0.5
thirdBullish = thirdClose > thirdOpen
thirdBearish = thirdClose < thirdOpen
thirdAboveMidpoint = thirdClose > firstMidpoint
thirdBelowMidpoint = thirdClose < firstMidpoint
 
bear1 = firstBearish
small2 = secondSmallBody
bull3 = thirdBullish
recover3 = thirdAboveMidpoint
 
morningStar = bear1 and small2 and bull3 and recover3
 
bull1 = firstBullish
smallEvening2 = secondSmallBody
bear3 = thirdBearish
decline3 = thirdBelowMidpoint
 
eveningStar = bull1 and smallEvening2 and bear3 and decline3
 
var int longState = 0
var int shortState = 0
 
var float longRefHigh = na
var float shortRefLow = na
 
var int longStarBar = na
var int shortStarBar = na
 
var int longRefBar = na
var int shortRefBar = na
 
bool buySignal = false
bool sellSignal = false
bool longReference = false
bool shortReference = false
 
if barstate.isconfirmed
 
    if morningStar
        longState := 1
        longRefHigh := na
        longStarBar := bar_index
        longRefBar := na
 
    if eveningStar
        shortState := 1
        shortRefLow := na
        shortStarBar := bar_index
        shortRefBar := na
 
    if longState == 1 and bar_index > longStarBar
        if close < open and low < low[1]
            longRefHigh := high
            longRefBar := bar_index
            longState := 2
            longReference := true
 
    if shortState == 1 and bar_index > shortStarBar
        if close > open and high > high[1]
            shortRefLow := low
            shortRefBar := bar_index
            shortState := 2
            shortReference := true
 
    if longState == 2 and bar_index > longRefBar
        if high > longRefHigh
            buySignal := true
            longState := 0
            longRefHigh := na
            longRefBar := na
 
    if shortState == 2 and bar_index > shortRefBar
        if low < shortRefLow
            sellSignal := true
            shortState := 0
            shortRefLow := na
            shortRefBar := na
 
plotshape(showPatterns and morningStar, title="Morning Star", style=shape.circle, location=location.belowbar, color=morningColor, size=size.tiny)
plotshape(showPatterns and eveningStar, title="Evening Star", style=shape.circle, location=location.abovebar, color=eveningColor, size=size.tiny)
 
plotshape(showReferences and longReference, title="BUY Reference", style=shape.diamond, location=location.belowbar, color=referenceColor, size=size.tiny)
plotshape(showReferences and shortReference, title="SELL Reference", style=shape.diamond, location=location.abovebar, color=referenceColor, size=size.tiny)
 
plotshape(showSignals and buySignal, title="BUY Signal", style=shape.labelup, location=location.belowbar, color=buyColor, text="BUY", textcolor=color.black, size=size.small)
plotshape(showSignals and sellSignal, title="SELL Signal", style=shape.labeldown, location=location.abovebar, color=sellColor, text="SELL", textcolor=color.white, size=size.small)
 
activeLongLevel = longState == 2 ? longRefHigh : na
activeShortLevel = shortState == 2 ? shortRefLow : na
 
plot(showLevels ? activeLongLevel : na, title="BUY Reference High", color=buyLevelColor, linewidth=1, style=plot.style_linebr)
plot(showLevels ? activeShortLevel : na, title="SELL Reference Low", color=sellLevelColor, linewidth=1, style=plot.style_linebr)
 
var table statusPanel = table.new(position.top_right, 2, 5, bgcolor=color.new(color.black, 10), border_width=1, border_color=color.new(color.gray, 60))
 
longStatusText = longState == 0 ? "INACTIVE" : longState == 1 ? "WAITING REF" : "WAITING BREAK"
shortStatusText = shortState == 0 ? "INACTIVE" : shortState == 1 ? "WAITING REF" : "WAITING BREAK"
 
longPriceText = longState == 2 ? str.tostring(longRefHigh, format.mintick) : "--"
shortPriceText = shortState == 2 ? str.tostring(shortRefLow, format.mintick) : "--"
 
panelHeaderColor = color.rgb(18, 39, 65)
panelTextColor = color.white
panelMutedColor = color.rgb(190, 200, 215)
panelBuyColor = color.rgb(40, 185, 120)
panelSellColor = color.rgb(235, 80, 80)
 
if barstate.islast and showDashboard
    table.cell(statusPanel, 0, 0, "", text_color=color.white, bgcolor=panelHeaderColor, text_size=size.small)
    table.cell(statusPanel, 1, 0, "CONFIRMATION", text_color=color.white, bgcolor=panelHeaderColor, text_size=size.small)
 
    table.cell(statusPanel, 0, 1, "LONG STATE", text_color=panelMutedColor, text_size=size.tiny)
    table.cell(statusPanel, 1, 1, longStatusText, text_color=panelBuyColor, text_size=size.tiny)
 
    table.cell(statusPanel, 0, 2, "LONG REF", text_color=panelMutedColor, text_size=size.tiny)
    table.cell(statusPanel, 1, 2, longPriceText, text_color=panelTextColor, text_size=size.tiny)
 
    table.cell(statusPanel, 0, 3, "SHORT STATE", text_color=panelMutedColor, text_size=size.tiny)
    table.cell(statusPanel, 1, 3, shortStatusText, text_color=panelSellColor, text_size=size.tiny)
 
    table.cell(statusPanel, 0, 4, "SHORT REF", text_color=panelMutedColor, text_size=size.tiny)
    table.cell(statusPanel, 1, 4, shortPriceText, text_color=panelTextColor, text_size=size.tiny)
 
alertcondition(buySignal, title="BUY Alert", message="Morning Star Pullback BUY")
alertcondition(sellSignal, title="SELL Alert", message="Evening Star Pullback SELL")

← 返回列表