本页源码来自 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/
// © MonicaPropTraderz
//@version=6
// © MonicaPropTraderz
// | PropTraderz — original implementation (rewritten from scratch, October 2026).
// Building blocks are standard, public-domain techniques: ATR volatility stop, EMA, RSI, ADX/DMI, MACD.
indicator("Prop Algo | PropTraderz", shorttitle = "PTZ Algo", overlay = true, max_labels_count = 500, max_lines_count = 500, max_bars_back = 1000)
// ════════════════════════════════════════════════════════════════════
// INPUTS
// ════════════════════════════════════════════════════════════════════
G_SIG = "Signals"
G_AST = "Trading Assistants"
G_RM = "Risk Management"
G_DSH = "Dashboard"
showSignals = input.bool(true, "Show Signals", group = G_SIG)
sens = input.float(2.4, "Sensitivity (ATR multiplier)", minval = 0.5, maxval = 10.0, step = 0.1, group = G_SIG, tooltip = "Lower = more signals, higher = fewer and stronger signals.")
sigLen = input.int(10, "Signal Length", minval = 2, maxval = 50, group = G_SIG)
mode = input.string("Trending", "Signal Mode / Filter", options = ["All Signals", "Trending", "Contrarian", "High Volume", "Strong", "Cloud: Swing", "Cloud: Smooth", "Cloud: Scalping"], group = G_SIG)
strongLen = input.int(200, "Strong Signal EMA", minval = 20, group = G_SIG)
compact = input.bool(true, "Compact Labels (arrows)", group = G_SIG)
showCloud = input.bool(true, "Trend Cloud", group = G_AST, inline = "cl")
cloudFast = input.int(50, "Fast", minval = 5, group = G_AST, inline = "cl")
cloudSlow = input.int(200, "Slow", minval = 10, group = G_AST, inline = "cl")
showRibbon = input.bool(false, "Scalp Ribbon (8/13/21)", group = G_AST)
showDots = input.bool(true, "Reversal Dots", group = G_AST, inline = "rd")
dotLen = input.int(14, "Length", minval = 5, group = G_AST, inline = "rd")
colorBars = input.bool(true, "Momentum Candle Colors", group = G_AST)
showStruct = input.bool(false, "Market Structure (HH/HL/LH/LL)", group = G_AST, inline = "ms")
structLen = input.int(10, "Pivot", minval = 2, group = G_AST, inline = "ms")
bullCol = input.color(#26a65b, "Bull", group = G_AST, inline = "col")
bearCol = input.color(#d64545, "Bear", group = G_AST, inline = "col")
showTPSL = input.bool(true, "Show Entry / SL / TP Levels", group = G_RM)
slMult = input.float(2.0, "Stop Loss (ATR x)", minval = 0.1, step = 0.1, group = G_RM)
tp1R = input.float(1.0, "TP 1 (R)", minval = 0.0, step = 0.25, group = G_RM, inline = "tp")
tp2R = input.float(2.0, "TP 2 (R)", minval = 0.0, step = 0.25, group = G_RM, inline = "tp")
tp3R = input.float(3.0, "TP 3 (R)", minval = 0.0, step = 0.25, group = G_RM, inline = "tp")
showTrail = input.bool(false, "Trailing Stop Line", group = G_RM)
showDash = input.bool(true, "Show Dashboard", group = G_DSH)
dashPos = input.string("Bottom Right", "Position", options = ["Top Right", "Middle Right", "Bottom Right", "Top Left", "Middle Left", "Bottom Left", "Top Center", "Bottom Center"], group = G_DSH)
dashSize = input.string("Small", "Size", options = ["Tiny", "Small", "Normal", "Large"], group = G_DSH)
// ════════════════════════════════════════════════════════════════════
// CORE CALCULATIONS
// ════════════════════════════════════════════════════════════════════
atrSig = ta.atr(sigLen)
atr14 = ta.atr(14)
rsi14 = ta.rsi(close, 14)
rsiLow = ta.lowest(rsi14, 5)
rsiHigh = ta.highest(rsi14, 5)
[diPlus, diMinus, adx] = ta.dmi(14, 14)
emaStrong = ta.ema(close, strongLen)
emaF = ta.ema(close, cloudFast)
emaS = ta.ema(close, cloudSlow)
swingBase = ta.ema(close, 34)
scalpBase = ta.hma(close, 21)
volAvg = ta.sma(nz(volume), 20)
volOk = nz(volume) > volAvg * 1.2
// ATR volatility stop — trend engine
longStop = hl2 - sens * atrSig
shortStop = hl2 + sens * atrSig
var float trail = na
var int dir = 1
if na(trail)
trail := longStop
if dir == 1
trail := math.max(trail, longStop)
if close < trail
dir := -1
trail := shortStop
else
trail := math.min(trail, shortStop)
if close > trail
dir := 1
trail := longStop
flipUp = dir == 1 and dir[1] == -1
flipDn = dir == -1 and dir[1] == 1
// Filters
filtBull = switch mode
"All Signals" => true
"Trending" => adx > 20
"Contrarian" => rsiLow < 35
"High Volume" => volOk
"Strong" => close > emaStrong
"Cloud: Swing" => close > swingBase
"Cloud: Smooth" => emaF > emaS
"Cloud: Scalping" => close > scalpBase
=> true
filtBear = switch mode
"All Signals" => true
"Trending" => adx > 20
"Contrarian" => rsiHigh > 65
"High Volume" => volOk
"Strong" => close < emaStrong
"Cloud: Swing" => close < swingBase
"Cloud: Smooth" => emaF < emaS
"Cloud: Scalping" => close < scalpBase
=> true
bull = flipUp and filtBull
bear = flipDn and filtBear
strongBull = bull and close > emaStrong
strongBear = bear and close < emaStrong
// ════════════════════════════════════════════════════════════════════
// SIGNAL LABELS
// ════════════════════════════════════════════════════════════════════
if showSignals and bull
label.new(bar_index, low, compact ? (strongBull ? "▲▲" : "▲") : (strongBull ? "STRONG\nBUY" : "BUY"), yloc = yloc.belowbar, style = label.style_label_up, color = bullCol, textcolor = color.white, size = size.small)
if showSignals and bear
label.new(bar_index, high, compact ? (strongBear ? "▼▼" : "▼") : (strongBear ? "STRONG\nSELL" : "SELL"), yloc = yloc.abovebar, style = label.style_label_down, color = bearCol, textcolor = color.white, size = size.small)
// ════════════════════════════════════════════════════════════════════
// TRADE MANAGEMENT (Entry / SL / TP)
// ════════════════════════════════════════════════════════════════════
var int side = 0
var float entry = na
var float sl = na
var float tp1 = na
var float tp2 = na
var float tp3 = na
var int entryBar = na
var bool hit1 = false
var bool hit2 = false
var bool hit3 = false
var bool slHit = false
if bull or bear
side := bull ? 1 : -1
entry := close
sl := bull ? close - slMult * atr14 : close + slMult * atr14
risk = math.abs(entry - sl)
tp1 := entry + side * risk * tp1R
tp2 := entry + side * risk * tp2R
tp3 := entry + side * risk * tp3R
entryBar := bar_index
hit1 := false
hit2 := false
hit3 := false
slHit := false
bool tp1Now = false
bool tp2Now = false
bool tp3Now = false
bool slNow = false
if side != 0 and not slHit and not hit3 and bar_index > entryBar
if tp1R > 0 and not hit1 and (side == 1 ? high >= tp1 : low <= tp1)
hit1 := true
tp1Now := true
if tp2R > 0 and not hit2 and (side == 1 ? high >= tp2 : low <= tp2)
hit2 := true
tp2Now := true
if tp3R > 0 and not hit3 and (side == 1 ? high >= tp3 : low <= tp3)
hit3 := true
tp3Now := true
if side == 1 ? low <= sl : high >= sl
slHit := true
slNow := true
tpNow = tp1Now or tp2Now or tp3Now
plotshape(tpNow and side == 1, "TP Hit (long)", shape.xcross, location.abovebar, bullCol, size = size.tiny, text = "TP", textcolor = bullCol)
plotshape(tpNow and side == -1, "TP Hit (short)", shape.xcross, location.belowbar, bearCol, size = size.tiny, text = "TP", textcolor = bearCol)
drawLvl(line[] ls, label[] lbs, int x1, float y, string txt, color c, string st) =>
array.push(ls, line.new(x1, y, bar_index + 8, y, color = c, style = st, width = 1))
array.push(lbs, label.new(bar_index + 8, y, txt + ": " + str.tostring(y, format.mintick), style = label.style_label_left, color = c, textcolor = color.white, size = size.small))
var line[] lvLines = array.new<line>()
var label[] lvLabels = array.new<label>()
if barstate.islast
for l in lvLines
line.delete(l)
for lb in lvLabels
label.delete(lb)
array.clear(lvLines)
array.clear(lvLabels)
if showTPSL and side != 0
drawLvl(lvLines, lvLabels, entryBar, entry, "Entry", color.new(#7a8699, 0), line.style_dashed)
drawLvl(lvLines, lvLabels, entryBar, sl, "Stop", bearCol, line.style_solid)
if tp1R > 0
drawLvl(lvLines, lvLabels, entryBar, tp1, "TP 1", bullCol, line.style_dotted)
if tp2R > 0
drawLvl(lvLines, lvLabels, entryBar, tp2, "TP 2", bullCol, line.style_dotted)
if tp3R > 0
drawLvl(lvLines, lvLabels, entryBar, tp3, "TP 3", bullCol, line.style_dotted)
// ════════════════════════════════════════════════════════════════════
// TRADING ASSISTANTS
// ════════════════════════════════════════════════════════════════════
cloudBull = emaF > emaS
showCloudNow = showCloud or mode == "Cloud: Smooth"
pF = plot(showCloudNow ? emaF : na, "Cloud Fast", color.new(cloudBull ? bullCol : bearCol, 40))
pS = plot(showCloudNow ? emaS : na, "Cloud Slow", color.new(cloudBull ? bullCol : bearCol, 40))
fill(pF, pS, color.new(cloudBull ? bullCol : bearCol, 82), "Trend Cloud")
rib8 = ta.ema(close, 8)
rib13 = ta.ema(close, 13)
rib21 = ta.ema(close, 21)
plot(showRibbon ? rib8 : na, "Ribbon 8", color.new(#4fc3f7, 20))
plot(showRibbon ? rib13 : na, "Ribbon 13", color.new(#29b6f6, 35))
plot(showRibbon ? rib21 : na, "Ribbon 21", color.new(#0288d1, 50))
plot(showTrail and dir == dir[1] ? trail : na, "Trailing Stop", dir == 1 ? bullCol : bearCol, 1, plot.style_linebr)
rDot = ta.rsi(close, dotLen)
dotUp = ta.crossover(rDot, 30)
dotDn = ta.crossunder(rDot, 70)
plotshape(showDots and dotUp, "Reversal Dot Up", shape.circle, location.belowbar, color.new(bullCol, 10), size = size.tiny)
plotshape(showDots and dotDn, "Reversal Dot Down", shape.circle, location.abovebar, color.new(bearCol, 10), size = size.tiny)
// Momentum candles (MACD histogram slope + trend direction)
macdLine = ta.ema(close, 12) - ta.ema(close, 26)
hist = macdLine - ta.ema(macdLine, 9)
barCol = dir == 1 and hist > hist[1] ? bullCol : dir == -1 and hist < hist[1] ? bearCol : color.new(#7b6fa8, 0)
barcolor(colorBars ? barCol : na)
// Market structure
ph = ta.pivothigh(high, structLen, structLen)
pl = ta.pivotlow(low, structLen, structLen)
var float lastPH = na
var float lastPL = na
if not na(ph)
if showStruct
label.new(bar_index - structLen, ph, na(lastPH) ? "H" : ph > lastPH ? "HH" : "LH", style = label.style_label_down, color = color.new(color.black, 100), textcolor = na(lastPH) or ph > lastPH ? bullCol : bearCol, size = size.small)
lastPH := ph
if not na(pl)
if showStruct
label.new(bar_index - structLen, pl, na(lastPL) ? "L" : pl < lastPL ? "LL" : "HL", style = label.style_label_up, color = color.new(color.black, 100), textcolor = na(lastPL) or pl > lastPL ? bullCol : bearCol, size = size.small)
lastPL := pl
// ════════════════════════════════════════════════════════════════════
// DASHBOARD
// ════════════════════════════════════════════════════════════════════
f_bias(string tf) => request.security(syminfo.tickerid, tf, close > ta.ema(close, 200))
b5 = f_bias("5")
b15 = f_bias("15")
b30 = f_bias("30")
b60 = f_bias("60")
b240 = f_bias("240")
atrRank = ta.percentrank(atr14, 100)
volRma = ta.rma(nz(volume), 21)
instActive = nz(volume) > volRma * 1.44
ema9 = ta.ema(close, 9)
pressure = ema9 > ema9[2] ? "Bullish" : ema9 < ema9[2] ? "Bearish" : "Flat"
mState = adx >= 25 ? "Trending" : adx >= 18 ? "Ranging" : "No Trend"
inNY = not na(time(timeframe.period, "1300-2200", "UTC"))
inLDN = not na(time(timeframe.period, "0700-1600", "UTC"))
inTKY = not na(time(timeframe.period, "0000-0900", "UTC"))
inSYD = not na(time(timeframe.period, "2100-0600", "UTC"))
session = inLDN and inNY ? "London / New York" : inTKY and inLDN ? "Tokyo / London" : inSYD and inTKY ? "Sydney / Tokyo" : inNY ? "New York" : inLDN ? "London" : inTKY ? "Tokyo" : inSYD ? "Sydney" : "Closed"
dashLoc = switch dashPos
"Top Right" => position.top_right
"Middle Right" => position.middle_right
"Bottom Right" => position.bottom_right
"Top Left" => position.top_left
"Middle Left" => position.middle_left
"Bottom Left" => position.bottom_left
"Top Center" => position.top_center
=> position.bottom_center
tSize = switch dashSize
"Tiny" => size.tiny
"Normal" => size.normal
"Large" => size.large
=> size.small
var table dash = table.new(dashLoc, 4, 7, bgcolor = color.new(#0b1220, 10), frame_color = #2a3245, frame_width = 1, border_color = #1c2333, border_width = 1)
cell(int c, int r, string t, color bg, color tc) =>
table.cell(dash, c, r, t, text_color = tc, bgcolor = bg, text_size = tSize, text_halign = text.align_left)
biasBg(bool b) => b ? color.new(bullCol, 25) : color.new(bearCol, 25)
if barstate.islast and showDash
hdr = color.new(#141c2e, 0)
cell(0, 0, "MTF", hdr, color.new(#ff7a45, 0))
cell(1, 0, "Trend", hdr, color.new(#ff7a45, 0))
cell(2, 0, "PTZ Algo", hdr, color.new(#ff7a45, 0))
cell(3, 0, "", hdr, color.white)
cell(0, 1, "M5", na, color.white)
cell(1, 1, b5 ? "▲" : "▼", biasBg(b5), color.white)
cell(0, 2, "M15", na, color.white)
cell(1, 2, b15 ? "▲" : "▼", biasBg(b15), color.white)
cell(0, 3, "M30", na, color.white)
cell(1, 3, b30 ? "▲" : "▼", biasBg(b30), color.white)
cell(0, 4, "1H", na, color.white)
cell(1, 4, b60 ? "▲" : "▼", biasBg(b60), color.white)
cell(0, 5, "4H", na, color.white)
cell(1, 5, b240 ? "▲" : "▼", biasBg(b240), color.white)
cell(0, 6, "", na, color.white)
cell(1, 6, "", na, color.white)
cell(2, 1, "Signal", na, color.gray)
cell(3, 1, side == 1 ? "Long" : side == -1 ? "Short" : "—", side == 1 ? color.new(bullCol, 25) : side == -1 ? color.new(bearCol, 25) : na, color.white)
cell(2, 2, "Market State", na, color.gray)
cell(3, 2, mState + " (" + str.tostring(math.round(adx)) + ")", na, color.white)
cell(2, 3, "Volatility", na, color.gray)
cell(3, 3, (atrRank >= 70 ? "High" : atrRank <= 30 ? "Low" : "Normal") + " (" + str.tostring(math.round(atrRank)) + "%)", na, color.white)
cell(2, 4, "Volume Activity", na, color.gray)
cell(3, 4, instActive ? "Active" : "Quiet", na, instActive ? color.new(#4fc3f7, 0) : color.white)
cell(2, 5, "Session (UTC)", na, color.gray)
cell(3, 5, session, na, color.white)
cell(2, 6, "Trend Pressure", na, color.gray)
cell(3, 6, pressure, na, pressure == "Bullish" ? bullCol : pressure == "Bearish" ? bearCol : color.white)
// ════════════════════════════════════════════════════════════════════
// ALERTS
// ════════════════════════════════════════════════════════════════════
alertcondition(bull, "Buy Signal", "PTZ Algo: BUY on {{ticker}} ({{interval}}) at {{close}}")
alertcondition(strongBull, "Strong Buy Signal", "PTZ Algo: STRONG BUY on {{ticker}} ({{interval}}) at {{close}}")
alertcondition(bear, "Sell Signal", "PTZ Algo: SELL on {{ticker}} ({{interval}}) at {{close}}")
alertcondition(strongBear, "Strong Sell Signal","PTZ Algo: STRONG SELL on {{ticker}} ({{interval}}) at {{close}}")
alertcondition(tp1Now, "TP 1 Hit", "PTZ Algo: TP 1 reached on {{ticker}} ({{interval}})")
alertcondition(tp2Now, "TP 2 Hit", "PTZ Algo: TP 2 reached on {{ticker}} ({{interval}})")
alertcondition(tp3Now, "TP 3 Hit", "PTZ Algo: TP 3 reached on {{ticker}} ({{interval}})")
alertcondition(slNow, "Stop Loss Hit", "PTZ Algo: stop loss hit on {{ticker}} ({{interval}})")
alertcondition(ta.crossover(emaF, emaS), "Bullish Cloud Cross", "PTZ Algo: trend cloud turned bullish on {{ticker}} ({{interval}})")
alertcondition(ta.crossunder(emaF, emaS), "Bearish Cloud Cross", "PTZ Algo: trend cloud turned bearish on {{ticker}} ({{interval}})")