Candle BUY SELL + Support Resistance [v6]

JohnsonForexTrader · study · 134 行 · 点赞 77 · 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/
// © JohnsonForexTrader
 
//@version=6
indicator("Candle BUY SELL + Support Resistance [v6]", shorttitle="Candle S/R", overlay=true)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SETTINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
groupSR = "Support & Resistance"
 
pivotLength = input.int(5, "Pivot Length", minval=2, group=groupSR)
showSupport = input.bool(true, "Show Support", group=groupSR)
showResistance = input.bool(true, "Show Resistance", group=groupSR)
 
groupSignal = "Candle Signals"
 
showSignals = input.bool(true, "Show BUY / SELL", group=groupSignal)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CANDLE DATA
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
body = math.abs(close - open)
candleRange = high - low
 
upperWick = high - math.max(open, close)
lowerWick = math.min(open, close) - low
 
bullish = close > open
bearish = close < open
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CANDLE PATTERNS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
// Bullish Engulfing
bullishEngulfing =
     bullish and
     bearish[1] and
     open <= close[1] and
     close >= open[1]
 
// Bearish Engulfing
bearishEngulfing =
     bearish and
     bullish[1] and
     open >= close[1] and
     close <= open[1]
 
// Hammer
hammer =
     candleRange > 0 and
     lowerWick >= body * 2 and
     upperWick <= body
 
// Shooting Star
shootingStar =
     candleRange > 0 and
     upperWick >= body * 2 and
     lowerWick <= body
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SUPPORT & RESISTANCE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
pivotLow = ta.pivotlow(low, pivotLength, pivotLength)
pivotHigh = ta.pivothigh(high, pivotLength, pivotLength)
 
var float support = na
var float resistance = na
 
if not na(pivotLow)
    support := pivotLow
 
if not na(pivotHigh)
    resistance := pivotHigh
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CANDLE BUY / SELL
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
buySignal = bullishEngulfing or hammer
sellSignal = bearishEngulfing or shootingStar
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// PLOT SUPPORT / RESISTANCE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plot(
     showSupport ? support : na,
     title="Support",
     color=color.green,
     linewidth=2,
     style=plot.style_stepline)
 
plot(
     showResistance ? resistance : na,
     title="Resistance",
     color=color.red,
     linewidth=2,
     style=plot.style_stepline)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CLEAN BUY / SELL
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plotshape(
     showSignals and buySignal,
     title="BUY",
     style=shape.labelup,
     location=location.belowbar,
     color=color.lime,
     text="BUY",
     textcolor=color.black,
     size=size.tiny)
 
plotshape(
     showSignals and sellSignal,
     title="SELL",
     style=shape.labeldown,
     location=location.abovebar,
     color=color.red,
     text="SELL",
     textcolor=color.white,
     size=size.tiny)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(
     buySignal,
     title="Candle BUY",
     message="Candle BUY signal detected.")
 
alertcondition(
     sellSignal,
     title="Candle SELL",
     message="Candle SELL signal detected.")

← 返回列表