Thomas Trend Cloud Pro

Thomas-Sterling · study · 187 行 · 点赞 244 · 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/
// © Thomas-Sterling
 
 
 //@version=6
indicator("Thomas Trend Cloud Pro", overlay=true, max_lines_count=30, max_labels_count=150, max_boxes_count=20)
 
//━━━━━━━━━━ SETTINGS ━━━━━━━━━━
emaLen       = input.int(20, "Cloud Length", minval=2)
atrLen       = input.int(10, "ATR Length", minval=2)
atrFactor    = input.float(2.5, "Trend Sensitivity", minval=0.5, step=0.1)
pipSize      = input.float(0.1, "Pip Size (Broker Dependent)", minval=0.00001)
tpGapPips    = input.int(300, "TP1 to TP2 Gap (Pips)", minval=1)
tp1ATR       = input.float(1.5, "TP1 Distance (ATR)", minval=0.1, step=0.1)
rightBars    = input.int(12, "Right Label Distance", minval=2, maxval=100)
swingLen     = input.int(5, "Pattern Swing Length", minval=2)
tolerance    = input.float(0.3, "Double Pattern Tolerance (%)", minval=0.05, step=0.05)
 
showPatterns  = input.bool(true, "Double Top / Bottom Circles")
showStructure = input.bool(true, "Show BOS / CHoCH")
showFVG       = input.bool(true, "Show FVG Zones")
maxFVG        = input.int(3, "Maximum FVG Zones", minval=1, maxval=10)
showDashboard = input.bool(true, "Show Dashboard")
 
tpGap = tpGapPips * pipSize
 
//━━━━━━━━━━ TREND CLOUD ━━━━━━━━━━
atr = ta.atr(atrLen)
[supertrend, stDirection] = ta.supertrend(atrFactor, atrLen)
 
bullTrend = stDirection < 0
bearTrend = stDirection > 0
 
basis = ta.ema(close, emaLen)
upperCloud = basis + atr * 0.8
lowerCloud = basis - atr * 0.8
 
pUpper = plot(upperCloud, "Cloud Upper", color=color.new(color.gray, 80))
pLower = plot(lowerCloud, "Cloud Lower", color=color.new(color.gray, 80))
fill(pUpper, pLower, color=color.new(color.gray, 82), title="Trend Cloud")
plot(basis, "Cloud Midline", color=color.new(color.gray, 65), linewidth=1)
 
//━━━━━━━━━━ BUY / SELL TRIANGLES ━━━━━━━━━━
buySignal = bullTrend and bearTrend[1]
sellSignal = bearTrend and bullTrend[1]
 
plotshape(buySignal, title="BUY", style=shape.triangleup, location=location.belowbar, color=color.rgb(25, 180, 145), size=size.small)
plotshape(sellSignal, title="SELL", style=shape.triangledown, location=location.abovebar, color=color.rgb(190, 135, 45), size=size.small)
 
//━━━━━━━━━━ DOUBLE TOP / BOTTOM ━━━━━━━━━━
pivotH = ta.pivothigh(high, swingLen, swingLen)
pivotL = ta.pivotlow(low, swingLen, swingLen)
 
var float previousHigh = na
var int previousHighBar = na
var float previousLow = na
var int previousLowBar = na
 
if not na(pivotH)
    currentHighBar = bar_index - swingLen
    if showPatterns and not na(previousHigh) and math.abs(pivotH - previousHigh) / math.max(math.abs(previousHigh), syminfo.mintick) * 100 <= tolerance
        label.new(previousHighBar, previousHigh, "●", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_none, textcolor=color.red, size=size.large)
        label.new(currentHighBar, pivotH, "●", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_none, textcolor=color.red, size=size.large)
    previousHigh := pivotH
    previousHighBar := currentHighBar
 
if not na(pivotL)
    currentLowBar = bar_index - swingLen
    if showPatterns and not na(previousLow) and math.abs(pivotL - previousLow) / math.max(math.abs(previousLow), syminfo.mintick) * 100 <= tolerance
        label.new(previousLowBar, previousLow, "●", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_none, textcolor=color.rgb(25, 180, 145), size=size.large)
        label.new(currentLowBar, pivotL, "●", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_none, textcolor=color.rgb(25, 180, 145), size=size.large)
    previousLow := pivotL
    previousLowBar := currentLowBar
 
//━━━━━━━━━━ BOS / CHoCH ━━━━━━━━━━
var float structureHigh = na
var float structureLow = na
var int marketTrend = 0
 
if not na(pivotH)
    structureHigh := pivotH
if not na(pivotL)
    structureLow := pivotL
 
bullBreak = not na(structureHigh) and ta.crossover(close, structureHigh)
bearBreak = not na(structureLow) and ta.crossunder(close, structureLow)
 
bullCHoCH = bullBreak and marketTrend == -1
bearCHoCH = bearBreak and marketTrend == 1
 
if bullBreak
    if showStructure
        label.new(bar_index, low, bullCHoCH ? "CHoCH ↑" : "BOS ↑", style=label.style_label_up, color=bullCHoCH ? color.blue : color.green, textcolor=color.white, size=size.tiny)
    marketTrend := 1
 
if bearBreak
    if showStructure
        label.new(bar_index, high, bearCHoCH ? "CHoCH ↓" : "BOS ↓", style=label.style_label_down, color=bearCHoCH ? color.blue : color.red, textcolor=color.white, size=size.tiny)
    marketTrend := -1
 
//━━━━━━━━━━ FAIR VALUE GAPS ━━━━━━━━━━
var box[] fvgBoxes = array.new_box()
 
bullishFVG = low > high[2]
bearishFVG = high < low[2]
 
if showFVG and bullishFVG
    newBullFVG = box.new(left=bar_index - 2, top=low, right=bar_index + 1, bottom=high[2], xloc=xloc.bar_index, extend=extend.right, bgcolor=color.new(color.teal, 88), border_color=color.new(color.teal, 65))
    array.push(fvgBoxes, newBullFVG)
 
if showFVG and bearishFVG
    newBearFVG = box.new(left=bar_index - 2, top=low[2], right=bar_index + 1, bottom=high, xloc=xloc.bar_index, extend=extend.right, bgcolor=color.new(color.red, 90), border_color=color.new(color.red, 70))
    array.push(fvgBoxes, newBearFVG)
 
while array.size(fvgBoxes) > maxFVG
    oldFVG = array.shift(fvgBoxes)
    box.delete(oldFVG)
 
//━━━━━━━━━━ ENTRY / TP1 / TP2 — NO SL ━━━━━━━━━━
var float entryPrice = na
var float tp1Price = na
var float tp2Price = na
var string lastSignal = "WAIT"
 
var line entryLine = na
var line tp1Line = na
var line tp2Line = na
var linefill targetFill = na
 
var label entryLabel = na
var label tp1Label = na
var label tp2Label = na
 
if buySignal or sellSignal
    if not na(entryLine)
        line.delete(entryLine)
    if not na(tp1Line)
        line.delete(tp1Line)
    if not na(tp2Line)
        line.delete(tp2Line)
    if not na(targetFill)
        linefill.delete(targetFill)
    if not na(entryLabel)
        label.delete(entryLabel)
    if not na(tp1Label)
        label.delete(tp1Label)
    if not na(tp2Label)
        label.delete(tp2Label)
 
    isBuy = buySignal
    entryPrice := close
    lastSignal := isBuy ? "BUY" : "SELL"
 
    tp1Distance = math.max(atr * tp1ATR, syminfo.mintick)
    tp1Price := isBuy ? entryPrice + tp1Distance : entryPrice - tp1Distance
    tp2Price := isBuy ? tp1Price + tpGap : tp1Price - tpGap
 
    entryLine := line.new(bar_index, entryPrice, bar_index + rightBars, entryPrice, color=color.blue, width=2)
    tp1Line := line.new(bar_index, tp1Price, bar_index + rightBars, tp1Price, color=color.rgb(25, 180, 145), width=1)
    tp2Line := line.new(bar_index, tp2Price, bar_index + rightBars, tp2Price, color=color.rgb(25, 180, 145), width=1)
    targetFill := linefill.new(tp1Line, tp2Line, color.new(color.teal, 90))
 
    entryLabel := label.new(bar_index + rightBars, entryPrice, (isBuy ? "BUY ENTRY: " : "SELL ENTRY: ") + str.tostring(entryPrice, format.mintick), style=label.style_label_left, color=color.blue, textcolor=color.white, size=size.small)
    tp1Label := label.new(bar_index + rightBars, tp1Price, "TP1: " + str.tostring(tp1Price, format.mintick), style=label.style_label_left, color=color.rgb(25, 180, 145), textcolor=color.white, size=size.small)
    tp2Label := label.new(bar_index + rightBars, tp2Price, "TP2: " + str.tostring(tp2Price, format.mintick), style=label.style_label_left, color=color.rgb(25, 180, 145), textcolor=color.white, size=size.small)
 
//━━━━━━━━━━ DASHBOARD ━━━━━━━━━━
var table dash = table.new(position.top_right, 2, 4, border_width=1)
 
if barstate.islast
    if showDashboard
        table.cell(dash, 0, 0, "THOMAS CLOUD", bgcolor=color.rgb(35, 40, 48), text_color=color.white)
        table.cell(dash, 1, 0, "PRO", bgcolor=color.rgb(35, 40, 48), text_color=color.rgb(25, 180, 145))
        table.cell(dash, 0, 1, "Trend", bgcolor=color.new(color.gray, 30), text_color=color.white)
        table.cell(dash, 1, 1, bullTrend ? "BULLISH" : "BEARISH", bgcolor=bullTrend ? color.rgb(25, 145, 110) : color.rgb(190, 65, 65), text_color=color.white)
        table.cell(dash, 0, 2, "Last Signal", bgcolor=color.new(color.gray, 30), text_color=color.white)
        table.cell(dash, 1, 2, lastSignal, bgcolor=lastSignal == "BUY" ? color.green : lastSignal == "SELL" ? color.red : color.gray, text_color=color.white)
        table.cell(dash, 0, 3, "TP Gap", bgcolor=color.new(color.gray, 30), text_color=color.white)
        table.cell(dash, 1, 3, str.tostring(tpGapPips) + " pips", bgcolor=color.rgb(35, 40, 48), text_color=color.rgb(25, 180, 145))
    else
        table.clear(dash, 0, 0, 1, 3)
 
//━━━━━━━━━━ ALERTS ━━━━━━━━━━
alertcondition(buySignal, title="BUY Signal", message="Thomas Trend Cloud Pro: BUY")
alertcondition(sellSignal, title="SELL Signal", message="Thomas Trend Cloud Pro: SELL")
alertcondition(bullBreak, title="Bullish BOS / CHoCH", message="Thomas Trend Cloud Pro: Bullish structure break")
alertcondition(bearBreak, title="Bearish BOS / CHoCH", message="Thomas Trend Cloud Pro: Bearish structure break")

← 返回列表