Entropy Chart Analysis [PhenLabs]📊 Entropy Chart analysis -
Version: PineScript™ v6
📌 Description
The Entropy Chart indicator analysis applies Approximate Entropy (ApEn) to identify zones of potential support and resistance on your price chart. It is designed to locate changes in the market’s predictability, with a focus on zones near significant psychological price levels (e.g., multiples of 50). By quantifying entropy, the indicator aims to identify zones where price action might stabilize (potential support) or become randomized (potential resistance).
This tool automates the visualization of these key areas for traders, which may have the effect of revealing reversal levels or consolidation zones that would be hard to discern through traditional means. It also filters the signals by proximity to key levels in an attempt to reduce noise and highlight higher-probability setups. These dynamic zones adapt to changing market conditions by stretching, merging, and expiring based on user-inputted rules.
🚀 Points of Innovation
Combines Approximate Entropy (ApEn) calculation with price action near significant levels.
Filters zone signals based on proximity (in ticks) to predefined significant price levels (multiples of 50).
Dynamically merges overlapping or nearby zones to consolidate signals and reduce chart clutter.
Uses ApEn crossovers relative to its moving average as the core trigger mechanism.
Provides distinct visual coloring for bullish, bearish, and merged (mixed-signal) zones.
Offers comprehensive customization for entropy calculation, zone sensitivity, level filtering, and visual appearance.
🔧 Core Components
Approximate Entropy (ApEn) Calculation : Measures the regularity or randomness of price fluctuations over a specified window. Low ApEn suggests predictability, while high ApEn suggests randomness.
Zone Trigger Logic : Creates potential support zones when ApEn crosses below its average (indicating increasing predictability) and potential resistance zones when it crosses above (indicating increasing randomness).
Significant Level Filter : Validates zone triggers only if they occur within a user-defined tick distance from significant price levels (multiples of 50).
Dynamic Zone Management : Automatically creates, extends, merges nearby zones based on tick distance, and removes the oldest zones to maintain a maximum limit.
Zone Visualization : Draws and updates colored boxes on the chart to represent active support, resistance, or mixed zones.
🔥 Key Features
Entropy-Based S/R Detection : Uses ApEn to identify potential support (low entropy) and resistance (high entropy) areas.
Significant Level Filtering : Enhances signal quality by focusing on entropy changes near key psychological price points.
Automatic Zone Drawing & Merging : Visualizes zones dynamically, merging close signals for clearer interpretation.
Highly Customizable : Allows traders to adjust parameters for ApEn calculation, zone detection thresholds, level filter sensitivity, merging distance, and visual styles.
Integrated Alerts : Provides built-in alert conditions for the formation of new bullish or bearish zones near significant levels.
Clear Visual Output : Uses distinct, customizable colors for buy (support), sell (resistance), and mixed (merged) zones.
🎨 Visualization
Buy Zones : Represented by greenish boxes (default: #26a69a), indicating potential support areas formed during low entropy periods near significant levels.
Sell Zones : Represented by reddish boxes (default: #ef5350), indicating potential resistance areas formed during high entropy periods near significant levels.
Mixed Zones : Represented by bluish/purple boxes (default: #8894ff), formed when a buy zone and a sell zone merge, indicating areas of potential consolidation or conflict.
Dynamic Extension : Active zones are automatically extended to the right with each new bar.
📖 Usage Guidelines
Calculation Parameters
Window Length
Default: 15
Range: 10-100
Description: Lookback period for ApEn calculation. Shorter lengths are more responsive; longer lengths are smoother.
Embedding Dimension (m)
Default: 2
Range: 1-6
Description: Length of patterns compared in ApEn calculation. Higher values detect more complex patterns but require more data.
Tolerance (r)
Default: 0.5
Range: 0.1-1.0 (step 0.1)
Description: Sensitivity factor for pattern matching (as a multiple of standard deviation). Lower values require closer matches (more sensitive).
Zone Settings
Zone Lookback
Default: 5
Range: 5-50
Description: Lookback period for the moving average of ApEn used in threshold calculations.
Zone Threshold
Default: 0.5
Range: 0.5-3.0
Description: Multiplier for the ApEn average to set crossover trigger levels. Higher values require larger ApEn deviations to create zones.
Maximum Zones
Default: 5
Range: 1-10
Description: Maximum number of active zones displayed. The oldest zones are removed first when the limit is reached.
Zone Merge Distance (Ticks)
Default: 5
Range: 1-50
Description: Maximum distance in ticks for two separate zones to be merged into one.
Level Filter Settings
Tick Size
Default: 0.25
Description: The minimum price increment for the asset. Must be set correctly for the specific instrument to ensure accurate level filtering.
Max Ticks Distance from Levels
Default: 40
Description: Maximum allowed distance (in ticks) from a significant level (multiple of 50) for a zone trigger to be valid.
Visual Settings
Buy Zone Color : Default: color.new(#26a69a, 83). Sets the fill color for support zones.
Sell Zone Color : Default: color.new(#ef5350, 83). Sets the fill color for resistance zones.
Mixed Zone Color : Default: color.new(#8894ff, 83). Sets the fill color for merged zones.
Buy Border Color : Default: #26a69a. Sets the border color for support zones.
Sell Border Color : Default: #ef5350. Sets the border color for resistance zones.
Mixed Border Color : Default: color.new(#a288ff, 50). Sets the border color for mixed zones.
Border Width : Default: 1, Range: 1-3. Sets the thickness of zone borders.
✅ Best Use Cases
Identifying potential support/resistance near significant psychological price levels (e.g., $50, $100 increments).
Detecting potential market turning points or consolidation zones based on shifts in price predictability.
Filtering entries or exits by confirming signals occurring near significant levels identified by the indicator.
Adding context to other technical analysis approaches by highlighting entropy-derived zones.
⚠️ Limitations
Parameter Dependency : Indicator performance is sensitive to parameter settings ( Window Length , Tolerance , Zone Threshold , Max Ticks Distance ), which may need optimization for different assets and timeframes.
Volatility Sensitivity : High market volatility or erratic price action can affect ApEn calculations and potentially lead to less reliable zone signals.
Fixed Level Filter : The significant level filter is based on multiples of 50. While common, this may not capture all relevant levels for every asset or market condition. Accurate Tick Size input is essential.
Not Standalone : Should be used in conjunction with other analysis methods (price action, volume, other indicators) for confirmation, not as a sole basis for trading decisions.
💡 What Makes This Unique
Entropy + Level Context : Uniquely combines ApEn analysis with a specific filter for proximity to significant price levels (multiples of 50), adding locational context to entropy signals.
Intelligent Zone Merging : Automatically consolidates nearby buy/sell zones based on tick distance, simplifying visual analysis and highlighting stronger confluence areas.
Targeted Signal Generation : Focuses alerts and zone creation on specific market conditions (entropy shifts near key levels).
🔬 How It Works
Calculate Entropy : The script computes the Approximate Entropy (ApEn) of the closing prices over the defined Window Length to quantify price predictability.
Check Triggers : It monitors ApEn relative to its moving average. A crossunder below a calculated threshold (avg_apen / zone_threshold) indicates potential support; a crossover above (avg_apen * zone_threshold) indicates potential resistance.
Filter by Level : A potential zone trigger is confirmed only if the low (for support) or high (for resistance) of the trigger bar is within the Max Ticks Distance of a significant price level (multiple of 50).
Manage & Draw Zones : If a trigger is confirmed, a new zone box is created. The script checks for overlaps with existing zones within the Zone Merge Distance and merges them if necessary. Zones are extended forward, and the oldest are removed to respect the Maximum Zones limit. Active zones are drawn and updated on the chart.
💡 Note:
Crucially, set the Tick Size parameter correctly for your specific trading instrument in the “Level Filter Settings”. Incorrect Tick Size will make the significant level filter inaccurate.
Experiment with parameters, especially Window Length , Tolerance (r) , Zone Threshold , and Max Ticks Distance , to tailor the indicator’s sensitivity to your preferred asset and timeframe.
Always use this indicator as part of a comprehensive trading plan, incorporating risk management and seeking confirmation from other analysis techniques.
Approximation
Profitability Visualization with Bid-Ask Spread ApproximationOverview
The " Profitability Visualization with Bid-Ask Spread Approximation " indicator is designed to assist traders in assessing potential profit and loss targets in relation to the current market price or a simulated entry price. It provides flexibility by allowing users to choose between two methods for calculating the offset from the current price:
Bid-Ask Spread Approximation: The indicator attempts to estimate the bid-ask spread by using the highest (high) and lowest (low) prices within a given period (typically the current bar or a user-defined timeframe) as proxies for the ask and bid prices, respectively. This method provides a dynamic offset that adapts to market volatility.
Percentage Offset: Alternatively, users can specify a fixed percentage offset from the current price. This method offers a consistent offset regardless of market conditions.
Key Features
Dual Offset Calculation Methods: Choose between a dynamic bid-ask spread approximation or a fixed percentage offset to tailor the indicator to your trading style and market analysis.
Entry Price Consideration: The indicator can simulate an entry price at the beginning of each trading session (or the first bar on the chart if no sessions are defined). This feature enables a more realistic visualization of potential profit and loss levels based on a hypothetical entry point.
Profit and Loss Targets: When the entry price consideration is enabled, the indicator plots profit target (green) and loss target (red) lines. These lines represent the price levels at which a trade entered at the simulated entry price would achieve a profit or incur a loss equivalent to the calculated offset amount.
Offset Visualization: Regardless of whether the entry price is considered, the indicator always displays upper (aqua) and lower (fuchsia) offset lines. These lines represent the calculated offset levels based on the chosen method (bid-ask approximation or percentage offset).
Customization: Users can adjust the percentage offset, toggle the bid-ask approximation and entry price consideration, and customize the appearance of the lines through the indicator's settings.
Inputs
useBidAskApproximation A boolean (checkbox) input that determines whether to use the bid-ask spread approximation (true) or the percentage offset (false). Default is false.
percentageOffset A float input that allows users to specify the percentage offset to be used when useBidAskApproximation is false. The default value is 0.63.
considerEntryPrice A boolean input that enables the consideration of a simulated entry price for calculating and displaying profit and loss targets. Default is true.
Calculations
Bid-Ask Approximation (if enabled): bidApprox = request.security(syminfo.tickerid, timeframe.period, low) Approximates the bid price using the lowest price (low) of the current period. askApprox = request.security(syminfo.tickerid, timeframe.period, high) Approximates the ask price using the highest price (high) of the current period. spreadApprox = askApprox - bidApprox Calculates the approximate spread.
Offset Amount: offsetAmount = useBidAskApproximation ? spreadApprox / 2 : close * (percentageOffset / 100) Determines the offset amount based on the selected method. If useBidAskApproximation is true, the offset is half of the approximated spread; otherwise, it's the current closing price (close) multiplied by the percentageOffset.
Entry Price (if enabled): var entryPrice = 0.0 Initializes a variable to store the entry price. if considerEntryPrice Checks if entry price consideration is enabled. if barstate.isnew Checks if the current bar is the first bar of a new session. entryPrice := close Sets the entryPrice to the closing price of the first bar of the session.
Profit and Loss Targets (if entry price is considered): profitTarget = entryPrice + offsetAmount Calculates the profit target price level. lossTarget = entryPrice - offsetAmount Calculates the loss target price level.
Plotting
Profit Target Line: Plotted in green (color.green) with a dashed line style (plot.style_linebr) and increased linewidth (linewidth=2) when considerEntryPrice is true.
Loss Target Line: Plotted in red (color.red) with a dashed line style (plot.style_linebr) and increased linewidth (linewidth=2) when considerEntryPrice is true.
Upper Offset Line: Always plotted in aqua (color.aqua) to show the offset level above the current price.
Lower Offset Line: Always plotted in fuchsia (color.fuchsia) to show the offset level below the current price.
Limitations
Approximation: The bid-ask spread approximation is based on high and low prices and may not perfectly reflect the actual bid-ask spread of a specific broker, especially during periods of high volatility or low liquidity.
Simplified Entry: The entry price simulation is basic and assumes entry at the beginning of each session. It does not account for specific entry signals or order types.
No Order Execution: This indicator is purely for visualization and does not execute any trades.
Data Discrepancies: The high and low values used for approximation might not always align with real-time bid and ask prices due to differences in data aggregation and timing between TradingView and various brokers.
Disclaimer
This indicator is for educational and informational purposes only and should not be considered financial advice. Trading involves substantial risk, and past performance is not indicative of future results. Always conduct thorough research and consider your own risk tolerance before making any trading decisions. It is recommended to combine this indicator with other technical analysis tools and a well-defined trading strategy.
fastlog2Library "fastlog2"
Description:
Returns the approximation of Log2 with the maximal error of: 0.000061011436
Reference:
www.anycodings.com
fastlog2(x)
Returns the approximation of Log2 with the maximal error of: 0.000061011436
Parameters:
x : float
Returns: float, log2 of x