Trade Clarity Coach Pro by Mr_David

Mr_Davidd7 · study · 175 行 · 点赞 519 · TradingView 原页

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

Pine Script

//@version=6
indicator("Trade Clarity Coach Pro V2", overlay=true, max_boxes_count=10, max_lines_count=20, max_labels_count=30)
 
// SETTINGS
fastLen = input.int(20, "Fast EMA")
slowLen = input.int(50, "Slow EMA")
rsiLen = input.int(14, "RSI Length")
diLen = input.int(14, "DI Length")
adxSmooth = input.int(14, "ADX Smoothing")
minADX = input.float(18, "Minimum ADX")
atrLen = input.int(14, "ATR Length")
 
slATR = input.float(1.5, "Stop Loss ATR")
tp1RR = input.float(1.0, "TP1 Risk Reward")
tp2RR = input.float(2.0, "TP2 Risk Reward")
extendBars = input.int(20, "Setup Box Width", minval=5, maxval=100)
 
showEMA = input.bool(true, "Show EMAs")
showDashboard = input.bool(true, "Show Dashboard")
 
// INDICATOR CALCULATIONS
fastEMA = ta.ema(close, fastLen)
slowEMA = ta.ema(close, slowLen)
rsi = ta.rsi(close, rsiLen)
atr = ta.atr(atrLen)
 
[plusDI, minusDI, adx] = ta.dmi(diLen, adxSmooth)
 
// TREND DETECTION
bullTrend = fastEMA > slowEMA and close > slowEMA
bearTrend = fastEMA < slowEMA and close < slowEMA
 
marketTrending = adx >= minADX
 
// ENTRY CONDITIONS
bullPullback = low <= fastEMA and close > fastEMA and close[1] <= fastEMA[1]
bearPullback = high >= fastEMA and close < fastEMA and close[1] >= fastEMA[1]
 
bullMomentum = rsi > 50 and rsi < 70 and plusDI > minusDI
bearMomentum = rsi < 50 and rsi > 30 and minusDI > plusDI
 
buySignal = barstate.isconfirmed and bullTrend and marketTrending and bullPullback and bullMomentum
sellSignal = barstate.isconfirmed and bearTrend and marketTrending and bearPullback and bearMomentum
 
// TRADE VARIABLES
var float entry = na
var float stop = na
var float tp1 = na
var float tp2 = na
var int direction = 0
 
// DRAWING OBJECTS
var box profitBox = na
var box riskBox = na
 
var line entryLine = na
var line slLine = na
var line tp1Line = na
var line tp2Line = na
 
var label entryLabel = na
var label slLabel = na
var label tp1Label = na
var label tp2Label = na
 
// FORMAT PRICE
priceText(float p) =>
    str.tostring(p, format.mintick)
 
// DELETE PREVIOUS SETUP
if buySignal or sellSignal
 
    if not na(profitBox)
        box.delete(profitBox)
    if not na(riskBox)
        box.delete(riskBox)
 
    if not na(entryLine)
        line.delete(entryLine)
    if not na(slLine)
        line.delete(slLine)
    if not na(tp1Line)
        line.delete(tp1Line)
    if not na(tp2Line)
        line.delete(tp2Line)
 
    if not na(entryLabel)
        label.delete(entryLabel)
    if not na(slLabel)
        label.delete(slLabel)
    if not na(tp1Label)
        label.delete(tp1Label)
    if not na(tp2Label)
        label.delete(tp2Label)
 
    // CALCULATE LONG SETUP
    if buySignal
        entry := close
        stop := close - atr * slATR
        tp1 := close + (entry - stop) * tp1RR
        tp2 := close + (entry - stop) * tp2RR
        direction := 1
 
    // CALCULATE SHORT SETUP
    if sellSignal
        entry := close
        stop := close + atr * slATR
        tp1 := close - (stop - entry) * tp1RR
        tp2 := close - (stop - entry) * tp2RR
        direction := -1
 
    // BOX COORDINATES
    rightX = bar_index + extendBars
 
    // LONG POSITION
    if direction == 1
        profitBox := box.new(bar_index, tp2, rightX, entry, bgcolor=color.new(color.green, 83), border_color=color.green, border_width=1)
        riskBox := box.new(bar_index, entry, rightX, stop, bgcolor=color.new(color.red, 83), border_color=color.red, border_width=1)
 
    // SHORT POSITION
    if direction == -1
        profitBox := box.new(bar_index, entry, rightX, tp2, bgcolor=color.new(color.green, 83), border_color=color.green, border_width=1)
        riskBox := box.new(bar_index, stop, rightX, entry, bgcolor=color.new(color.red, 83), border_color=color.red, border_width=1)
 
    // PRICE LINES
    entryLine := line.new(bar_index, entry, rightX, entry, color=color.blue, width=2)
    slLine := line.new(bar_index, stop, rightX, stop, color=color.red, width=2)
    tp1Line := line.new(bar_index, tp1, rightX, tp1, color=color.lime, width=1, style=line.style_dashed)
    tp2Line := line.new(bar_index, tp2, rightX, tp2, color=color.green, width=2)
 
    // PRICE LABELS
    entryLabel := label.new(rightX, entry, "ENTRY  " + priceText(entry), style=label.style_label_left, color=color.blue, textcolor=color.white, size=size.small)
    slLabel := label.new(rightX, stop, "STOP LOSS  " + priceText(stop), style=label.style_label_left, color=color.red, textcolor=color.white, size=size.small)
    tp1Label := label.new(rightX, tp1, "TP 1  " + priceText(tp1), style=label.style_label_left, color=color.lime, textcolor=color.black, size=size.small)
    tp2Label := label.new(rightX, tp2, "TP 2  " + priceText(tp2), style=label.style_label_left, color=color.green, textcolor=color.white, size=size.small)
 
// EMAs
plot(showEMA ? fastEMA : na, "Fast EMA", color=color.aqua, linewidth=2)
plot(showEMA ? slowEMA : na, "Slow EMA", color=color.orange, linewidth=2)
 
// BUY SELL SIGNALS
plotshape(buySignal, title="BUY", style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", textcolor=color.white)
plotshape(sellSignal, title="SELL", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white)
 
// DASHBOARD
var table dash = table.new(position.top_right, 2, 5, border_width=1)
 
trendText = bullTrend ? "BULLISH" : bearTrend ? "BEARISH" : "MIXED"
decision = buySignal ? "BUY SETUP" : sellSignal ? "SELL SETUP" : not marketTrending ? "WAIT - SIDEWAYS" : bullTrend ? "BULLISH - WAIT" : bearTrend ? "BEARISH - WAIT" : "NO SETUP"
 
trendColor = bullTrend ? color.green : bearTrend ? color.red : color.gray
decisionColor = buySignal ? color.green : sellSignal ? color.red : color.gray
 
if barstate.islast and showDashboard
    table.cell(dash, 0, 0, "TRADE CLARITY", bgcolor=color.rgb(25,35,55), text_color=color.white)
    table.cell(dash, 1, 0, "COACH PRO", bgcolor=color.rgb(25,35,55), text_color=color.aqua)
 
    table.cell(dash, 0, 1, "Market Trend", bgcolor=color.black, text_color=color.white)
    table.cell(dash, 1, 1, trendText, bgcolor=trendColor, text_color=color.white)
 
    table.cell(dash, 0, 2, "Trade Decision", bgcolor=color.black, text_color=color.white)
    table.cell(dash, 1, 2, decision, bgcolor=decisionColor, text_color=color.white)
 
    table.cell(dash, 0, 3, "RSI", bgcolor=color.black, text_color=color.white)
    table.cell(dash, 1, 3, str.tostring(rsi, "#.0"), text_color=color.white)
 
    table.cell(dash, 0, 4, "ADX", bgcolor=color.black, text_color=color.white)
    table.cell(dash, 1, 4, str.tostring(adx, "#.0"), text_color=color.white)
 
if barstate.islast and not showDashboard
    table.clear(dash, 0, 0, 1, 4)
 
// ALERTS
alertcondition(buySignal, "BUY Setup", "Trade Clarity Coach Pro: BUY setup confirmed")
alertcondition(sellSignal, "SELL Setup", "Trade Clarity Coach Pro: SELL setup confirmed")

← 返回列表