本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rahul304
//@version=6
indicator("Vealth1st - 2X Opposite Candle Alert", overlay=true)
// Settings
bodyMultiplier = input.float(2.0, "Required Body Multiplier", minval=1.0, step=0.5)
// Calculate candle body sizes
previousBody = math.abs(close[1] - open[1])
currentBody = math.abs(close - open)
// Candle colors
previousGreen = close[1] > open[1]
previousRed = close[1] < open[1]
currentGreen = close > open
currentRed = close < open
// Current body must be at least 2x previous body
bodyIsLargeEnough = currentBody >= previousBody * bodyMultiplier
// Signals confirmed at candle close
buySignal = previousRed and currentGreen and bodyIsLargeEnough and barstate.isconfirmed
sellSignal = previousGreen and currentRed and bodyIsLargeEnough and barstate.isconfirmed
// Display BUY / SELL labels
plotshape(buySignal, title="BUY Signal", style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", textcolor=color.white, size=size.small)
plotshape(sellSignal, title="SELL Signal", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white, size=size.small)
// Alert conditions
alertcondition(buySignal, title="BUY Alert - 2X Body", message="BUY: Green candle body is at least 2x previous red candle body on {{ticker}} {{interval}}. Close: {{close}}")
alertcondition(sellSignal, title="SELL Alert - 2X Body", message="SELL: Red candle body is at least 2x previous green candle body on {{ticker}} {{interval}}. Close: {{close}}")