RSI BandsOverview
The RSI Bands indicator is a tool designed to calculate and display overbought, oversold, and middle bands based on the Relative Strength Index (RSI).
Its primary purpose is to provide traders with a clue on whether to place limit buy or limit sell orders, or to set stop-loss orders effectively. The bands represent the price levels the asset must reach for the RSI to align with specific thresholds:
Overbought Band: Displays the upper band representing the price level the asset must reach for the RSI to become overbought.
Oversold Band: Displays the lower band representing the price level the asset must reach for the RSI to become oversold.
Middle Band: Displays the middle band representing the price level the asset must reach for the RSI to hit the middle level. It uses both traditional RSI calculations and a dynamic period adjustment mechanism for improved adaptability to market conditions. The script also offers smoothing options for the bands.
Features
Calculates overbought, oversold, and middle bands using RSI values.
Dynamically adjusts the RSI period based on pivot points if enabled.
Offers smoothing options for the bands: EMA, SMA, or None.
Customizable input parameters for flexibility.
Inputs
Source Value: Selects the data source (e.g., close price) for RSI calculation.
Period: Sets the static RSI calculation period. Used if dynamic period is disabled.
Use Dynamic Period?: Toggles the use of a dynamic RSI period.
Pivot Left/Right Length: Determines the range of bars for pivot detection when using dynamic periods.
Dynamic Period Multiplier: Scales the dynamically calculated RSI period.
Overbought Level: RSI level that marks the overbought threshold.
Oversold Level: RSI level that marks the oversold threshold.
Middle Level: RSI level used as a midpoint reference.
Smoothing Type: Specifies the smoothing method for the bands (EMA, SMA, or None).
Smoothing Length: Length used for the selected smoothing method.
Key Calculations
RSI Calculation:
Computes RSI using gains and losses over the specified period (dynamic or static).
Incorporates a custom function for calculating RSI with dynamic periods.
Dynamic Period Adjustment:
Uses pivot points to determine an adaptive RSI period.
Multiplies the base dynamic period by the Dynamic Period Multiplier.
Band Calculation:
Calculates price changes (deltas) required to achieve the overbought, oversold, and middle RSI levels.
The price changes (deltas) are determined using an iterative approximation technique. For each target RSI level (overbought, oversold, or middle), the script estimates the required change in price by adjusting a hypothetical delta value until the calculated RSI aligns with the target RSI. This approximation ensures precise calculation of the price levels necessary for the RSI to reach the specified thresholds.
Computes the upper (overbought), lower (oversold), and middle bands by adding these deltas to the source price.
Smoothing:
Applies the selected smoothing method (EMA or SMA) to the calculated bands.
Plots
Overbought Band: Displays the upper band representing the price level the asset must reach for the RSI to become overbought.
Oversold Band: Displays the lower band representing the price level the asset must reach for the RSI to become oversold.
Middle Band: Displays the middle band representing the price level the asset must reach for the RSI to hit the middle level.
Usage
Choose the source value (e.g., close price).
Select whether to use a dynamic RSI period or a static one.
Adjust pivot lengths and multipliers for dynamic period calculation as needed.
Set the overbought, oversold, and middle RSI levels based on your analysis.
Configure smoothing options for the bands.
Observe the plotted bands and use them to identify potential overbought and oversold market conditions.
Crimsonvault
Adaptive MAAdaptive Moving Average (AMA)
Overview
The Adaptive Moving Average (AMA) script is designed to calculate and plot a moving average that adapts dynamically based on market conditions. This script uses pivot-based periods for its calculation, allowing it to adjust its behavior in response to market volatility and trends. It supports both Simple Moving Average (SMA) and Exponential Moving Average (EMA).
Features
Dynamic Period Calculation: Leverages the DynamicPeriodPublic library to compute periods based on pivot points, providing an adaptive length for the moving average.
Customizable Parameters: Users can choose predefined "Fast" and "Slow" settings or manually configure the parameters for greater control.
Supports SMA and EMA: Flexibility to choose between SMA and EMA for the moving average calculation.
Inputs
Source ( src ): Data source for the moving average (e.g., close price).
Default: close
Length Type ( length_type ): Determines the type of period calculation.
Options: Fast, Slow, Manual
MA Type ( ma_type ): Specifies the type of moving average to calculate.
Options: SMA, EMA
Manual Parameters (used when length_type is set to Manual):
Left Bars ( left_bars ): Number of left-hand bars for pivot detection.
Right Bars ( right_bars ): Number of right-hand bars for pivot detection.
Number of Pivots ( num_pivots ): Minimum number of pivots for dynamic period calculation.
Length Multiplier ( length_mult ): Multiplier applied to the calculated period.
Use Cases
Trend Analysis: Identify market trends with an average that adapts to changing conditions.
Volatility-Based Strategies: Adjust strategies dynamically in response to market volatility.
Custom Configurations: Fine-tune pivot parameters for specific markets or assets using the "Manual" mode.
Example Usage
Select the desired length type (Fast, Slow, or Manual).
If Manual is selected, configure the pivot detection parameters and length multiplier.
Choose the moving average type (SMA or EMA).
Observe the adaptive moving average plotted on the chart.
DynamicPeriodPublicDynamic Period Calculation Library
This library provides tools for adaptive period determination, useful for creating indicators or strategies that automatically adjust to market conditions.
Overview
The Dynamic Period Library calculates adaptive periods based on pivot points, enabling the creation of responsive indicators and strategies that adjust to market volatility.
Key Features
Dynamic Periods: Computes periods using distances between pivot highs and lows.
Customizable Parameters: Users can adjust detection settings and period constraints.
Robust Handling: Includes fallback mechanisms for cases with insufficient pivot data.
Use Cases
Adaptive Indicators: Build tools that respond to market volatility by adjusting their periods dynamically.
Dynamic Strategies: Enhance trading strategies by integrating pivot-based period adjustments.
Function: `dynamic_period`
Description
Calculates a dynamic period based on the average distances between pivot highs and lows.
Parameters
`left` (default: 5): Number of left-hand bars for pivot detection.
`right` (default: 5): Number of right-hand bars for pivot detection.
`numPivots` (default: 5): Minimum pivots required for calculation.
`minPeriod` (default: 2): Minimum allowed period.
`maxPeriod` (default: 50): Maximum allowed period.
`defaultPeriod` (default: 14): Fallback period if no pivots are found.
Returns
A dynamic period calculated based on pivot distances, constrained by `minPeriod` and `maxPeriod`.
Example
//@version=6
import CrimsonVault/DynamicPeriodPublic/1
left = input.int(5, "Left bars", minval = 1)
right = input.int(5, "Right bars", minval = 1)
numPivots = input.int(5, "Number of Pivots", minval = 2)
period = DynamicPeriodPublic.dynamic_period(left, right, numPivots)
plot(period, title = "Dynamic Period", color = color.blue)
Implementation Notes
Pivot Detection: Requires sufficient historical data to identify pivots accurately.
Edge Cases: Ensures a default period is applied when pivots are insufficient.
Constraints: Limits period values to a user-defined range for stability.