Price Pressure Momentum Profile

uzair2join · study · 95 行 · 点赞 21 · 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/
// © uzair2join
//
// Price Pressure Momentum (PPM) Profile
// Based on the "Price Pressure Momentum / Angle of Attack" concept credited to Bob Kendall.
// This is an independent implementation with added acceleration, multi-period alignment, signal line, alerts and status table.
 
//@version=6
indicator("Price Pressure Momentum Profile [thenqstory]", shorttitle="PPM Profile", overlay=false, format=format.percent, precision=3)
 
// ───────── Inputs ─────────
src       = input.source(close, "Source")
lookback  = input.int(1, "Lookback (bars)", minval=1, tooltip="How many bars back the SMA slope is measured over.")
 
grpP      = "PPM Periods (Momentum Profile)"
len1      = input.int(10, "PPM1 Period (short)",  minval=1, group=grpP)
len2      = input.int(21, "PPM2 Period (medium)", minval=1, group=grpP)
len3      = input.int(40, "PPM3 Period (long)",   minval=1, group=grpP)
show1     = input.bool(true, "Show PPM1", group=grpP)
show2     = input.bool(true, "Show PPM2", group=grpP)
show3     = input.bool(true, "Show PPM3", group=grpP)
 
grpS      = "Signal Line"
showSig   = input.bool(true, "Show Signal Line (smoothed PPM1)", group=grpS)
sigLen    = input.int(10, "Signal Smoothing", minval=1, group=grpS)
 
grpA      = "Acceleration (PPM1 change per bar)"
showAcc   = input.bool(true, "Show Acceleration Histogram", group=grpA)
accSmooth = input.int(3, "Acceleration Smoothing (1 = raw)", minval=1, group=grpA)
accMult   = input.float(1.0, "Histogram Scale Multiplier", minval=0.1, step=0.5, group=grpA, tooltip="Visual only. Increase if bars look too small next to the PPM lines. Does not affect alerts.")
 
grpV      = "Visuals"
showBg    = input.bool(true, "Background when all 3 PPMs agree", group=grpV)
showTbl   = input.bool(true, "Show Status Table", group=grpV)
 
// ───────── Calculations ─────────
f_ppm(len) =>
    s = ta.sma(src, len)
    p = s[lookback]
    p != 0 ? (s - p) / p * 100 : na
 
ppm1 = f_ppm(len1)
ppm2 = f_ppm(len2)
ppm3 = f_ppm(len3)
 
signal   = ta.sma(ppm1, sigLen)
 
accRaw   = ppm1 - ppm1[1]
accel    = accSmooth > 1 ? ta.ema(accRaw, accSmooth) : accRaw
accPlot  = accel * accMult
 
allUp    = ppm1 > 0 and ppm2 > 0 and ppm3 > 0
allDown  = ppm1 < 0 and ppm2 < 0 and ppm3 < 0
 
// ───────── Colors ─────────
accColor = accel >= 0 ?
     (accel >= nz(accel[1]) ? color.new(color.teal, 0) : color.new(color.teal, 60)) :
     (accel <= nz(accel[1]) ? color.new(color.red, 0)  : color.new(color.red, 60))
 
bgCol = showBg ? (allUp ? color.new(color.green, 90) : allDown ? color.new(color.red, 90) : na) : na
bgcolor(bgCol, title="Alignment Background")
 
// ───────── Plots ─────────
hline(0, "Zero Line", color=color.gray, linestyle=hline.style_dashed)
plot(showAcc ? accPlot : na, "Acceleration", color=accColor, style=plot.style_columns)
plot(show3   ? ppm3    : na, "PPM3 (long)",   color=color.blue,   linewidth=1)
plot(show2   ? ppm2    : na, "PPM2 (medium)", color=color.green,  linewidth=1)
plot(show1   ? ppm1    : na, "PPM1 (Angle of Attack)", color=color.orange, linewidth=2)
plot(showSig ? signal  : na, "Signal (smoothed PPM1)", color=color.purple, linewidth=1)
 
// ───────── Alerts ─────────
alertcondition(ta.crossover(ppm1, 0),       "PPM1 crosses above 0",        "PPM1 turned positive (buying pressure)")
alertcondition(ta.crossunder(ppm1, 0),      "PPM1 crosses below 0",        "PPM1 turned negative (selling pressure)")
alertcondition(ta.crossover(ppm1, signal),  "PPM1 crosses above Signal",   "PPM1 crossed above its signal line")
alertcondition(ta.crossunder(ppm1, signal), "PPM1 crosses below Signal",   "PPM1 crossed below its signal line")
alertcondition(ta.crossover(accel, 0),      "Acceleration turns positive", "Momentum is accelerating up")
alertcondition(ta.crossunder(accel, 0),     "Acceleration turns negative", "Momentum is accelerating down")
alertcondition(allUp and not allUp[1],      "All PPMs bullish",            "PPM1, PPM2 and PPM3 are all above 0")
alertcondition(allDown and not allDown[1],  "All PPMs bearish",            "PPM1, PPM2 and PPM3 are all below 0")
 
// ───────── Status Table ─────────
var table tbl = table.new(position.top_right, 2, 5, bgcolor=color.new(color.black, 20), border_width=1)
f_cell(row, label, val) =>
    c = na(val) ? color.gray : val > 0 ? color.teal : val < 0 ? color.red : color.gray
    table.cell(tbl, 0, row, label, text_color=color.white, text_size=size.small)
    table.cell(tbl, 1, row, na(val) ? "n/a" : str.tostring(val, "#.###") + "%", text_color=c, text_size=size.small)
 
if showTbl and barstate.islast
    f_cell(0, "PPM1 (" + str.tostring(len1) + ")", ppm1)
    f_cell(1, "PPM2 (" + str.tostring(len2) + ")", ppm2)
    f_cell(2, "PPM3 (" + str.tostring(len3) + ")", ppm3)
    f_cell(3, "Accel", accel)
    bias = allUp ? "ALIGNED UP" : allDown ? "ALIGNED DOWN" : "MIXED"
    table.cell(tbl, 0, 4, "Profile", text_color=color.white, text_size=size.small)
    table.cell(tbl, 1, 4, bias, text_color=allUp ? color.teal : allDown ? color.red : color.gray, text_size=size.small)

← 返回列表