Institutional 1:2 Pip Setup & Accuracy Tracker

PremiumTrader57 · study · 141 行 · 点赞 19 · 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/
// © PremiumTrader57
//@version=6
indicator("Institutional 1:2 Pip Setup & Accuracy Tracker", shorttitle = "1:2 Pip Pro", overlay = true, max_labels_count = 500, max_lines_count = 500)
 
// ======== 1. PIP & RISK PARAMETERS ========
GRP_RISK = "1. Fixed Pip Target & Stop"
pipSize  = input.float(0.0001, "Pip Size (Forex=0.0001, JPY=0.01, Gold=0.1)", step = 0.0001, group = GRP_RISK)
slPips   = input.float(100.0, "Stop Loss (Pips)", minval = 5.0, step = 5.0, group = GRP_RISK)
tpPips   = input.float(200.0, "Take Profit (Pips)", minval = 10.0, step = 10.0, group = GRP_RISK)
onlyLast = input.bool(true, "Show Lines for Latest Setup Only", group = GRP_RISK)
 
// ======== 2. CONFLUENCE FILTERS ========
GRP_FLT  = "2. Institutional Confluence Filters"
emaFast  = input.int(50, "Structure EMA", minval = 10, group = GRP_FLT)
emaSlow  = input.int(200, "Macro Trend EMA", minval = 50, group = GRP_FLT)
adxLen   = input.int(14, "ADX Trend Strength Length", minval = 5, group = GRP_FLT)
adxMin   = input.float(22.0, "Min ADX (Filter Choppy Markets)", minval = 10.0, step = 1.0, group = GRP_FLT)
rsiLen   = input.int(14, "Pullback RSI Length", minval = 5, group = GRP_FLT)
 
// ======== 3. VISUALS & DASHBOARD ========
GRP_VIS  = "3. Visuals & Accuracy HUD"
upCol    = input.color(#089981, "Bullish Color", group = GRP_VIS)
dnCol    = input.color(#F23645, "Bearish Color", group = GRP_VIS)
showEmas = input.bool(true, "Plot 50 & 200 EMAs", group = GRP_VIS)
showHud  = input.bool(true, "Show Live Win-Rate Dashboard", group = GRP_VIS)
 
// ======== CALCULATIONS ========
float e50  = ta.ema(close, emaFast)
float e200 = ta.ema(close, emaSlow)
float rsi  = ta.rsi(close, rsiLen)
[diPlus, diMinus, adx] = ta.dmi(adxLen, adxLen)
 
// Strong Trend + Pullback Rejection Logic (No Repaint)
bool strongTrend = adx >= adxMin
bool bullContext = close > e200 and e50 > e200 and strongTrend
bool bearContext = close < e200 and e50 < e200 and strongTrend
 
// Price pulls back near/below 50 EMA and closes back in trend direction with momentum
bool bullTrigger = bullContext and low <= e50 and close > e50 and close > open and rsi > 45 and rsi < 68
bool bearTrigger = bearContext and high >= e50 and close < e50 and close < open and rsi < 55 and rsi > 32
 
// Prevent consecutive duplicate signals
var int state = 0
bool buySig  = bullTrigger and state != 1 and barstate.isconfirmed
bool sellSig = bearTrigger and state != -1 and barstate.isconfirmed
 
if buySig
    state := 1
if sellSig
    state := -1
 
// ======== TRADE TRACKING & ACCURACY ENGINE ========
var bool  inTrade = false
var int   tDir    = 0
var float entP    = na
var float slP     = na
var float tpP     = na
 
var int   totalTr = 0
var int   wins    = 0
var int   losses  = 0
 
var array<line>  lns = array.new<line>()
var array<label> lbs = array.new<label>()
 
if inTrade
    if tDir == 1
        if low <= slP
            inTrade := false
            losses  += 1
            state   := 0
        else if high >= tpP
            inTrade := false
            wins    += 1
            state   := 0
    else if tDir == -1
        if high >= slP
            inTrade := false
            losses  += 1
            state   := 0
        else if low <= tpP
            inTrade := false
            wins    += 1
            state   := 0
 
if (buySig or sellSig) and not inTrade
    inTrade := true
    tDir    := buySig ? 1 : -1
    entP    := close
    slP     := tDir == 1 ? entP - (slPips * pipSize) : entP + (slPips * pipSize)
    tpP     := tDir == 1 ? entP + (tpPips * pipSize) : entP - (tpPips * pipSize)
    totalTr += 1
 
    if onlyLast
        while array.size(lns) > 0
            line.delete(array.shift(lns))
        while array.size(lbs) > 0
            label.delete(array.shift(lbs))
 
    color sigCol = tDir == 1 ? upCol : dnCol
    label.new(bar_index, tDir == 1 ? low : high, tDir == 1 ? "BUY\n+200p" : "SELL\n+200p",
              yloc = tDir == 1 ? yloc.belowbar : yloc.abovebar,
              style = tDir == 1 ? label.style_label_up : label.style_label_down,
              color = sigCol, textcolor = color.white, size = size.small)
 
    array.push(lns, line.new(bar_index, entP, bar_index + 25, entP, color = #2962FF, width = 1, style = line.style_solid))
    array.push(lns, line.new(bar_index, tpP, bar_index + 25, tpP, color = upCol, width = 2, style = line.style_dotted))
    array.push(lns, line.new(bar_index, slP, bar_index + 25, slP, color = dnCol, width = 2, style = line.style_dashed))
 
    array.push(lbs, label.new(bar_index + 25, tpP, "TP (" + str.tostring(tpPips, "#") + "p): " + str.tostring(tpP, format.mintick), style = label.style_label_left, color = upCol, textcolor = color.white, size = size.tiny))
    array.push(lbs, label.new(bar_index + 25, slP, "SL (" + str.tostring(slPips, "#") + "p): " + str.tostring(slP, format.mintick), style = label.style_label_left, color = dnCol, textcolor = color.white, size = size.tiny))
 
// ======== PLOTS & DASHBOARD ========
plot(showEmas ? e50 : na, "50 EMA", color = color.new(#2962FF, 25), linewidth = 1)
plot(showEmas ? e200 : na, "200 EMA", color = color.new(#FF9800, 15), linewidth = 2)
 
var table hud = table.new(position.bottom_right, 2, 5, bgcolor = color.new(#131722, 10), border_color = #363A45, border_width = 1)
 
if showHud and barstate.islast
    int closedTr  = wins + losses
    float winRate = closedTr > 0 ? (float(wins) / float(closedTr)) * 100.0 : 0.0
    color wrCol   = winRate >= 60.0 ? upCol : winRate >= 45.0 ? #FF9800 : dnCol
 
    table.cell(hud, 0, 0, "1:2 PIP SETUP STATS", text_color = color.white, bgcolor = #1E222D, text_size = size.small)
    table.merge_cells(hud, 0, 0, 1, 0)
 
    table.cell(hud, 0, 1, "Target / Stop", text_color = #94A3B8, text_size = size.small)
    table.cell(hud, 1, 1, str.tostring(tpPips, "#") + " / " + str.tostring(slPips, "#") + " Pips", text_color = color.white, text_size = size.small)
 
    table.cell(hud, 0, 2, "Closed Trades", text_color = #94A3B8, text_size = size.small)
    table.cell(hud, 1, 2, str.tostring(closedTr) + " (" + str.tostring(wins) + "W / " + str.tostring(losses) + "L)", text_color = color.white, text_size = size.small)
 
    table.cell(hud, 0, 3, "Actual Win Rate", text_color = #94A3B8, text_size = size.small)
    table.cell(hud, 1, 3, closedTr > 0 ? str.tostring(winRate, "#.#") + "%" : "Waiting...", text_color = wrCol, text_size = size.small)
 
    table.cell(hud, 0, 4, "Current Status", text_color = #94A3B8, text_size = size.small)
    table.cell(hud, 1, 4, inTrade ? (tDir == 1 ? "LONG OPEN" : "SHORT OPEN") : "SCANNING", text_color = inTrade ? (tDir == 1 ? upCol : dnCol) : #94A3B8, text_size = size.small)
 
alertcondition(buySig,  "1:2 Buy Setup",  "1:2 Pip Pro: BUY Signal on {{ticker}}")
alertcondition(sellSig, "1:2 Sell Setup", "1:2 Pip Pro: SELL Signal on {{ticker}}")

← 返回列表