Strategy · Pine Script v6 · Own pane

订单流分析

by YooooungLee

This strategy evaluates order flow by combining volume dynamics and price deviation relative to the Volume Weighted Average Price (VWAP).

View on GitHub

Repaints

GitHub stars4on the repository
Pine versionv6current
Lines of code104
Settings8inputs
LicenceApache-2.0
Last update10 months ago29 Dec 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

104 lines of Pine Script v6 from Quant-code/strategy/订单流分析策略.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

订单流分析策略.pine
//@version=6
strategy("订单流分析", shorttitle="订单流", overlay=false, 
         default_qty_type=strategy.fixed, default_qty_value=1,
         pyramiding=0, calc_on_every_tick=true)


// ====== 输入参数 ======
var_group = "策略参数"
timeframeInput = input.string("AUTO", "时间周期调整", options=["AUTO", "1分钟", "5分钟", "15分钟", "30分钟", "1小时", "4小时", "日线"], group=var_group)

// 根据时间周期自动调整参数
var timeframeMap = array.from("1", "5", "15", "30", "60", "240", "D")
var selectedTimeframe = timeframeInput == "AUTO" ? timeframe.period : array.get(timeframeMap, array.indexof(array.from("1分钟", "5分钟", "15分钟", "30分钟", "1小时", "4小时", "日线"), timeframeInput))

// 动态调整参数
volumeThreshold = input.float(2.0, "成交量阈值(相对于平均值)", minval=1.0, group=var_group)
priceChangeThreshold = input.float(0.5, "价格变化阈值(%)", minval=0.1, group=var_group)
lookbackPeriod = input.int(20, "回溯期间", minval=5, group=var_group)

// 根据时间周期调整参数
adjustedVolumeThreshold = timeframeInput == "AUTO" ? volumeThreshold :timeframe.isintraday ? volumeThreshold * 1.5 : volumeThreshold
adjustedPriceThreshold = timeframeInput == "AUTO" ? priceChangeThreshold :timeframe.isintraday ? priceChangeThreshold * 0.5 : priceChangeThreshold
adjustedLookback = timeframeInput == "AUTO" ? lookbackPeriod :timeframe.isintraday ? math.floor(lookbackPeriod * 0.7) : lookbackPeriod

// ====== 风控参数 ======
risk_group = "风控参数"
useStopLoss = input.bool(true, "启用止损", group=risk_group)
stopLossPercent = input.float(2.0, "止损百分比", minval=0.1, maxval=100.0, group=risk_group)
useTakeProfit = input.bool(true, "启用止盈", group=risk_group)
takeProfitPercent = input.float(3.0, "止盈百分比", minval=0.1, maxval=100.0, group=risk_group)

// ====== 计算指标 ======
// 计算VWAP作为参考
vwap = ta.vwap(hlc3)

// 计算相对成交量(使用指数移动平均以减少滞后)
averageVolume = ta.ema(volume, adjustedLookback)
volumeRatio = volume / averageVolume

// 计算价格变化百分比(相对VWAP)
priceChange = math.abs(close - vwap) / vwap * 100

// 计算买卖压力(考虑VWAP)
buyPressure = close > vwap ? volume : 0.0
sellPressure = close < vwap ? volume : 0.0
netPressure = ta.ema(buyPressure - sellPressure, adjustedLookback)

// 计算成交量动量
volumeMomentum = ta.mom(volume, 1)
isVolumeIncreasing = volumeMomentum > 0

// ====== 生成信号 ======
// 判断成交量和价格变动
isHighVolume = volumeRatio >= volumeThreshold
isSignificantMove = priceChange >= priceChangeThreshold

// 生成交易条件
longCondition = isHighVolume and isSignificantMove and netPressure > 0 and close > vwap and isVolumeIncreasing
shortCondition = isHighVolume and isSignificantMove and netPressure < 0 and close < vwap and isVolumeIncreasing

// ====== 执行策略 ======
if (longCondition)
    strategy.entry("买入开仓", strategy.long)
if (shortCondition)
    strategy.entry("卖出开仓", strategy.short)

// 设置止损止盈
if (useStopLoss or useTakeProfit)
    strategy.exit("多单平仓", from_entry="买入开仓", stop=useStopLoss ? close * (1 - stopLossPercent/100) : na, limit=useTakeProfit ? close * (1 + takeProfitPercent/100) : na)
    strategy.exit("空单平仓", from_entry="卖出开仓", stop=useStopLoss ? close * (1 + stopLossPercent/100) : na, limit=useTakeProfit ? close * (1 - takeProfitPercent/100) : na)

// ====== 绘制图表 ======
// 计算买卖压力
bullishPressure = netPressure > 0 ? netPressure : 0
bearishPressure = netPressure < 0 ? math.abs(netPressure) : 0

// 计算移动最大值作为标准化基准
maxPressure = math.max(ta.highest(bullishPressure, 100), ta.highest(bearishPressure, 100))
normBullishPressure = maxPressure != 0 ? (bullishPressure / maxPressure * 100) : 0
normBearishPressure = maxPressure != 0 ? (bearishPressure / maxPressure * 100) : 0

// 绘制买卖压力柱状图
plot(normBullishPressure, "买压", color=color.new(color.green, 0), style=plot.style_columns)
plot(-normBearishPressure, "卖压", color=color.new(color.red, 0), style=plot.style_columns)

// 绘制中轴线
hline(0, "中轴线", color=color.new(color.gray, 50))

// 绘制成交量比率(放大5倍使其更容易观察)
plot(volumeRatio * 5, "成交量比率", color=color.new(color.blue, 0), linewidth=2)
hline(volumeThreshold * 5, "成交量阈值", color=color.new(color.gray, 0), linestyle=hline.style_dashed)

// ====== 背景标记 ======
bgcolor(longCondition ? color.new(color.green, 90) : shortCondition ? color.new(color.red, 90) : na)

// ====== 盈亏标记 ======
if (strategy.closedtrades > 0)
    lastTradeIndex = strategy.closedtrades - 1
    lastTradeProfit = strategy.closedtrades.profit(lastTradeIndex)
    lastTradeBarIndex = strategy.closedtrades.exit_bar_index(lastTradeIndex)
    if (bar_index == lastTradeBarIndex)
        labelText = lastTradeProfit > 0 ? "盈利: " + str.tostring(lastTradeProfit, "#.##") : "亏损: " + str.tostring(lastTradeProfit, "#.##")
        labelColor = lastTradeProfit > 0 ? color.green : color.red
        label.new(x=bar_index, y=close, text=labelText, color=labelColor, style=label.style_label_down, size=size.small)

Overview

订单流分析 enters long trades when trading volume exceeds a relative threshold, price moves significantly above VWAP, net volume pressure is positive, and volume momentum is rising. Short trades are placed when price drops below VWAP under high volume and negative pressure. It manages risk through optional percentage-based stop loss and take profit orders. Plotting in a separate pane, the script evaluates on every tick, meaning signals can change intrabar before the bar closes.

Details

Published by

YooooungLee on GitHub

Type

Strategy, Pine Script v6

Draws

Separate pane below the chart

Category

Volume, Oscillators & momentum

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
时间周期调整stringAUTOtimeframeInput
成交量阈值(相对于平均值)float2.0volumeThreshold
价格变化阈值(%)float0.5priceChangeThreshold
回溯期间int20lookbackPeriod
启用止损booltrueuseStopLoss
止损百分比float2.0stopLossPercent
启用止盈booltrueuseTakeProfit
止盈百分比float3.0takeProfitPercent
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Q-Trend + KVO Strategy

by TradersPost
218 stars

This strategy combines the ATR-banded Q-Trend indicator with the Klinger Volume Oscillator (KVO) to execute confluence trades. It enters long when a Q-Trend buy trigger aligns with a positive KVO value and a bullish candle confirmation, taking short trades und

Strategy v6 TrendVolume
Updated 3 months ago · None stated GitHub repository of Q-Trend + KVO Strategy

BBPBΔ(OBV-PVT)BB

by hasnocool
106 stars

This strategy calculates the normalized rate of change between On-Balance Volume (OBV) and Price Volume Trend (PVT) indicators. It applies Bollinger Bands to this volume metric along with a Hodrick-Prescott filter array for time series decomposition. Displayed

Strategy v4 VolumeVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of BBPBΔ(OBV-PVT)BB

BTC Futures MACD

by iamrichardD
57 stars

This strategy plots a MACD oscillator in a separate pane and trades Bitcoin futures from zero-line and signal-line crosses. Optional early momentum signals, a volume filter, and a trend moving-average filter can confirm entries. It sizes positions as fixed con

Strategy v6 Oscillators & momentumMoving averages Repaints
Updated 1 year ago · Apache-2.0 GitHub repository of BTC Futures MACD

RSI-VWAP Indicator

by oguzhandilber
47 stars

This strategy calculates a Relative Strength Index (RSI) applied to the Volume Weighted Average Price (VWAP) rather than standard close values. It plots dedicated long and short RSI-VWAP lines with customizable overbought and oversold thresholds, alongside an

Strategy v4 Oscillators & momentumVolume
Updated 5 years ago · None stated GitHub repository of RSI-VWAP Indicator
13 stars

This strategy calculates the Volume Zone Oscillator (VZO) alongside volume spikes to detect directional momentum. It enters long positions when the VZO turns bullish accompanied by a volume spike, and enters short when the VZO turns bearish with elevated volum

Strategy v5 VolumeOscillators & momentum
Updated 1 year ago · None stated GitHub repository of Ruckard Neobutane VZO bA002

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers