Optimal Length BackTester [YinYangAlgorithms]This Indicator allows for a ‘Optimal Length’ to be inputted within the Settings as a Source. Unlike most Indicators and/or Strategies that rely on either Static Lengths or Internal calculations for the length, this Indicator relies on the Length being derived from an external Indicator in the form of a Source Input.
This may not sound like much, but this application may allows limitless implementations of such an idea. By allowing the input of a Length within a Source Setting you may have an ‘Optimal Length’ that adjusts automatically without the need for manual intervention. This may allow for Traditional and Non-Traditional Indicators and/or Strategies to allow modifications within their settings as well to accommodate the idea of this ‘Optimal Length’ model to create an Indicator and/or Strategy that adjusts its length based on the top performing Length within the current Market Conditions.
This specific Indicator aims to allow backtesting with an ‘Optimal Length’ inputted as a ‘Source’ within the Settings.
This ‘Optimal Length’ may be used to display and potentially optimize multiple different Traditional Indicators within this BackTester. The following Traditional Indicators are included and available to be backtested with an ‘Optimal Length’ inputted as a Source in the Settings:
Moving Average; expressed as either a: Simple Moving Average, Exponential Moving Average or Volume Weighted Moving Average
Bollinger Bands; expressed based on the Moving Average Type
Donchian Channels; expressed based on the Moving Average Type
Envelopes; expressed based on the Moving Average Type
Envelopes Adjusted; expressed based on the Moving Average Type
All of these Traditional Indicators likewise may be displayed with multiple ‘Optimal Lengths’. They have the ability for multiple different ‘Optimal Lengths’ to be inputted and displayed, such as:
Fast Optimal Length
Slow Optimal Length
Neutral Optimal Length
By allowing for the input of multiple different ‘Optimal Lengths’ we may express the ‘Optimal Movement’ of such an expressed Indicator based on different Time Frames and potentially also movement based on Fast, Slow and Neutral (Inclusive) Lengths.
This in general is a simple Indicator that simply allows for the input of multiple different varieties of ‘Optimal Lengths’ to be displayed in different ways using Tradition Indicators. However, the idea and model of accepting a Length as a Source is unique and may be adopted in many different forms and endless ideas.
Tutorial:
You may add an ‘Optimal Length’ within the Settings as a ‘Source’ as followed in the example above. This Indicator allows for the input of a:
Neutral ‘Optimal Length’
Fast ‘Optimal Length’
Slow ‘Optimal Length’
It is important to account for all three as they generally encompass different min/max length values and therefore result in varying ‘Optimal Length’s’.
For instance, say you’re calculating the ‘Optimal Length’ and you use:
Min: 1
Max: 400
This would therefore be scanning for 400 (inclusive) lengths.
As a general way of calculating you may assume the following for which lengths are being used within an ‘Optimal Length’ calculation:
Fast: 1 - 199
Slow: 200 - 400
Neutral: 1 - 400
This allows for the calculation of a Fast and Slow length within the predetermined lengths allotted. However, it likewise allows for a Neutral length which is inclusive to all lengths alloted and may be deemed the ‘Most Accurate’ for these reasons. However, just because the Neutral is inclusive to all lengths, doesn’t mean the Fast and Slow lengths are irrelevant. The Fast and Slow length inputs may be useful for seeing how specifically zoned lengths may fair, and likewise when they cross over and/or under the Neutral ‘Optimal Length’.
This Indicator features the ability to display multiple different types of Traditional Indicators within the ‘Display Type’.
We will go over all of the different ‘Display Types’ with examples on how using a Fast, Slow and Neutral length would impact it:
Simple Moving Average:
In this example above have the Fast, Slow and Neutral Optimal Length formatted as a Slow Moving Average. The first example is on the 15 minute Time Frame and the second is on the 1 Day Time Frame, demonstrating how the length changes based on the Time Frame and the effects it may have.
Here we can see that by inputting ‘Optimal Lengths’ as a Simple Moving Average we may see moving averages that change over time with their ‘Optimal Lengths’. These lengths may help identify Support and/or Resistance locations. By using an 'Optimal Length' rather than a static length, we may create a Moving Average which may be more accurate as it attempts to be adaptive to current Market Conditions.
Bollinger Bands:
Bollinger Bands are a way to see a Simple Moving Average (SMA) that then uses Standard Deviation to identify how much deviation has occurred. This Deviation is then Added and Subtracted from the SMA to create the Bollinger Bands which help Identify possible movement zones that are ‘within range’. This may mean that the price may face Support / Resistance when it reaches the Outer / Inner bounds of the Bollinger Bands. Likewise, it may mean the Price is ‘Overbought’ when outside and above or ‘Underbought’ when outside and below the Bollinger Bands.
By applying All 3 different types of Optimal Lengths towards a Traditional Bollinger Band calculation we may hope to see different ranges of Bollinger Bands and how different lookback lengths may imply possible movement ranges on both a Short Term, Long Term and Neutral perspective. By seeing these possible ranges you may have the ability to identify more levels of Support and Resistance over different lengths and Trading Styles.
Donchian Channels:
Above you’ll see two examples of Machine Learning: Optimal Length applied to Donchian Channels. These are displayed with both the 15 Minute Time Frame and the 1 Day Time Frame.
Donchian Channels are a way of seeing potential Support and Resistance within a given lookback length. They are a way of withholding the High’s and Low’s of a specific lookback length and looking for deviation within this length. By applying a Fast, Slow and Neutral Machine Learning: Optimal Length to these Donchian Channels way may hope to achieve a viable range of High’s and Low’s that one may use to Identify Support and Resistance locations for different ranges of Optimal Lengths and likewise potentially different Trading Strategies.
Envelopes / Envelopes Adjusted:
Envelopes are an interesting one in the sense that they both may be perceived as useful; however we deem that with the use of an ‘Optimal Length’ that the ‘Envelopes Adjusted’ may work best. We will start with examples of the Traditional Envelope then showcase the Adjusted version.
Envelopes:
As you may see, a Traditional form of Envelopes even produced with a Machine Learning: Optimal Length may not produce optimal results. Unfortunately this may occur with some Traditional Indicators and they may need some adjustments as you’ll notice with the ‘Envelopes Adjusted’ version. However, even without the adjustments, these Envelopes may be useful for seeing ‘Overbought’ and ‘Oversold’ locations within a Machine Learning: Optimal Length standpoint.
Envelopes Adjusted:
By adding an adjustment to these Envelopes, we may hope to better reflect our Optimal Length within it. This is caused by adding a ratio reflection towards the current length of the Optimal Length and the max Length used. This allows for the Fast and Neutral (and potentially Slow if Neutral is greater) to achieve a potentially more accurate result.
Envelopes, much like Bollinger Bands are a way of seeing potential movement zones along with potential Support and Resistance. However, unlike Bollinger Bands which are based on Standard Deviation, Envelopes are based on percentages +/- from the Simple Moving Average.
We will conclude our Tutorial here. Hopefully this has given you some insight into how useful adding a ‘Optimal Length’ within an external (secondary) Indicator as a Source within the Settings may be. Likewise, how useful it may be for automation sake in the sense that when the ‘Optimal Length’ changes, it doesn’t rely on an alert where you need to manually update it yourself; instead it will update Automatically and you may reap the benefits of such with little manual input needed (aside from the initial setup).
If you have any questions, comments, ideas or concerns please don't hesitate to contact us.
HAPPY TRADING!

# Length

TurntLibraryLibrary "TurntLibrary"
Collection of functions created for simplification/easy referencing. Includes variations of moving averages, length value oscillators, and a few other simple functions based upon HH/LL values.
ma(source, length, type)
Apply a moving average to a float value
Parameters:
source : Value to be used
length : Number of bars to include in calculation
type : Moving average type to use ("SMA","EMA","RMA","WMA","VWAP","SWMA","LRC")
Returns: Smoothed value of initial float value
curve(src, len, lb1, lb2)
Exaggerates curves of a float value designed for use as an exit signal.
Parameters:
src : Initial value to curve
len : Number of bars to include in calculation
lb1 : (Default = 1) First lookback length
lb2 : (Default = 2) Second lookback length
Returns: Curved Average
fragma(src, len, space, str)
Average of a moving average and the previous value of the moving average
Parameters:
src : Initial float value to use
len : Number of bars to include in calculation
space : Lookback integer for second half of average
str : Moving average type to use ("SMA","EMA","RMA","WMA","VWAP","SWMA","LRC")
Returns: Fragmented Average
maxmin(x, y)
Difference of 2 float values, subtracting the lowest from the highest
Parameters:
x : Value 1
y : Value 2
Returns: The +Difference between 2 float values
oscLen(val, type)
Variable Length using a oscillator value and a corresponding slope shape ("Incline",Decline","Peak","Trough")
Parameters:
val : Oscillator Value to use
type : Slope of length curve ("Incline",Decline","Peak","Trough")
Returns: Variable Length Integer
hlAverage(val, smooth, max, min, type, include)
Average of HH,LL with variable lengths based on the slope shape ("Incline","Decline","Trough") value relative to highest and lowest
Parameters:
val : Source Value to use
smooth
max
min
type
include : Add "val" to the averaging process, instead of more weight to highest or lowest value
Returns: Variable Length Average of Highest Lowest "val"
pct(val)
Convert a positive float / price to a percentage of it's highest value on record
Parameters:
val : Value To convert to a percentage of it's highest value ever
Returns: Percentage
hlrange(x, len)
Difference between Highest High and Lowest Low of float value
Parameters:
x : Value to use in calculation
len : Number of bars to include in calculation
Returns: Difference
midpoint(x, len, smooth)
The average value of the float's Highest High and Lowest Low in a number of bars
Parameters:
x : Value to use in calculation
len
smooth : (Default=na) Optional smoothing type to use ("SMA","EMA","RMA","WMA","VWAP","SWMA","LRC")
Returns: Midpoint

Dynamic Highest Lowest Moving AverageSimilar to my last script, although this one uses the RSI value of
(highest high - price) / (price - lowest low)
to feed into the the logic creating the dynamic length. Choose how the length curve works by selecting either Incline, Decline, Peak or Trough.
Lastly select the moving average type to filter the result through to smoothen things out a bit
to find something that works for your strategy. This is useful as an entry/exit indicator along with other moving averages, or even just a standalone if you play with the settings enough.

Oscillating Length Moving Averages***CREDIT TO TradingView's TA Library*** (), Attempted to use "import TradingView/ta/4" to import the library, but for whatever reason
some of the functions failed to work, while others had no issue, so I opted to just copy paste what I wanted to use.
This moving average uses an oscillator to influence the length used during calculation. Extremely customizable/tunable with ability to change Max and Min length values, length multiplier, length multiple,4 different settings ,( Decline , <>Peak, >Decline , <>Peak, ><Trough
step6:Select Final Filtering method
step7:plot

Feature scalerFeature scaler | Pine Utilities series, ready to be used in "study-on-study" fashion |
Includes min-max, normalization, standardization and unit length scaling.
One and only source: en.wikipedia.org
Endpoint inputs allow to set an interval of interest for min-max scaler.
Can be (and should be) applied to other studies, or to the chart itself. In this example, I applied min-max scaling to weighted linear regression's slope values.
Unfortunately, "All data" is still "experimental" and works only on charts where less than 5000 bars are available. max_bars_back() didn't help.
Sup TV

RSI Multi Length [LuxAlgo]The following indicator aims to return information over RSIs using multiple periods, including the percentage of RSIs of different periods being overbought/oversold, as well as the average between these multiple RSIs.
The percentage of RSIs of different periods being overbought/oversold is additionally used to return adaptive overbought/oversold levels.
Settings
Maximum Length: Maximum period of the RSI used for the indicator calculation
Minimum Length: Minimum period value of the RSI used for the indicator calculation
Overbought: Value of the overbought level
Oversold: Value of the oversold level
Src: Input source of the indicator
Usage
The main element of the indicator is given by the multi-length RSI average, returning an oscillator similar to a fixed-length RSI. Because of its multiple length nature, the indicator can reflect shorter to longer-term price variations depending on the Maximum/Minimum length range defined by the user.
The green area indicates the percentage of RSIs over the user-defined overbought level. The red area indicates the percentage of RSIs under the user-defined oversold level, this percentage is inverted for ease of visualization. Additionally, a dashboard at the top right of the indicator pane indicates these percentages for the most recent bar.
A lower percentage of overbought/oversold RSIs can indicate a potential shorter-term retracement.
These percentages are used to construct adaptive overbought/oversold levels for the average multi-length RSI. The overbought level will be easier to reach if the percentage of overbought RSI's is high, the same logic applies to the adaptive oversold level.

Range Adaptive EMA Float Series Inputuses range and change distance on arrays to allow for more control as well as any choice of input value as a controller for how tightly it grips the input signal.

ATR Break-Out - evoThis script measures candle length and average true range (ATR). A break out occurs when a candle is larger than the given ATR value. You can choose to calculate length from wicks or from the body (open & close).
You can use this as trend direction indicator by following the last break out candle or open a position after a break out with a stop just above or below the candle. Enjoy!

Ranged Candle Length - evoSimilar to one of my previous scripts 'Ranged Volume', but instead of using volume, this script uses candle length mirrored. It creates a range using highest and lowest of a given period. When the range gets larger, it means the current candle is bigger than the largest candle of your given period (break-out).
Yellow = Bullish break out
Red = Bearish break out
A good way to use this is to follow the direction of the last break-out candle or open a position with a stop just below or above the candle (that's how I tested it real time).
Good luck!

Variable Length Moving AverageThe Variable Length Moving Average was created by George R. Arrington Ph.D. (Stocks & Commodities V. 9:6 (219-223)) and I'm really loving this indicator. It is a great moving average that hugs the price very closely and it is fully adjustable to your needs. It detects signals extremely well and I have color coded the moving average line to make it very easy to interpret.
This is not to be confused with the Variable Moving Average created by Tushar S. Chande and as of now I haven't seen any other script for this moving average out there yet.
Please let me know if you would like me to write any other scripts for indicators you would like to see!

Minkowski Distance Factor Adaptive Period MACDHi, this script comes from the idea that Ricardo Santos' Minkovski Distance Function is transferred to the period as a factor.
Minkowski distance is used as a percentage factor with the help of Relative Strength Index function.
Minkowski Distance Function Script :
And thus an adaptive MACD was created.
This script can give much better results in more optimized larger periods.
I leave the decision to determine the periods and weights.
I used the weights of 9,12,26 and periods created with multiplied by factor.
Regards.

Average Candle Length 2.0This script will tell you the following:
• Average length of all the candles (wick to wick) for the last 20 candles
-- shown in blue
• Average length of bull (green) candles (wick to wick) for the last 20 candles
-- shown in green
• Average length of bear (red) candles (wick to wick) for the last 20 candles
-- shown in red
___________________________________________
Inputs:
• # of Candles to analyze (default = 20)

IO_CWL IndexCandlestick body and Wick Length Index (CWL)
Shows a trend chart of candle body length and wick length.
Green -> Candle body
Red -> Candle Wick
-- Invsto

Missile RSI (RSI of momentum w/ Dominant Cycle length + Fisher)This is a predictive indicator that looks for explosions in momentum of the cycles in price and large shifts in Momentum (Fisher turns the Bimodal PDF into Guassian like) as statistically unlikely events, showing points to exit or reverse positions.
You can adjust the lowpass frequency cuttoff (Aka what cycles you want to remove from the calculations through the super smoother filter).
To be honest you can monkey trade the direction of the Signal if you'd like but the Divergences and Maxing of the values is whats most useful.
Let me know if you guys want me to add anything else.

Impulses-1Lines "Total Up Impulses" and "Total Down Impulses" are the sum of impulses in the last n periods (Length).
line 1 => "Total Up Impulses": the sum of up impulses.
line 2 => "Total Down Impulses": the sum of down impulses.
When line 1 crosses up line 2, it indicates an uptrend is comming out.
When line 1 crosses down line 2, it indicates a downtrend is comming out.

Bran's 8 Length SMAAll the SMAs you could ever want in a single indicator. Customizable, versatile and great for TAs who don't want to eat up their indicators with a bunch of custom SMA lines.