本页源码来自 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/
// © CryptoNejc
//@version=6
indicator("Volume Price Momentum [NJ]", "VPM")
// ✧═════════════════✧
// ║ INPUTS ║
// ✧═════════════════✧
const string g1 = "✧ DISPLAY ✧"
displayLabels = input.bool(true, "Show buy/sell labels?", group = g1)
displayColCandles = input.bool(true, "Show colored candles?", group = g1)
displayRngStatus = input.bool(true, "Show range status?", group = g1)
const string g2 = "✧ CALCULATION ✧"
buyThr = input.int(50, "Buy threshold", group = g2)
sellThr = input.int(45, "Sell threshold", group = g2)
volLen = input.int(30, "Volume length", group = g2)
priceLen = input.int(50, "Price length", group = g2)
smoothLen = input.int(14, "Smoothing length", group = g2)
// ✧═══════════════════════✧
// ║ RANGE FILTER ║
// ✧═══════════════════════✧
import CryptoNejc/RangeDetector/1 as rd
inRange = rd.detect()
// ✧══════════════════════✧
// ║ CALCULATION ║
// ✧══════════════════════✧
// Volume and price percentile ranks
volRank = ta.percentrank(volume, volLen)
priceRank = ta.percentrank(close, priceLen)
// Average percentile score
avgScore = (volRank + priceRank) / 2
// Smooth the score
smoothScore = ta.sma(avgScore, smoothLen)
// Cap the score
cappedScore = math.max(35, math.min(60, smoothScore))
// Buy/sell signals
buySig = cappedScore >= buyThr and not inRange
sellSig = cappedScore < sellThr
// ✧═══════════════════════✧
// ║ FINAL SIGNAL ║
// ✧═══════════════════════✧
var int sig = 0
if buySig
sig := 1
if sellSig
sig := -1
// ✧════════════════✧
// ║ PLOTS ║
// ✧════════════════✧
// Colors
long = color.rgb(0, 136, 100)
short = color.rgb(120, 0, 32)
color sigCol = sig == 1 ? long : sig == -1 ? short : na
// Score oscillator
plot(cappedScore, "Score", sigCol, 3)
hline(buyThr, "Buy threshold", long)
hline(sellThr, "Sell threshold", short)
// Range status table
var table rangeTable = table.new(
position.top_right, 1, 2,
frame_color = color.new(color.white, 85),
frame_width = 1)
if barstate.islast and displayRngStatus
table.cell(
rangeTable, 0, 0,
"✧ RANGE ✧",
text_color = color.new(color.white, 15),
text_size = size.small,
bgcolor = color.rgb(18, 18, 20))
table.cell(
rangeTable, 0, 1,
inRange ? "✓" : "✕",
text_color = inRange ? long : short,
text_size = size.large,
bgcolor = color.rgb(18, 18, 20))
// Colored candles
plotcandle(
open, high, low, close,
"Colored candles",
displayColCandles ? sigCol : na,
displayColCandles ? sigCol : na,
bordercolor = displayColCandles ? sigCol : na,
display = display.all - display.status_line - display.price_scale,
force_overlay = true)
// Buy/sell labels
plotshape(
sig == 1 and sig[1] == -1 and displayLabels,
title = "Buy",
text = "BUY",
style = shape.labelup,
location = location.belowbar,
color = long,
textcolor = color.white,
size = size.small,
force_overlay = true)
plotshape(
sig == -1 and sig[1] == 1 and displayLabels,
title = "Sell",
text = "SELL",
style = shape.labeldown,
location = location.abovebar,
color = short,
textcolor = color.white,
size = size.small,
force_overlay = true)