OPEN-SOURCE SCRIPT
업데이트됨

Volume Bars [jpkxyz]

2 532
스냅샷

Multi-Timeframe Volume indicator by @jpkxyz

This script is a Multi-Timeframe Volume Z-Score Indicator. It dynamically calculates /the Z-Score of volume over different timeframes to assess how significantly current
volume deviates from its historical average. The Z-Score is computed for each
timeframe independently and is based on a user-defined lookback period. The
script switches between timeframes automatically, adapting to the chart's current
timeframe using `timeframe.multiplier`.

The Z-Score formula used is: (current volume - mean) / standard deviation, where
mean and standard deviation are calculated over the lookback period.

The indicator highlights periods of "significant" and "massive" volume by comparing
the Z-Score to user-specified thresholds (`zScoreThreshold` for significant volume
and `massiveZScoreThreshold` for massive volume). The script flags buy or sell
conditions based on whether the current close is higher or lower than the open.

Visual cues:
- Dark Green for massive buy volume.
- Red for massive sell volume.
- Green for significant buy volume.
- Orange for significant sell volume.
- Gray for normal volume.

The script also provides customizable alert conditions for detecting significant or massive buy/sell volume events, allowing users to set real-time alerts.
릴리즈 노트
Volume Bars [jpkxyz] - Volume Z-Score Analysis Indicator

This indicator calculates and displays volume Z-scores, measuring how current volume deviates from its historical average over a user-defined lookback period.
The Z-score formula used is: (current volume - mean) / standard deviation.

Features:
- Z-score based volume analysis
- Two threshold levels: significant and massive volume
- Optional non-repainting mode for backtesting
- Customizable bar colors and transparency

Bar colors indicate:
- Dark Green: Massive buy volume
- Red: Massive sell volume
- Green: Significant buy volume
- Orange: Significant sell volume
- Gray: Normal volume

Applications:
- Volume spike identification
- Volume trend analysis
- Backtesting with non-repainting mode
- Real-time volume monitoring with repainting mode

The indicator uses bar colors to integrate volume analysis directly with price action while maintaining chart clarity.




The previous version used barmerge.lookahead_on for various timeframe requests without an offset. This can lead to misleading historical results because it's looking ahead without the protective offset. Thank you PineCoders for making me aware of this.

Here are the key improvements:

1. Added repainting control via input parameter
2. Users can now choose between:
* allowRepaint = true: For live trading analysis (sees volume changes in real-time)
* allowRepaint = false: For backtesting and alerts (only uses confirmed volume)

Benefits of this approach:

1. For Live Trading:
  • When allowRepaint = true, you'll see volume bars change color as volume accumulates within the current bar
  • Helpful for watching potential volume setups develop
  • Good for discretionary trading decisions

2. For Backtesting:
  • When allowRepaint = false, you only get signals based on completed bars
  • More reliable for backtesting results
  • Better for automated alerts to avoid false triggers
  • Prevents misleading historical results

Usage Recommendation:

1. Use allowRepaint = true when:
  • Actively watching the market
  • Making manual trading decisions
  • Want to see potential volume setups forming in real time

2. Use allowRepaint = false when:
  • Backtesting strategies
  • Want to avoid false signals
  • Running automated systems




Please be aware that the historical bars color change depending if you have repainting on or off. When you switch between modes, it's essentially shifting the volume data by one bar, which changes the Z-score calculations and therefore the bar colors.

1. When allowRepaint = false, you're seeing data from the previous bar (volume[1]) for all calculations
2. When allowRepaint = true, you're seeing volume data from the current bar


Example:
  • In non-repainting mode, bar 5's color is based on bar 4's volume
  • In repainting mode, bar 5's color is based on bar 5's volume


This is why PineCoders recommends using volume[1] with lookahead=barmerge.lookahead_on for consistent historical data. If you want truly consistent historical bars, you should keep it in non-repainting mode.
If you want to get real-time data while live trading keep it in repainting mode.

The new logic ensures:

1. New bars start with neutral transparency
2. In repainting mode, transparency updates as volume conditions are met
3. In non-repainting mode, bars stay neutral until confirmed

Default Input Changes: 



Previous
  • Lookback for Z-Score: 100 Bars
  • Significant Volume Threshold: 0.2
  • Massive Volume Threshold: 0.4


New
  • Lookback for Z-Score: 25 Bars / to make it more responsive to recent volume
  • Significant Volume Threshold: 0.3 / slightly higher filter
  • Massive Volume Threshold: 0.6 / slightly higher filter


Simpler and cleaner timeframe logic:

1. Removed all individual timeframe volume requests
2. Added single request using timeframe.period
3. Simplified Z-score calculation to use only current timeframe
4. Removed getCurrentZScore() function as it's no longer needed

If you have questions, suggestions, find errors or if your using this script to build cool things yourself, please let me know in the comments.


DISCLAIMER:

The creator of this script
- Does not guarantee accuracy or completeness of data
- Is not responsible for trading decisions or losses
- Makes no claims about future market performance
- Provides no warranty of fitness for any purpose

Use this indicator at your own risk. Past performance does not indicate future results.
Trading involves substantial risk of loss. Only trade with capital you can afford to lose.
By using this script you acknowledge and accept full responsibility for any outcomes.



릴리즈 노트
Volume Bars Indicator Update Description


1. Non-Repainting Mode Fix

Old Behavior: Used previous bar's volume (volume[1]), causing volume signals to display one bar late
New Behavior: Uses current bar's volume (volume), showing signals on the correct bar once confirmed
Impact: More accurate historical analysis as volume events now align with the bars where they occurred

2. Volume Data Source

Pine Script®
// Old version currentVolume = request.security(syminfo.tickerid, timeframe.period, allowRepaint ? volume : volume[1], lookahead = barmerge.lookahead_on) // New version currentVolume = request.security(syminfo.tickerid, timeframe.period, volume, lookahead = barmerge.lookahead_on)


  • Simplified volume data retrieval
  • Ensures consistent data source regardless of repainting mode
  • Volume calculations now always use the correct bar's data


3. Repainting Control Logic

Pine Script®
// New clean logic isLiveBar = barstate.isrealtime shouldBeNeutral = not allowRepaint and isLiveBar


  • Streamlined control flow
  • More explicit and easier to maintain
  • Clearer separation between live bar and historical bar handling


4. Default Z-Score Thresholds

  • Significant Volume Threshold: Changed from 0.2 to 1.0
  • Massive Volume Threshold: Changed from 0.4 to 2.0
  • Impact: More selective signal generation, focusing on more significant volume events
  • Note: These values remain customizable through input parameters


Behavior Summary

Repainting Mode (allowRepaint = true)

  • Behavior unchanged
  • Live bars update colors in real-time
  • Shows immediate volume feedback
  • Useful for active trading where immediate volume feedback is desired


Non-Repainting Mode (allowRepaint = false)

  • Current bar always stays neutral/grey until closed
  • Volume colors appear on the correct bars once confirmed
  • Historical bars maintain their colors regardless of mode changes
  • Ideal for backtesting and strategy development

Performance Implications

Calculation Efficiency


  • Core Z-score calculations remain unchanged
  • No additional computational overhead
  • Same mathematical accuracy in both modes


Memory Usage

  • Slightly optimized due to simplified volume data handling
  • No additional variables or storage requirements
  • Consistent memory footprint across both modes


Signal Quality

  • More accurate historical representation
  • Higher default thresholds reduce noise
  • Better signal-to-noise ratio for volume analysis
  • More reliable backtesting results in non-repainting mode


릴리즈 노트
Update with cleaner chart display.
릴리즈 노트
Multi-Timeframe Volume Indicator (Volume Z-Score)

This script is a multi-timeframe volume Z-score indicator that helps traders measure how unusual current volume is compared to recent history.

It calculates a Z-score for volume using a user-defined lookback period, then highlights significant and massive volume events based on threshold levels.

The script can also classify volume as buy or sell pressure by checking whether the bar closes above or below its open.

How It Works

The Z-score is calculated as:

  • (current volume - mean volume) / standard deviation


Mean and standard deviation are calculated over the selected lookback period.

The script adapts to the active chart timeframe and can be used for both real-time monitoring and backtesting workflows.

Volume Event Classification

The indicator compares volume Z-score values to two user-defined thresholds:

  • Significant volume threshold
  • Massive volume threshold


It then classifies bars by direction:

  • Buy volume when close > open
  • Sell volume when close < open


Bar Color Logic

  • Dark Green = Massive buy volume
  • Red = Massive sell volume
  • Green = Significant buy volume
  • Orange = Significant sell volume
  • Gray = Normal volume


Key Features

  • Volume Z-score analysis (relative volume deviation)
  • Two threshold levels: significant and massive
  • Multi-timeframe-aware behavior
  • Optional repainting control for live trading vs backtesting
  • Customizable colors and transparency
  • Alert conditions for significant/massive buy/sell volume events


Repainting Mode (Important)

This script includes a repainting toggle so users can choose the behavior that fits their workflow.

  1. allowRepaint = true (live trading / discretionary use)
    • Volume colors can update while the current bar is forming
    • Useful for real-time monitoring of developing volume spikes
  2. allowRepaint = false (backtesting / alerts)
    • Signals are based on confirmed bars only
    • Helps avoid false triggers on live bars
    • Better suited for testing and automation


Notes on Historical Bars

Bar colors may differ when switching repainting mode on/off because confirmed vs live-bar handling changes how volume conditions are evaluated.

For the most consistent historical analysis, use non-repainting mode.
For real-time discretionary trading, repainting mode may be more useful.

Typical Use Cases

  1. Volume spike detection
  2. Buy vs sell volume pressure context
  3. Backtesting volume-based ideas
  4. Real-time volume monitoring and alerts


Inputs (Typical)

  • Lookback period for Z-score calculation
  • Significant volume threshold
  • Massive volume threshold
  • allowRepaint toggle
  • Bar colors / transparency


Practical Notes

This indicator is best used as a volume context and confirmation tool, not a standalone trading system.

Disclaimer

This script is for educational and analytical purposes only.

The creator does not guarantee accuracy or completeness, and is not responsible for trading decisions or losses. Trading involves substantial risk. Use at your own risk and only trade with capital you can afford to lose.

면책사항

해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.