HTF Candles Overlay [Trendoscope®]🎲 HTF Candles Overlay is a simple indicator where you can overlay higher timeframe candles on current timeframe chart.
Most of the code is encapsulated in the library HTFCandlesLib . After publishing the library as open source, many people requested to convert that into an indicator. Based on this, we decided to publish this small code for the use of community.
🎯 Usage
The indicator is simple, it helps users visualise higher timeframe candles. We majorly use this for debugging or validating our implementations based on higher timeframe. Instead of switching back and forth to different timeframes, it helps us visualise higher timeframe candles on the same chart when we are validating the implementation that involves higher timeframe calculations.
🎯 Components
The indicator provides two types of displays
Candles - overlay candles built through lines and labels
Plot - close price of higher timeframe plotted on chart
🎯 Candles
The behaviour of the candles are similar to that of hollow candles. The color of the body and the border+wick demonstrates the movement of the candle.
Body color is lime if the HTF close is higher than HTF open. Body color is orange if the HTF close is lower than the HTF open.
Wick and border color is lime if HTF close price is higher than previous HTF close price. And they are orange if HTF close price is lower than the previous HTF close price
In most cases body color will be same as the wick color. In case of stocks and indices, it may happen that the open price is too far away from previous close price due to gaps. This can lead to close price being relatively in different direction when compared to open and previous close.
Wicks are not at the centre of the candle. Instead wicks are drawn on the current chart timeframe position where the current timeframe has reached the highest or lowest point within the given HTF candle
Candles also list OHLC price of HTF candle along with HTF bar index and the range of LTF bar index that the candle spawns
Here are some pictorial representations that can help understand better.
Here are the examples of candles with gaps where body and wick/border are in different directions (colours)
🎯 Indicator Settings
Simple settings allow users to select the timeframe, whether to display candles and plots and their specific colors.
🎯 Possible inconsistencies
The overlay can show inconsistent data in certain situations. Here are some of the scenarios where the indicator may not show consistent display of the data.
When the HTF data from request.security does not match that of combined LTF data . In such cases, HTF candles may not form inline with the current timeframe candles. This happens when there is a data issue of different OHLC data available in tradingview.
When using weekly candle as either chart timeframe or higher timeframe - end of week may not coincide with end of month or other timeframes. This can cause some inconsistencies in the visuals of the indicator.
When open and close time of either LTF or HTF falls under different day due to time zone used. - time is always the time on which the candle close. So, when we use time zone that causes the exchange day to open and close on different days, that can cause some inconsistencies in the candles being drawn.
Trendoscope
supertrendLibrary "supertrend"
supertrend : Library dedicated to different variations of supertrend
supertrend_atr(length, multiplier, atrMaType, source, highSource, lowSource, waitForClose, delayed)
supertrend_atr: Simple supertrend based on atr but also takes into consideration of custom MA Type, sources
Parameters:
length (simple int) : : ATR Length
multiplier (simple float) : : ATR Multiplier
atrMaType (simple string) : : Moving Average type for ATR calculation. This can be sma, ema, hma, rma, wma, vwma, swma
source (float) : : Default is close. Can Chose custom source
highSource (float) : : Default is high. Can also use close price for both high and low source
lowSource (float) : : Default is low. Can also use close price for both high and low source
waitForClose (simple bool) : : Considers source for direction change crossover if checked. Else, uses highSource and lowSource.
delayed (simple bool) : : if set to true lags supertrend atr stop based on target levels.
Returns: dir : Supertrend direction
supertrend : BuyStop if direction is 1 else SellStop
supertrend_bands(bandType, maType, length, multiplier, source, highSource, lowSource, waitForClose, useTrueRange, useAlternateSource, alternateSource, sticky)
supertrend_bands: Simple supertrend based on atr but also takes into consideration of custom MA Type, sources
Parameters:
bandType (simple string) : : Type of band used - can be bb, kc or dc
maType (simple string) : : Moving Average type for Bands. This can be sma, ema, hma, rma, wma, vwma, swma
length (simple int) : : Band Length
multiplier (float) : : Std deviation or ATR multiplier for Bollinger Bands and Keltner Channel
source (float) : : Default is close. Can Chose custom source
highSource (float) : : Default is high. Can also use close price for both high and low source
lowSource (float) : : Default is low. Can also use close price for both high and low source
waitForClose (simple bool) : : Considers source for direction change crossover if checked. Else, uses highSource and lowSource.
useTrueRange (simple bool) : : Used for Keltner channel. If set to false, then high-low is used as range instead of true range
useAlternateSource (simple bool) : - Custom source is used for Donchian Chanbel only if useAlternateSource is set to true
alternateSource (float) : - Custom source for Donchian channel
sticky (simple bool) : : if set to true borders change only when price is beyond borders.
Returns: dir : Supertrend direction
supertrend : BuyStop if direction is 1 else SellStop
supertrend_zigzag(length, history, useAlternativeSource, alternativeSource, source, highSource, lowSource, waitForClose, atrlength, multiplier, atrMaType)
supertrend_zigzag: Zigzag pivot based supertrend
Parameters:
length (simple int) : : Zigzag Length
history (simple int) : : number of historical pivots to consider
useAlternativeSource (simple bool)
alternativeSource (float)
source (float) : : Default is close. Can Chose custom source
highSource (float) : : Default is high. Can also use close price for both high and low source
lowSource (float) : : Default is low. Can also use close price for both high and low source
waitForClose (simple bool) : : Considers source for direction change crossover if checked. Else, uses highSource and lowSource.
atrlength (simple int) : : ATR Length
multiplier (simple float) : : ATR Multiplier
atrMaType (simple string) : : Moving Average type for ATR calculation. This can be sma, ema, hma, rma, wma, vwma, swma
Returns: dir : Supertrend direction
supertrend : BuyStop if direction is 1 else SellStop
zupertrend(length, history, useAlternativeSource, alternativeSource, source, highSource, lowSource, waitForClose, atrlength, multiplier, atrMaType)
zupertrend: Zigzag pivot based supertrend
Parameters:
length (simple int) : : Zigzag Length
history (simple int) : : number of historical pivots to consider
useAlternativeSource (simple bool)
alternativeSource (float)
source (float) : : Default is close. Can Chose custom source
highSource (float) : : Default is high. Can also use close price for both high and low source
lowSource (float) : : Default is low. Can also use close price for both high and low source
waitForClose (simple bool) : : Considers source for direction change crossover if checked. Else, uses highSource and lowSource.
atrlength (simple int) : : ATR Length
multiplier (simple float) : : ATR Multiplier
atrMaType (simple string) : : Moving Average type for ATR calculation. This can be sma, ema, hma, rma, wma, vwma, swma
Returns: dir : Supertrend direction
supertrend : BuyStop if direction is 1 else SellStop
zsupertrend(zigzagpivots, history, source, highSource, lowSource, waitForClose, atrMaType, atrlength, multiplier)
zsupertrend: Same as zigzag supertrend. But, works on already calculated array rather than Calculating fresh zigzag
Parameters:
zigzagpivots (array) : : Precalculated zigzag pivots
history (simple int) : : number of historical pivots to consider
source (float) : : Default is close. Can Chose custom source
highSource (float) : : Default is high. Can also use close price for both high and low source
lowSource (float) : : Default is low. Can also use close price for both high and low source
waitForClose (simple bool) : : Considers source for direction change crossover if checked. Else, uses highSource and lowSource.
atrMaType (simple string) : : Moving Average type for ATR calculation. This can be sma, ema, hma, rma, wma, vwma, swma
atrlength (simple int) : : ATR Length
multiplier (simple float) : : ATR Multiplier
Returns: dir : Supertrend direction
supertrend : BuyStop if direction is 1 else SellStop
taLibrary "ta"
Collection of all custom and enhanced TA indicators
ma(source, maType, length)
returns custom moving averages
Parameters:
source (float) : Moving Average Source
maType (simple string) : Moving Average Type : Can be sma, ema, hma, rma, wma, vwma, swma, highlow, linreg, median
length (simple int) : Moving Average Length
Returns: moving average for the given type and length
atr(maType, length)
returns ATR with custom moving average
Parameters:
maType (simple string) : Moving Average Type : Can be sma, ema, hma, rma, wma, vwma, swma, highlow, linreg, median
length (simple int) : Moving Average Length
Returns: ATR for the given moving average type and length
atrpercent(maType, length)
returns ATR as percentage of close price
Parameters:
maType (simple string) : Moving Average Type : Can be sma, ema, hma, rma, wma, vwma, swma, highlow, linreg, median
length (simple int) : Moving Average Length
Returns: ATR as percentage of close price for the given moving average type and length
bb(source, maType, length, multiplier, sticky)
returns Bollinger band for custom moving average
Parameters:
source (float) : Moving Average Source
maType (simple string) : Moving Average Type : Can be sma, ema, hma, rma, wma, vwma, swma, highlow, linreg, median
length (simple int) : Moving Average Length
multiplier (float) : Standard Deviation multiplier
sticky (simple bool) : - sticky boundaries which will only change when value is outside boundary.
Returns: Bollinger band with custom moving average for given source, length and multiplier
bbw(source, maType, length, multiplier, sticky)
returns Bollinger bandwidth for custom moving average
Parameters:
source (float) : Moving Average Source
maType (simple string) : Moving Average Type : Can be sma, ema, hma, rma, wma, vwma, swma, highlow, linreg, median
length (simple int) : Moving Average Length
multiplier (float) : Standard Deviation multiplier
sticky (simple bool) : - sticky boundaries which will only change when value is outside boundary.
Returns: Bollinger Bandwidth for custom moving average for given source, length and multiplier
bpercentb(source, maType, length, multiplier, sticky)
returns Bollinger Percent B for custom moving average
Parameters:
source (float) : Moving Average Source
maType (simple string) : Moving Average Type : Can be sma, ema, hma, rma, wma, vwma, swma, highlow, linreg, median
length (simple int) : Moving Average Length
multiplier (float) : Standard Deviation multiplier
sticky (simple bool) : - sticky boundaries which will only change when value is outside boundary.
Returns: Bollinger Percent B for custom moving average for given source, length and multiplier
kc(source, maType, length, multiplier, useTrueRange, sticky)
returns Keltner Channel for custom moving average
Parameters:
source (float) : Moving Average Source
maType (simple string) : Moving Average Type : Can be sma, ema, hma, rma, wma, vwma, swma, highlow, linreg, median
length (simple int) : Moving Average Length
multiplier (float) : Standard Deviation multiplier
useTrueRange (simple bool) : - if set to false, uses high-low.
sticky (simple bool) : - sticky boundaries which will only change when value is outside boundary.
Returns: Keltner Channel for custom moving average for given souce, length and multiplier
kcw(source, maType, length, multiplier, useTrueRange, sticky)
returns Keltner Channel Width with custom moving average
Parameters:
source (float) : Moving Average Source
maType (simple string) : Moving Average Type : Can be sma, ema, hma, rma, wma, vwma, swma, highlow, linreg, median
length (simple int) : Moving Average Length
multiplier (float) : Standard Deviation multiplier
useTrueRange (simple bool) : - if set to false, uses high-low.
sticky (simple bool) : - sticky boundaries which will only change when value is outside boundary.
Returns: Keltner Channel Width for custom moving average
kpercentk(source, maType, length, multiplier, useTrueRange, sticky)
returns Keltner Channel Percent K Width with custom moving average
Parameters:
source (float) : Moving Average Source
maType (simple string) : Moving Average Type : Can be sma, ema, hma, rma, wma, vwma, swma, highlow, linreg, median
length (simple int) : Moving Average Length
multiplier (float) : Standard Deviation multiplier
useTrueRange (simple bool) : - if set to false, uses high-low.
sticky (simple bool) : - sticky boundaries which will only change when value is outside boundary.
Returns: Keltner Percent K for given moving average, source, length and multiplier
dc(length, useAlternateSource, alternateSource, sticky)
returns Custom Donchian Channel
Parameters:
length (simple int) : - donchian channel length
useAlternateSource (simple bool) : - Custom source is used only if useAlternateSource is set to true
alternateSource (float) : - Custom source
sticky (simple bool) : - sticky boundaries which will only change when value is outside boundary.
Returns: Donchian channel
dcw(length, useAlternateSource, alternateSource, sticky)
returns Donchian Channel Width
Parameters:
length (simple int) : - donchian channel length
useAlternateSource (simple bool) : - Custom source is used only if useAlternateSource is set to true
alternateSource (float) : - Custom source
sticky (simple bool) : - sticky boundaries which will only change when value is outside boundary.
Returns: Donchian channel width
dpercentd(length, useAlternateSource, alternateSource, sticky)
returns Donchian Channel Percent of price
Parameters:
length (simple int) : - donchian channel length
useAlternateSource (simple bool) : - Custom source is used only if useAlternateSource is set to true
alternateSource (float) : - Custom source
sticky (simple bool) : - sticky boundaries which will only change when value is outside boundary.
Returns: Donchian channel Percent D
oscillatorRange(source, method, highlowLength, rangeLength, sticky)
oscillatorRange - returns Custom overbought/oversold areas for an oscillator input
Parameters:
source (float) : - Osillator source such as RSI, COG etc.
method (simple string) : - Valid values for method are : sma, ema, hma, rma, wma, vwma, swma, highlow, linreg, median
highlowLength (simple int) : - length on which highlow of the oscillator is calculated
rangeLength (simple int) : - length used for calculating oversold/overbought range - usually same as oscillator length
sticky (simple bool) : - overbought, oversold levels won't change unless crossed
Returns: Dynamic overbought and oversold range for oscillator input
oscillator(type, length, shortLength, longLength, source, highSource, lowSource, method, highlowLength, sticky)
oscillator - returns Choice of oscillator with custom overbought/oversold range
Parameters:
type (simple string) : - oscillator type. Valid values : cci, cmo, cog, mfi, roc, rsi, stoch, tsi, wpr
length (simple int) : - Oscillator length - not used for TSI
shortLength (simple int) : - shortLength only used for TSI
longLength (simple int) : - longLength only used for TSI
source (float) : - custom source if required
highSource (float) : - custom high source for stochastic oscillator
lowSource (float) : - custom low source for stochastic oscillator
method (simple string) : - Valid values for method are : sma, ema, hma, rma, wma, vwma, swma, highlow, linreg, median
highlowLength (simple int) : - length on which highlow of the oscillator is calculated
sticky (simple bool) : - overbought, oversold levels won't change unless crossed
Returns: Oscillator value along with dynamic overbought and oversold range for oscillator input
PitchforkLibrary "Pitchfork"
Pitchfork class
method tostring(this)
Converts PitchforkTypes/Fork object to string representation
Namespace types: Fork
Parameters:
this (Fork) : PitchforkTypes/Fork object
Returns: string representation of PitchforkTypes/Fork
method tostring(this)
Converts Array of PitchforkTypes/Fork object to string representation
Namespace types: array
Parameters:
this (array) : Array of PitchforkTypes/Fork object
Returns: string representation of PitchforkTypes/Fork array
method tostring(this, sortKeys, sortOrder)
Converts PitchforkTypes/PitchforkProperties object to string representation
Namespace types: PitchforkProperties
Parameters:
this (PitchforkProperties) : PitchforkTypes/PitchforkProperties object
sortKeys (bool) : If set to true, string output is sorted by keys.
sortOrder (int) : Applicable only if sortKeys is set to true. Positive number will sort them in ascending order whreas negative numer will sort them in descending order. Passing 0 will not sort the keys
Returns: string representation of PitchforkTypes/PitchforkProperties
method tostring(this, sortKeys, sortOrder)
Converts PitchforkTypes/PitchforkDrawingProperties object to string representation
Namespace types: PitchforkDrawingProperties
Parameters:
this (PitchforkDrawingProperties) : PitchforkTypes/PitchforkDrawingProperties object
sortKeys (bool) : If set to true, string output is sorted by keys.
sortOrder (int) : Applicable only if sortKeys is set to true. Positive number will sort them in ascending order whreas negative numer will sort them in descending order. Passing 0 will not sort the keys
Returns: string representation of PitchforkTypes/PitchforkDrawingProperties
method tostring(this, sortKeys, sortOrder)
Converts PitchforkTypes/Pitchfork object to string representation
Namespace types: Pitchfork
Parameters:
this (Pitchfork) : PitchforkTypes/Pitchfork object
sortKeys (bool) : If set to true, string output is sorted by keys.
sortOrder (int) : Applicable only if sortKeys is set to true. Positive number will sort them in ascending order whreas negative numer will sort them in descending order. Passing 0 will not sort the keys
Returns: string representation of PitchforkTypes/Pitchfork
method createDrawing(this)
Creates PitchforkTypes/PitchforkDrawing from PitchforkTypes/Pitchfork object
Namespace types: Pitchfork
Parameters:
this (Pitchfork) : PitchforkTypes/Pitchfork object
Returns: PitchforkTypes/PitchforkDrawing object created
method createDrawing(this)
Creates PitchforkTypes/PitchforkDrawing array from PitchforkTypes/Pitchfork array of objects
Namespace types: array
Parameters:
this (array) : array of PitchforkTypes/Pitchfork object
Returns: array of PitchforkTypes/PitchforkDrawing object created
method draw(this)
draws from PitchforkTypes/PitchforkDrawing object
Namespace types: PitchforkDrawing
Parameters:
this (PitchforkDrawing) : PitchforkTypes/PitchforkDrawing object
Returns: PitchforkTypes/PitchforkDrawing object drawn
method delete(this)
deletes PitchforkTypes/PitchforkDrawing object
Namespace types: PitchforkDrawing
Parameters:
this (PitchforkDrawing) : PitchforkTypes/PitchforkDrawing object
Returns: PitchforkTypes/PitchforkDrawing object deleted
method delete(this)
deletes underlying drawing of PitchforkTypes/Pitchfork object
Namespace types: Pitchfork
Parameters:
this (Pitchfork) : PitchforkTypes/Pitchfork object
Returns: PitchforkTypes/Pitchfork object deleted
method delete(this)
deletes array of PitchforkTypes/PitchforkDrawing objects
Namespace types: array
Parameters:
this (array) : Array of PitchforkTypes/PitchforkDrawing object
Returns: Array of PitchforkTypes/PitchforkDrawing object deleted
method delete(this)
deletes underlying drawing in array of PitchforkTypes/Pitchfork objects
Namespace types: array
Parameters:
this (array) : Array of PitchforkTypes/Pitchfork object
Returns: Array of PitchforkTypes/Pitchfork object deleted
method clear(this)
deletes array of PitchforkTypes/PitchforkDrawing objects and clears the array
Namespace types: array
Parameters:
this (array) : Array of PitchforkTypes/PitchforkDrawing object
Returns: void
method clear(this)
deletes array of PitchforkTypes/Pitchfork objects and clears the array
Namespace types: array
Parameters:
this (array) : Array of Pitchfork/Pitchfork object
Returns: void
PitchforkDrawingProperties
Pitchfork Drawing Properties object
Fields:
extend (series bool) : If set to true, forks are extended towards right. Default is true
fill (series bool) : Fill forklines with transparent color. Default is true
fillTransparency (series int) : Transparency at which fills are made. Only considered when fill is set. Default is 80
forceCommonColor (series bool) : Force use of common color for forks and fills. Default is false
commonColor (series color) : common fill color. Used only if ratio specific fill colors are not available or if forceCommonColor is set to true.
PitchforkDrawing
Pitchfork drawing components
Fields:
medianLine (Line type from Trendoscope/Drawing/2) : Median line of the pitchfork
baseLine (Line type from Trendoscope/Drawing/2) : Base line of the pitchfork
forkLines (array type from Trendoscope/Drawing/2) : fork lines of the pitchfork
linefills (array type from Trendoscope/Drawing/2) : Linefills between forks
Fork
Fork object property
Fields:
ratio (series float) : Fork ratio
forkColor (series color) : color of fork. Default is blue
include (series bool) : flag to include the fork in drawing. Default is true
PitchforkProperties
Pitchfork Properties
Fields:
forks (array) : Array of Fork objects
type (series string) : Pitchfork type. Supported values are "regular", "schiff", "mschiff", Default is regular
inside (series bool) : Flag to identify if to draw inside fork. If set to true, inside fork will be drawn
Pitchfork
Pitchfork object
Fields:
a (chart.point) : Pivot Point A of pitchfork
b (chart.point) : Pivot Point B of pitchfork
c (chart.point) : Pivot Point C of pitchfork
properties (PitchforkProperties) : PitchforkProperties object which determines type and composition of pitchfork
dProperties (PitchforkDrawingProperties) : Drawing properties for pitchfork
lProperties (LineProperties type from Trendoscope/Drawing/2) : Common line properties for Pitchfork lines
drawing (PitchforkDrawing) : PitchforkDrawing object
FibRatiosLibrary "FibRatios"
Library with calculation logic for fib retracement, extension and ratios
retracement(a, b, ratio, logScale, precision)
Calculates the retracement for points a, b with given ratio and scale
Parameters:
a (float) : Starting point a
b (float) : Second point b
ratio (float) : Ratio for which we need to calculate retracement c
logScale (bool) : Flag to get calculations in log scale. Default is false
precision (int) : rounding precision. If set to netagive number, round_to_mintick is applied. Default is -1
Returns: retracement point c for points a,b with given ratio and scale
retracementRatio(a, b, c, logScale, precision)
Calculates the retracement ratio for points a, b, c with given scale
Parameters:
a (float) : Starting point a
b (float) : Second point b
c (float) : Retracement point. c should be placed between a and b
logScale (bool) : Flag to get calculations in log scale. Default is false
precision (int) : rounding precision. If set to netagive number, round_to_mintick is applied. Default is 3
Returns: retracement ratio for points a,b,c on given scale
extension(a, b, c, ratio, logScale, precision)
Calculates the extensions for points a, b, c with given ratio and scale
Parameters:
a (float) : Starting point a
b (float) : Second point b
c (float) : Retracement point. c should be placed between a and b
ratio (float) : Ratio for which we need to calculate extension d
logScale (bool) : Flag to get calculations in log scale. Default is false
precision (int) : rounding precision. If set to netagive number, round_to_mintick is applied. Default is -1
Returns: extensoin point d for points a,b,c with given ratio and scale
extensionRatio(a, b, c, d, logScale, precision)
Calculates the extension ratio for points a, b, c, d with given scale
Parameters:
a (float) : Starting point a
b (float) : Second point b
c (float) : Retracement point. c should be placed between a and b
d (float) : Extension point. d should be placed beyond a, c. But, can be with b,c or beyond b
logScale (bool) : Flag to get calculations in log scale. Default is false
precision (int) : rounding precision. If set to netagive number, round_to_mintick is applied. Default is 3
Returns: extension ratio for points a,b,c,d on given scale
alertsLibrary "alerts"
The library provides options to run alert() calls in loop without worrying about limitations of frequency options.
When an alert statement is called within a loop,
it will fire just once per bar irrespective of how many iterations allowed when fequency is set to alert.freq_once_per_bar or alert.freq_once_per_bar_close
it will fire continuously till it breaks when frequency is set to alert.freq_all
The function helps overcome this issue by using varip key array which resets on every bar
method alert(message, key)
Enhanced alert which can be used in loops
Namespace types: series string, simple string, input string, const string
Parameters:
message (string) : Alert message to be fired
key (string) : Key to be checked to avoid repetitive alerts
Returns: array containing id of already fired alerts
method updateAlertTemplate(this, template)
Updates alert template with given keys and values
Namespace types: map
Parameters:
this (map) : map containing key value pair
template (string) : Alert message template
Returns: updated alert message
utilsLibrary "utils"
Few essentials captured together (subset of arrayutils)
timer(timeStart, timeEnd)
finds difference between two timestamps
Parameters:
timeStart (int) : start timestamp
timeEnd (int)
Returns:
method check_overflow(pivots, barArray, dir)
finds difference between two timestamps
Namespace types: array
Parameters:
pivots (array) : pivots array
barArray (array) : pivot bar array
dir (int) : direction for which overflow need to be checked
Returns: bool overflow
method get_trend_series(pivots, length, highLow, trend)
finds series of pivots in particular trend
Namespace types: array
Parameters:
pivots (array) : pivots array
length (int) : length for which trend series need to be checked
highLow (int) : filter pivot high or low
trend (int) : Uptrend or Downtrend
Returns: int trendIndexes
method get_trend_series(pivots, firstIndex, lastIndex)
finds series of pivots in particular trend
Namespace types: array
Parameters:
pivots (array) : pivots array
firstIndex (int) : First index of the series
lastIndex (int) : Last index of the series
Returns: int trendIndexes
getConsolidatedLabel(include, labels, separator)
Consolidates labels into single string by concatenating it with given separator
Parameters:
include (array) : array of conditions to include label or not
labels (array) : string array of labels
separator (string) : Separator for concatenating labels
Returns: string labelText
method getColors(theme)
gets array of colors based on theme
Namespace types: series Theme
Parameters:
theme (series Theme) : dark or light theme
Returns: color themeColors
HTFCandlesLibLibrary "HTFCandlesLib"
Library to get detailed higher timeframe candle information
method tostring(this, delimeter)
Returns OHLC values, BarIndex of higher and lower timeframe candles in string format
Namespace types: Candle
Parameters:
this (Candle) : Current Candle object
delimeter (string) : delimeter to join the string components of the candle
Returns: String representation of the Candle
method draw(this, bullishColor, bearishColor, printDescription)
Draws the current candle using boxes and lines for body and wicks
Namespace types: Candle
Parameters:
this (Candle) : Current Candle object
bullishColor (color) : color for bullish representation
bearishColor (color) : color for bearish representation
printDescription (bool) : if set to true prints the description
Returns: Current candle object
getCurrentCandle(ltfCandles)
Gets the current candle along with reassigned ltf components. To be used with request.security to capture higher timeframe candle data
Parameters:
ltfCandles (array) : Lower timeframe Candles array
Returns: Candle object with embedded lower timeframe key candles in them
Candle
Candle represents the data related to a candle
Fields:
o (series float) : Open price of the candle
h (series float) : High price of the candle
l (series float) : Low price of the candle
c (series float) : Close price of the candle
lo (Candle) : Lower timeframe candle that records the open price of the current candle.
lh (Candle) : Lower timeframe candle that records the high price of the current candle.
ll (Candle) : Lower timeframe candle that records the low price of the current candle.
lc (Candle) : Lower timeframe candle that records the close price of the current candle.
barindex (series int) : Bar Index of the candle
bartime (series int) : Bar time of the candle
last (Candle) : Link to last candle of the series if any
Motive Wave Scanner [Trendoscope®]Motive Wave Scanner is a simple algorithm to find out motive waves as per the rules of Elliott Wave theory.
It is an extension to our previous open source script Interactive Motive Wave Checklist which provides interactive capability to select six points of a five wave formation. Once users select them, the rules of motive waves are applied to manually selected points to highlight them as either diagonal wave, motive wave or none.
This indicator does the same. But, instead of requesting the pivots manually from the user, the indicator automatically picks and scans them through zigzag.
We have already published a similar script as protected source. But, due to some changes in the pine engine, there have been few issues in the runtime. In this publication, we not only address those runtime issues but also making it open source for the users to make use of the source code and enhance it further.
🎲 What are motive waves
Motive waves are strong upward or downward movement with 5 subwaves.
Motive Wave in the upward direction will start with Swing High, Ends with Swing High and consists of 3 Higher Highs and 2 Higher Lows representing strong upward trend.
Motive Wave in the downward direction will start with Swing Low, Ends with Swing low and consists of 3 Lower Lows and 2 Lower Highs representing strong downward trend.
🎲 Types of Motive Waves
Motive Waves are broadly classified by two types:
Impulse Waves
Diagonal Waves
Diagonal Waves are further classified into Contracting and Expanding Diagonals. These can fall into the category of either leading diagonal and ending diagonal.
🎲 Rules of Motive Waves
🎯 Generic Rule of any motive waves are as follows
Should consist of 5 alternating waves. (Swing High followed by Swing low and vice versa)
This can start from Swing High and end in Swing High or start from Swing Low and end in Swing Low of a zigzag.
Wave-2 should not move beyond Wave-1. This means, the Wave-2 is always shorter than Wave-1 with respect to distance between the price of start and end.
Wave-3 always moves beyond Wave-1. This means, the Wave-3 is always longer than Wave-2 in terms of price
Among Wave-1, Wave-3, and Wave-5, Wave-3 is never the shortest one. This means, either Wave-1 or Wave-5 can be longer than Wave-3 but not both. Wave-3 can also be longest among the three.
Here is the pictorial representation of the rules of the Motive Waves
For a wave to be considered as motive wave, it also needs to follow the rules of either impulse or diagonal waves.
🎯 Rules for a 5 wave pattern to be considered as Impulse Wave are:
Wave-4 never overlaps with Wave-1 price range
Wave-1, Wave-3 and Wave-5 should not be either expanding or contracting. Meaning, we cannot have Wave-1 > Wave-3 > Wave-5 , and we cannot have Wave-1 < Wave-3 < Wave-5
Pictorial representation of the impulse wave rules are as below:
🎯 Rules for the Diagonal Waves are as follows
Contrary to the first rule of impulse wave, in case of diagonal wave, Wave-4 always overlaps with Wave-1 price range. But, it will not go beyond Wave-3
Waves are progressively expanding or contracting - Wave1 > Wave3 > Wave5 and Wave2 > Wave4 to be contracting diagonal. Wave1 < Wave3 < Wave5 and Wave2 < Wave4 to be expanding diagonal wave.
Pictorial representation of the Contracting Diagonal Wave is as below. Here, the Wave-1, Wave-3 and Wave-5 are in contracting formation.
Pictorial representation of the Expanding Diagonal Wave is as below. Here, the Wave-1, Wave-3 and Wave-5 are in expanding formation.
🎲 Indicator Settings
Indicator settings are defined as below:
Repaint Warning : If Repaint is selected, the indicator will throw a runtime error after certain bars or when alerts are set. This is due to some pine internal issue. At present, we do not have any solution for this until the internal issue is resolved by Tradingview Pine Team.
BinaryInsertionSortLibrary "BinaryInsertionSort"
Library containing functions which can help create sorted array based on binary insertion sort.
This sorting will be quicker than array.sort function if the sorting needs to be done on every bar and the size of the array is comparatively big.
method binary_search_basic(sortedArray, item, order)
binary_search_basic - finds the closest index of the value
Namespace types: array
Parameters:
sortedArray (array) : array which is assumed to be sorted in the requested order
item (float) : float item which needs to be searched in the sorted array
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns: int index at which the item can be inserted into sorted array
method binary_search_basic(sortedArray, item, order)
binary_search_basic - finds the closest index of the value
Namespace types: array
Parameters:
sortedArray (array) : array which is assumed to be sorted in the requested order
item (int) : int item which needs to be searched in the sorted array
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns: int index at which the item can be inserted into sorted array
method binary_insertion_sort(sortedArray, item, order)
binary insertion sort - inserts item into sorted array while maintaining sort order
Namespace types: array
Parameters:
sortedArray (array) : array which is assumed to be sorted in the requested order
item (float) : float item which needs to be inserted into sorted array
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns: int index at which the item is inserted into sorted array
method binary_insertion_sort(sortedArray, item, order)
binary insertion sort - inserts item into sorted array while maintaining sort order
Namespace types: array
Parameters:
sortedArray (array) : array which is assumed to be sorted in the requested order
item (int) : int item which needs to be inserted into sorted array
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns: int index at which the item is inserted into sorted array
update_sort_indices(sortIndices, newItemIndex)
adds the sort index of new item added to sorted array and also updates existing sort indices.
Parameters:
sortIndices (array) : array containing sort indices of an array.
newItemIndex (int) : sort index of new item added to sorted array
Returns: void
get_array_of_series(item, order)
Converts series into array and sorted array.
Parameters:
item (float) : float series
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns:
get_array_of_series(item, order)
Converts series into array and sorted array.
Parameters:
item (int) : int series
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns:
get_sorted_arrays(item, order)
Converts series into array and sorted array. Also calculates the sort order of the value array
Parameters:
item (float) : float|int series
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns:
get_sorted_arrays(item, order)
Converts series into array and sorted array. Also calculates the sort order of the value array
Parameters:
item (int) : int series
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns:
WavesLibrary "Waves"
Methods for elliot wave detection
method delete(this)
deletes the subwave drawing
Namespace types: Subwave
Parameters:
this (Subwave) : Subwave object to be deleted
Returns: deleted subwave object
method delete(this)
deletes the wave drawing and the corresponding subwaves
Namespace types: Wave
Parameters:
this (Wave) : Wave object to be deleted
Returns: deleted wave object
method createWave(pivot, lineColor, waves, limit)
Create wave object
Namespace types: zg.Pivot
Parameters:
pivot (Pivot type from Trendoscope/Zigzag/7) : pivot object where the wave needs to be created
lineColor (color) : color of the wave to be drawn
waves (array) : array of existing waves
limit (int) : max number of waves to be shown in the chart
Returns: wave object created
method createSubWaves(wave, subwavePivots)
Create sub waves for the wave
Namespace types: Wave
Parameters:
wave (Wave)
subwavePivots (array) : array of sub wave pivots
Returns: wave object created
method draw(subWave)
Draw subwave
Namespace types: Subwave
Parameters:
subWave (Subwave)
Returns: subwsubWave object
method draw(wave, limitSubwaves)
Draw Wave
Namespace types: Wave
Parameters:
wave (Wave) : Wave object to be drawn
limitSubwaves (bool) : limit the number of subwave combinations within the wave
Returns: wave object
method checkMotiveWave(prices)
based on the price array, check if there is motive wave and identify the type
Namespace types: array
Parameters:
prices (array) : float array of prices
Returns: WaveType representing the identified wave type. na otherwise
method scanMotiveWave(pivot, lastPivot, existingWaves, allowedTypes)
Scan for motive wave
Namespace types: zg.Pivot
Parameters:
pivot (Pivot type from Trendoscope/Zigzag/7) : Zigzag pivot that will be checked for motive wave
lastPivot (Pivot type from Trendoscope/Zigzag/7) : previous Zigzag pivot
existingWaves (array) : array of existing waves
allowedTypes (array) : allowed Wave types to filter them
Returns: array of subwave pivots
SubwavePivots
SubwavePivots represents the sub pivots of the main wave
Fields:
waveType (series WaveType) : Type of the Wave
indices (array) : Bar index values of sub waves
subPivots (array type from Trendoscope/Zigzag/7) : sub pivot objects of the wave
Subwave
Subwave represents the drawing of sub waves
Fields:
waves (array type from Trendoscope/Drawing/1) : array of sub wave lines
points (array type from Trendoscope/Drawing/1) : Array of subwave pivot labels
subwavePivots (SubwavePivots) : array of subwave pivots being drawn
Wave
Wave object type
Fields:
pivot (Pivot type from Trendoscope/Zigzag/7) : starting point of the wave
wave (Line type from Trendoscope/Drawing/1) : Line representing the wave
waveLabel (Label type from Trendoscope/Drawing/1) : label containing wave details
subWaves (array) : array of sub waves
DrawingLibrary "Drawing"
User Defined types and methods for basic drawing structure. Consolidated from the earlier libraries - DrawingTypes and DrawingMethods
method get_price(this, bar)
get line price based on bar
Namespace types: Line
Parameters:
this (Line) : (series Line) Line object.
bar (int) : (series/int) bar at which line price need to be calculated
Returns: line price at given bar.
method init(this)
Namespace types: PolyLine
Parameters:
this (PolyLine)
method tostring(this, sortKeys, sortOrder, includeKeys)
Converts DrawingTypes/Point object to string representation
Namespace types: chart.point
Parameters:
this (chart.point) : DrawingTypes/Point object
sortKeys (bool) : If set to true, string output is sorted by keys.
sortOrder (int) : Applicable only if sortKeys is set to true. Positive number will sort them in ascending order whreas negative numer will sort them in descending order. Passing 0 will not sort the keys
includeKeys (array) : Array of string containing selective keys. Optional parmaeter. If not provided, all the keys are considered
Returns: string representation of DrawingTypes/Point
method tostring(this, sortKeys, sortOrder, includeKeys)
Converts DrawingTypes/LineProperties object to string representation
Namespace types: LineProperties
Parameters:
this (LineProperties) : DrawingTypes/LineProperties object
sortKeys (bool) : If set to true, string output is sorted by keys.
sortOrder (int) : Applicable only if sortKeys is set to true. Positive number will sort them in ascending order whreas negative numer will sort them in descending order. Passing 0 will not sort the keys
includeKeys (array) : Array of string containing selective keys. Optional parmaeter. If not provided, all the keys are considered
Returns: string representation of DrawingTypes/LineProperties
method tostring(this, sortKeys, sortOrder, includeKeys)
Converts DrawingTypes/Line object to string representation
Namespace types: Line
Parameters:
this (Line) : DrawingTypes/Line object
sortKeys (bool) : If set to true, string output is sorted by keys.
sortOrder (int) : Applicable only if sortKeys is set to true. Positive number will sort them in ascending order whreas negative numer will sort them in descending order. Passing 0 will not sort the keys
includeKeys (array) : Array of string containing selective keys. Optional parmaeter. If not provided, all the keys are considered
Returns: string representation of DrawingTypes/Line
method tostring(this, sortKeys, sortOrder, includeKeys)
Converts DrawingTypes/LabelProperties object to string representation
Namespace types: LabelProperties
Parameters:
this (LabelProperties) : DrawingTypes/LabelProperties object
sortKeys (bool) : If set to true, string output is sorted by keys.
sortOrder (int) : Applicable only if sortKeys is set to true. Positive number will sort them in ascending order whreas negative numer will sort them in descending order. Passing 0 will not sort the keys
includeKeys (array) : Array of string containing selective keys. Optional parmaeter. If not provided, all the keys are considered
Returns: string representation of DrawingTypes/LabelProperties
method tostring(this, sortKeys, sortOrder, includeKeys)
Converts DrawingTypes/Label object to string representation
Namespace types: Label
Parameters:
this (Label) : DrawingTypes/Label object
sortKeys (bool) : If set to true, string output is sorted by keys.
sortOrder (int) : Applicable only if sortKeys is set to true. Positive number will sort them in ascending order whreas negative numer will sort them in descending order. Passing 0 will not sort the keys
includeKeys (array) : Array of string containing selective keys. Optional parmaeter. If not provided, all the keys are considered
Returns: string representation of DrawingTypes/Label
method tostring(this, sortKeys, sortOrder, includeKeys)
Converts DrawingTypes/Linefill object to string representation
Namespace types: Linefill
Parameters:
this (Linefill) : DrawingTypes/Linefill object
sortKeys (bool) : If set to true, string output is sorted by keys.
sortOrder (int) : Applicable only if sortKeys is set to true. Positive number will sort them in ascending order whreas negative numer will sort them in descending order. Passing 0 will not sort the keys
includeKeys (array) : Array of string containing selective keys. Optional parmaeter. If not provided, all the keys are considered
Returns: string representation of DrawingTypes/Linefill
method tostring(this, sortKeys, sortOrder, includeKeys)
Converts DrawingTypes/BoxProperties object to string representation
Namespace types: BoxProperties
Parameters:
this (BoxProperties) : DrawingTypes/BoxProperties object
sortKeys (bool) : If set to true, string output is sorted by keys.
sortOrder (int) : Applicable only if sortKeys is set to true. Positive number will sort them in ascending order whreas negative numer will sort them in descending order. Passing 0 will not sort the keys
includeKeys (array) : Array of string containing selective keys. Optional parmaeter. If not provided, all the keys are considered
Returns: string representation of DrawingTypes/BoxProperties
method tostring(this, sortKeys, sortOrder, includeKeys)
Converts DrawingTypes/BoxText object to string representation
Namespace types: BoxText
Parameters:
this (BoxText) : DrawingTypes/BoxText object
sortKeys (bool) : If set to true, string output is sorted by keys.
sortOrder (int) : Applicable only if sortKeys is set to true. Positive number will sort them in ascending order whreas negative numer will sort them in descending order. Passing 0 will not sort the keys
includeKeys (array) : Array of string containing selective keys. Optional parmaeter. If not provided, all the keys are considered
Returns: string representation of DrawingTypes/BoxText
method tostring(this, sortKeys, sortOrder, includeKeys)
Converts DrawingTypes/Box object to string representation
Namespace types: Box
Parameters:
this (Box) : DrawingTypes/Box object
sortKeys (bool) : If set to true, string output is sorted by keys.
sortOrder (int) : Applicable only if sortKeys is set to true. Positive number will sort them in ascending order whreas negative numer will sort them in descending order. Passing 0 will not sort the keys
includeKeys (array) : Array of string containing selective keys. Optional parmaeter. If not provided, all the keys are considered
Returns: string representation of DrawingTypes/Box
method delete(this)
Deletes line from DrawingTypes/Line object
Namespace types: Line
Parameters:
this (Line) : DrawingTypes/Line object
Returns: Line object deleted
method delete(this)
Deletes label from DrawingTypes/Label object
Namespace types: Label
Parameters:
this (Label) : DrawingTypes/Label object
Returns: Label object deleted
method delete(this)
Deletes Linefill from DrawingTypes/Linefill object
Namespace types: Linefill
Parameters:
this (Linefill) : DrawingTypes/Linefill object
Returns: Linefill object deleted
method delete(this)
Deletes box from DrawingTypes/Box object
Namespace types: Box
Parameters:
this (Box) : DrawingTypes/Box object
Returns: DrawingTypes/Box object deleted
method delete(this)
Deletes lines from array of DrawingTypes/Line objects
Namespace types: array
Parameters:
this (array) : Array of DrawingTypes/Line objects
Returns: Array of DrawingTypes/Line objects
method delete(this)
Deletes labels from array of DrawingTypes/Label objects
Namespace types: array
Parameters:
this (array) : Array of DrawingTypes/Label objects
Returns: Array of DrawingTypes/Label objects
method delete(this)
Deletes linefill from array of DrawingTypes/Linefill objects
Namespace types: array
Parameters:
this (array) : Array of DrawingTypes/Linefill objects
Returns: Array of DrawingTypes/Linefill objects
method delete(this)
Deletes boxes from array of DrawingTypes/Box objects
Namespace types: array
Parameters:
this (array) : Array of DrawingTypes/Box objects
Returns: Array of DrawingTypes/Box objects
method clear(this)
clear items from array of DrawingTypes/Line while deleting underlying objects
Namespace types: array
Parameters:
this (array) : array
Returns: void
method clear(this)
clear items from array of DrawingTypes/Label while deleting underlying objects
Namespace types: array
Parameters:
this (array) : array
Returns: void
method clear(this)
clear items from array of DrawingTypes/Linefill while deleting underlying objects
Namespace types: array
Parameters:
this (array) : array
Returns: void
method clear(this)
clear items from array of DrawingTypes/Box while deleting underlying objects
Namespace types: array
Parameters:
this (array) : array
Returns: void
method draw(this)
Creates line from DrawingTypes/Line object
Namespace types: Line
Parameters:
this (Line) : DrawingTypes/Line object
Returns: line created from DrawingTypes/Line object
method draw(this)
Creates lines from array of DrawingTypes/Line objects
Namespace types: array
Parameters:
this (array) : Array of DrawingTypes/Line objects
Returns: Array of DrawingTypes/Line objects
method draw(this)
Creates label from DrawingTypes/Label object
Namespace types: Label
Parameters:
this (Label) : DrawingTypes/Label object
Returns: label created from DrawingTypes/Label object
method draw(this)
Creates labels from array of DrawingTypes/Label objects
Namespace types: array
Parameters:
this (array) : Array of DrawingTypes/Label objects
Returns: Array of DrawingTypes/Label objects
method draw(this)
Creates linefill object from DrawingTypes/Linefill
Namespace types: Linefill
Parameters:
this (Linefill) : DrawingTypes/Linefill objects
Returns: linefill object created
method draw(this)
Creates linefill objects from array of DrawingTypes/Linefill objects
Namespace types: array
Parameters:
this (array) : Array of DrawingTypes/Linefill objects
Returns: Array of DrawingTypes/Linefill used for creating linefills
method draw(this)
Creates box from DrawingTypes/Box object
Namespace types: Box
Parameters:
this (Box) : DrawingTypes/Box object
Returns: box created from DrawingTypes/Box object
method draw(this)
Creates labels from array of DrawingTypes/Label objects
Namespace types: array
Parameters:
this (array) : Array of DrawingTypes/Label objects
Returns: Array of DrawingTypes/Label objects
method createLabel(this, lblText, tooltip, properties)
Creates DrawingTypes/Label object from DrawingTypes/Point
Namespace types: chart.point
Parameters:
this (chart.point) : DrawingTypes/Point object
lblText (string) : Label text
tooltip (string) : Tooltip text. Default is na
properties (LabelProperties) : DrawingTypes/LabelProperties object. Default is na - meaning default values are used.
Returns: DrawingTypes/Label object
method createLine(this, other, properties)
Creates DrawingTypes/Line object from one DrawingTypes/Point to other
Namespace types: chart.point
Parameters:
this (chart.point) : First DrawingTypes/Point object
other (chart.point) : Second DrawingTypes/Point object
properties (LineProperties) : DrawingTypes/LineProperties object. Default set to na - meaning default values are used.
Returns: DrawingTypes/Line object
method createLinefill(this, other, fillColor, transparency)
Creates DrawingTypes/Linefill object from DrawingTypes/Line object to other DrawingTypes/Line object
Namespace types: Line
Parameters:
this (Line) : First DrawingTypes/Line object
other (Line) : Other DrawingTypes/Line object
fillColor (color) : fill color of linefill. Default is color.blue
transparency (int) : fill transparency for linefill. Default is 80
Returns: Array of DrawingTypes/Linefill object
method createBox(this, other, properties, textProperties)
Creates DrawingTypes/Box object from one DrawingTypes/Point to other
Namespace types: chart.point
Parameters:
this (chart.point) : First DrawingTypes/Point object
other (chart.point) : Second DrawingTypes/Point object
properties (BoxProperties) : DrawingTypes/BoxProperties object. Default set to na - meaning default values are used.
textProperties (BoxText) : DrawingTypes/BoxText object. Default is na - meaning no text will be drawn
Returns: DrawingTypes/Box object
method createBox(this, properties, textProperties)
Creates DrawingTypes/Box object from DrawingTypes/Line as diagonal line
Namespace types: Line
Parameters:
this (Line) : Diagonal DrawingTypes/PoLineint object
properties (BoxProperties) : DrawingTypes/BoxProperties object. Default set to na - meaning default values are used.
textProperties (BoxText) : DrawingTypes/BoxText object. Default is na - meaning no text will be drawn
Returns: DrawingTypes/Box object
LineProperties
Properties of line object
Fields:
xloc (series string) : X Reference - can be either xloc.bar_index or xloc.bar_time. Default is xloc.bar_index
extend (series string) : Property which sets line to extend towards either right or left or both. Valid values are extend.right, extend.left, extend.both, extend.none. Default is extend.none
color (series color) : Line color
style (series string) : Line style, valid values are line.style_solid, line.style_dashed, line.style_dotted, line.style_arrow_left, line.style_arrow_right, line.style_arrow_both. Default is line.style_solid
width (series int) : Line width. Default is 1
Line
Line object created from points
Fields:
start (chart.point) : Starting point of the line
end (chart.point) : Ending point of the line
properties (LineProperties) : LineProperties object which defines the style of line
object (series line) : Derived line object
LabelProperties
Properties of label object
Fields:
xloc (series string) : X Reference - can be either xloc.bar_index or xloc.bar_time. Default is xloc.bar_index
yloc (series string) : Y reference - can be yloc.price, yloc.abovebar, yloc.belowbar. Default is yloc.price
color (series color) : Label fill color
style (series string) : Label style as defined in Tradingview Documentation. Default is label.style_none
textcolor (series color) : text color. Default is color.black
size (series string) : Label text size. Default is size.normal. Other values are size.auto, size.tiny, size.small, size.normal, size.large, size.huge
textalign (series string) : Label text alignment. Default if text.align_center. Other allowed values - text.align_right, text.align_left, text.align_top, text.align_bottom
text_font_family (series string) : The font family of the text. Default value is font.family_default. Other available option is font.family_monospace
Label
Label object
Fields:
point (chart.point) : Point where label is drawn
lblText (series string) : label text
tooltip (series string) : Tooltip text. Default is na
properties (LabelProperties) : LabelProperties object
object (series label) : Pine label object
Linefill
Linefill object
Fields:
line1 (Line) : First line to create linefill
line2 (Line) : Second line to create linefill
fillColor (series color) : Fill color
transparency (series int) : Fill transparency range from 0 to 100
object (series linefill) : linefill object created from wrapper
BoxProperties
BoxProperties object
Fields:
border_color (series color) : Box border color. Default is color.blue
bgcolor (series color) : box background color
border_width (series int) : Box border width. Default is 1
border_style (series string) : Box border style. Default is line.style_solid
extend (series string) : Extend property of box. default is extend.none
xloc (series string) : defines if drawing needs to be done based on bar index or time. default is xloc.bar_index
BoxText
Box Text properties.
Fields:
boxText (series string) : Text to be printed on the box
text_size (series string) : Text size. Default is size.auto
text_color (series color) : Box text color. Default is color.yellow.
text_halign (series string) : horizontal align style - default is text.align_center
text_valign (series string) : vertical align style - default is text.align_center
text_wrap (series string) : text wrap style - default is text.wrap_auto
text_font_family (series string) : Text font. Default is
Box
Box object
Fields:
p1 (chart.point) : Diagonal point one
p2 (chart.point) : Diagonal point two
properties (BoxProperties) : Box properties
textProperties (BoxText) : Box text properties
object (series box) : Box object created
PolyLineProperties
Fields:
curved (series bool)
closed (series bool)
xloc (series string)
lineColor (series color)
fillColor (series color)
lineStyle (series string)
lineWidth (series int)
PolyLine
Fields:
points (array)
properties (PolyLineProperties)
object (series polyline)
ABCD Projection [Trendoscope®]Over the years, we have extensively explored and published numerous scripts centered around various chart patterns, including Harmonic Patterns, Reversal Patterns, Elliott Waves, and more. Our expertise in these areas has led to frequent requests for an indicator based on the ABCD pattern. Although we didn't include it as part of our Harmonic Patterns collection, the development of a dedicated ABCD Projection Indicator has always been a priority for us.
🎲 Overview of the ABCD Projection Indicator
The ABCD Projection Indicator is designed to identify and project ABCD patterns using a Zigzag-based approach. This pattern, characterized by alternating pivot highs and lows labeled as A, B, C, and D, is particularly significant in trending markets where it signifies trend continuation following deep pullbacks.
The indicator works by confirming the ABC pivots and projecting the D pivot based on the established price swings. Since ABCD patterns are most effective in trending environments, the indicator focuses on filtering patterns where the retracement from the C pivot has not compromised the trade's potential. Specifically, it ensures that the starting point (S)—where the pattern is detected—has not retraced beyond a defined threshold, preserving the opportunity to execute a trade with the goal of reaching the projected D pivot.
Additionally, the ABCD Projection Indicator considers the retracement ratio from the C pivot, which plays a crucial role in risk management. A higher retracement ratio reduces the stop distance (from pivot A to the entry point S) while increasing the distance to the target (pivot D), thereby enhancing the reward/risk ratio for trades.
🎲 Components of the ABCD Projection Indicator
The ABCD Projection Indicator comprises several key components:
A, B, C Pivots and Zigzag Wave : These elements form the foundational structure of the ABCD pattern.
S Point : This is the location where the pattern is identified, positioned a few bars away from the confirmed C pivot.
Estimated D Pivot : The D pivot is projected based on the A, B, and C price levels. The time or distance to the D pivot is influenced by the starting point S.
Mini Stats Table : Located in the top right corner, this table displays win/loss ratios and risk/reward data for both bullish and bearish scenarios.
Fibonacci Levels : Calculated from the C to D pivots, these levels are provided as a reference for additional analysis.
🎲 Indicator Settings
The settings for the ABCD Projection Indicator are minimal and intuitive, with tooltips provided to guide users through the configuration process.
Oscillator Scatterplot Analysis [Trendoscope®]In this indicator, we demonstrate how to plot oscillator behavior of oversold-overbought against price movements in the form of scatterplots and perform analysis. Scatterplots are drawn on a graph containing x and y-axis, where x represent one measure whereas y represents another. We use the library Graph to collect the data and plot it as scatterplot.
Pictorial explanation of components is defined in the chart below.
🎲 This indicator performs following tasks
Calculate and plot oscillator
Identify oversold and overbought areas based on various methods
Measure the price and bar movement from overbought to oversold and vice versa and plot them on the chart.
In our example,
The x-axis represents price movement. The plots found on the right side of the graph has positive price movements, whereas the plots found on the left side of the graph has negative price movements.
The y-axis represents the number of bars it took for reaching overbought to oversold and/or oversold to overbought. Positive bars mean we are measuring oversold to overbought, whereas negative bars are a measure of overbought to oversold.
🎲 Graph is divided into 4 equal quadrants
Quadrant 1 is the top right portion of the graph. Plots in this quadrant represent the instances where positive price movement is observed when the oscillator moved from oversold to overbought
Quadrant 2 is the top left portion of the graph. Plots in this quadrant represent the instances where negative price movement is observed when the oscillator moved from oversold to overbought.
Quadrant 3 is the bottom left portion of the chart. Plots in this quadrant represent the instances where negative price movement is observed when the oscillator moved from overbought to oversold.
Quadrant 4 is the bottom right portion of the chart. Plots in this quadrant represent the instances where positive price movement is observed when the oscillator moved from overbought to oversold.
🎲 Indicator components in Detail
Let's dive deep into the indicator.
🎯 Oscillator Selection
Select the Oscillator and define the overbought oversold conditions through input settings
Indicator - Oscillator base used for performing analysis
Length - Loopback length on which the oscillator is calculated
OB/OS Method - We use Bollinger Bands, Keltener Channel and Donchian channel to calculate dynamic overbought and oversold levels instead of static 80-10. This is also useful as other type of indicators may not be within 0-100 range.
Length and Multiplier are used for the bands for calculating Overbought/Oversold boundaries.
🎯 Define Graph Properties
Select different graph properties from the input settings that will instruct how to display the scatterplot.
Type - this can be either scatterplot or heatmap. Scatterplot will display plots with specific transparency to indicate the data, whereas heatmap will display background with different transparencies.
Plot Color - this is the color in which the scatterplot or heatmap is drawn
Plot Size - applicable mainly for scatterplot. Since the character we use for scatterplot is very tiny, the large at present looks optimal. But, based on the user's screen size, we may need to select different sizes so that it will render properly.
Rows and Columns - Number of rows and columns allocated per quadrant. This means, the total size of the chart is 2X rows and 2X columns. Data sets are divided into buckets based on the number of available rows and columns. Hence, changing this can change the appearance of the overall chart, even though they are representing the same data. Also, please note that tables can have max 10000 cells. If we increase the rows and columns by too much, we may get runtime errors.
Outliers - this is used to exclude the extreme data. 20% outlier means, the chart will ignore bottom 20% and top 20% when defining the chart boundaries. However, the extreme data is still added to the boundaries.
GraphLibrary "Graph"
Library to collect data and draw scatterplot and heatmap as graph
method init(this)
Initialise Quadrant Data
Namespace types: Quadrant
Parameters:
this (Quadrant) : Quadrant object that needs to be initialised
Returns: current Quadrant object
method init(this)
Initialise Graph Data
Namespace types: Graph
Parameters:
this (Graph) : Graph object that needs to be initialised with 4 Quadrants
Returns: current Graph object
method add(this, data)
Add coordinates to graph
Namespace types: Graph
Parameters:
this (Graph) : Graph object
data (Coordinate) : Coordinates containing x, y data
Returns: current Graph object
method calculate(this)
Calculation required for plotting the graph
Namespace types: Graph
Parameters:
this (Graph) : Graph object
Returns: current Graph object
method paint(this)
Draw graph
Namespace types: Graph
Parameters:
this (Graph) : Graph object
Returns: current Graph object
Coordinate
Coordinates of sample data
Fields:
xValue (series float) : x value of the sample data
yValue (series float) : y value of the sample data
Quadrant
Data belonging to particular quadrant
Fields:
coordinates (array) : Coordinates present in given quadrant
GraphProperties
Properties of Graph that needs to be drawn
Fields:
rows (series int) : Number of rows (y values) in each quadrant
columns (series int) : number of columns (x values) in each quadrant
graphtype (series GraphType) : Type of graph - scatterplot or heatmap
plotColor (series color) : color of plots or heatmap
plotSize (series string) : size of cells in the table
plotchar (series string) : Character to be printed for display of scatterplot
outliers (series int) : Excude the outlier percent of data from calculating the min and max
position (series string) : Table position
bgColor (series color) : graph background color
PlotRange
Range of a plot in terms of x and y values and the number of data points that fall within the Range
Fields:
minX (series float) : min range of X value
maxX (series float) : max range of X value
minY (series float) : min range of Y value
maxY (series float) : max range of Y value
count (series int) : number of samples in the range
Graph
Graph data and properties
Fields:
properties (GraphProperties) : Graph Properties object associated
quadrants (array) : Array containing 4 quadrant data
plotRanges (matrix) : range and count for each cell
xArray (array) : array of x values
yArray (array) : arrray of y values
divergingchartpatternLibrary "divergingchartpattern"
Library having implementation of converging chart patterns
getPatternNameByType(patternType)
Returns pattern name based on type
Parameters:
patternType (int) : integer value representing pattern type
Returns: string name of the pattern
method find(this, sProperties, dProperties, patterns, ohlcArray)
find converging patterns for given zigzag
Namespace types: zg.Zigzag
Parameters:
this (Zigzag type from Trendoscope/ZigzagLite/2) : Current zigzag Object
sProperties (ScanProperties) : ScanProperties Object
dProperties (DrawingProperties type from Trendoscope/abstractchartpatterns/5) : DrawingProperties Object
patterns (array type from Trendoscope/abstractchartpatterns/5) : array of existing patterns to check for duplicates
ohlcArray (array type from Trendoscope/ohlc/1) : array of OHLC values for historical reference
Returns: string name of the pattern
ScanProperties
Object containing properties for pattern scanning
Fields:
baseProperties (ScanProperties type from Trendoscope/abstractchartpatterns/5) : Object of Base Scan Properties
convergingDistanceMultiplier (series float)
convergingpatternsLibrary "convergingpatterns"
Library having implementation of converging chart patterns
getPatternNameByType(patternType)
Returns pattern name based on type
Parameters:
patternType (int) : integer value representing pattern type
Returns: string name of the pattern
method find(this, sProperties, dProperties, patterns, ohlcArray)
find converging patterns for given zigzag
Namespace types: zg.Zigzag
Parameters:
this (Zigzag type from Trendoscope/ZigzagLite/2) : Current zigzag Object
sProperties (ScanProperties) : ScanProperties Object
dProperties (DrawingProperties type from Trendoscope/abstractchartpatterns/5) : DrawingProperties Object
patterns (array type from Trendoscope/abstractchartpatterns/5) : array of existing patterns to check for duplicates
ohlcArray (array type from Trendoscope/ohlc/1) : array of OHLC values for historical reference
Returns: string name of the pattern
ScanProperties
Object containing properties for pattern scanning
Fields:
baseProperties (ScanProperties type from Trendoscope/abstractchartpatterns/5) : Object of Base Scan Properties
convergingDistanceMultiplier (series float) : when multiplied with pattern size gets the max number of bars within which the pattern should converge
simpletradeLibrary "simpletrade"
Library with Simple Trade types and tracking mechanism
method evaluate(this)
Evaluate current trade and update status
Namespace types: SimpleTrade
Parameters:
this (SimpleTrade) : SimpleTrade object that need to be evaluated
Returns: current SimpleTrade object
method erase(this)
Erase SimpleTrade drawings
Namespace types: SimpleTrade
Parameters:
this (SimpleTrade) : SimpleTrade object that needs to be erased
Returns: void
method draw(this, offset, gap)
Draw SimpleTrade drawings
Namespace types: SimpleTrade
Parameters:
this (SimpleTrade) : SimpleTrade object that needs to be drawn
offset (int) : offset distance at which the drawing needs to be drawn.
gap (int) : gap between start and end of the Simple trade drawings
Returns: updated offset
TradeDrawing
Object containing Trade drawings
Fields:
entryToStop (series box) : box showing entry to stop range
entryToTarget (series box) : box showing entry to target range
maxGain (series box) : box highlighting max gain of the Trade
maxLoss (series box) : box highlighting max lowss of the Trade
invalidationLine (series line) : line displaying trade invalidation price
invalidationLabel (series label) : label displaying trade invalidation price
stopLabel (series label) : label displaying trade stop price
entryLabel (series label) : label displaying trade entry price
targetLabel (series label) : label displaying trade target price
patternLabel (series label) : label displaying trade pattern details
SimpleTrade
Object containing Simple trade details for tracking
Fields:
id (series int) : Unique trade id
pid (series int) : parent id for trade. Multiple trades can have single parent id
dir (series int) : trade direction
tradeName (series string) : Trade name or description
tradeColor (series color) : color in which the trade needs to be drawn
entry (series float) : trade entry price
stop (series float) : trade stop price
invalidation (series float) : trade invalidation price
target (series float) : trade target price
maxGainPrice (series float) : price at which the trade attained max gain
maxLossPrice (series float) : price at which the trade attained max loss
drawing (TradeDrawing) : TradeDrawing object contianing drawing items
status (series int) : current status of the trade
maxStatus (series int) : max status attained by the trade
basechartpatternsLibrary "basechartpatterns"
Library having complete chart pattern implementation
getPatternNameById(id)
Returns pattern name by id
Parameters:
id (int) : pattern id
Returns: Pattern name
method find(points, properties, dProperties, ohlcArray)
Find patterns based on array of points
Namespace types: chart.point
Parameters:
points (chart.point ) : array of chart.point objects
properties (ScanProperties type from Trendoscope/abstractchartpatterns/1) : ScanProperties object
dProperties (DrawingProperties type from Trendoscope/abstractchartpatterns/1) : DrawingProperties object
ohlcArray (OHLC type from Trendoscope/ohlc/1)
Returns: Flag indicating if the pattern is valid, Current Pattern object
method find(this, properties, dProperties, patterns, ohlcArray)
Find patterns based on the currect zigzag object but will not store them in the pattern array.
Namespace types: zg.Zigzag
Parameters:
this (Zigzag type from Trendoscope/ZigzagLite/2) : Zigzag object containing pivots
properties (ScanProperties type from Trendoscope/abstractchartpatterns/1) : ScanProperties object
dProperties (DrawingProperties type from Trendoscope/abstractchartpatterns/1) : DrawingProperties object
patterns (Pattern type from Trendoscope/abstractchartpatterns/1) : Array of Pattern objects
ohlcArray (OHLC type from Trendoscope/ohlc/1)
Returns: Flag indicating if the pattern is valid, Current Pattern object
abstractchartpatternsLibrary "abstractchartpatterns"
Library having abstract types and methods for chart pattern implementations
checkBarRatio(p1, p2, p3, properties)
checks if three zigzag pivot points are having uniform bar ratios
Parameters:
p1 (chart.point) : First pivot point
p2 (chart.point) : Second pivot point
p3 (chart.point) : Third pivot point
properties (ScanProperties)
Returns: true if points are having uniform bar ratio
getRatioDiff(p1, p2, p3)
gets ratio difference between 3 pivot combinations
Parameters:
p1 (chart.point)
p2 (chart.point)
p3 (chart.point)
Returns: returns the ratio difference between pivot2/pivot1 ratio and pivot3/pivot2 ratio
method inspect(points, stratingBar, endingBar, direction, ohlcArray)
Creates a trend line between 2 or 3 points and validates and selects best combination
Namespace types: chart.point
Parameters:
points (chart.point ) : Array of chart.point objects used for drawing trend line
stratingBar (int) : starting bar of the trend line
endingBar (int) : ending bar of the trend line
direction (float) : direction of the last pivot. Tells whether the line is joining upper pivots or the lower pivots
ohlcArray (OHLC type from Trendoscope/ohlc/1) : Array of OHLC values
Returns: boolean flag indicating if the trend line is valid and the trend line object as tuple
method draw(this)
draws pattern on the chart
Namespace types: Pattern
Parameters:
this (Pattern) : Pattern object that needs to be drawn
Returns: Current Pattern object
method erase(this)
erase the given pattern on the chart
Namespace types: Pattern
Parameters:
this (Pattern) : Pattern object that needs to be erased
Returns: Current Pattern object
method push(this, p, maxItems)
push Pattern object to the array by keeping maxItems limit
Namespace types: Pattern
Parameters:
this (Pattern ) : array of Pattern objects
p (Pattern) : Pattern object to be added to array
@oaram maxItems Max number of items the array can hold
maxItems (int)
Returns: Current Pattern array
method deepcopy(this)
Perform deep copy of a chart point array
Namespace types: chart.point
Parameters:
this (chart.point ) : array of chart.point objects
Returns: deep copy array
DrawingProperties
Object containing properties for pattern drawing
Fields:
patternLineWidth (series int) : Line width of the pattern trend lines
showZigzag (series bool) : show zigzag associated with pattern
zigzagLineWidth (series int) : line width of the zigzag lines. Used only when showZigzag is set to true
zigzagLineColor (series color) : color of the zigzag lines. Used only when showZigzag is set to true
showPatternLabel (series bool) : display pattern label containing the name
patternLabelSize (series string) : size of the pattern label. Used only when showPatternLabel is set to true
showPivotLabels (series bool) : Display pivot labels of the patterns marking 1-6
pivotLabelSize (series string) : size of the pivot label. Used only when showPivotLabels is set to true
pivotLabelColor (series color) : color of the pivot label outline. chart.bg_color or chart.fg_color are the appropriate values.
deleteOnPop (series bool) : delete the pattern when popping out from the array of Patterns.
Pattern
Object containing Individual Pattern data
Fields:
points (chart.point )
originalPoints (chart.point )
trendLine1 (Line type from Trendoscope/LineWrapper/1) : First trend line joining pivots 1, 3, 5
trendLine2 (Line type from Trendoscope/LineWrapper/1) : Second trend line joining pivots 2, 4 (, 6)
properties (DrawingProperties) : DrawingProperties Object carrying common properties
patternColor (series color) : Individual pattern color. Lines and labels will be using this color.
ratioDiff (series float) : Difference between trendLine1 and trendLine2 ratios
zigzagLine (series polyline) : Internal zigzag line drawing Object
pivotLabels (label ) : array containning Pivot labels
patternLabel (series label) : pattern label Object
patternType (series int) : integer representing the pattern type
patternName (series string) : Type of pattern in string
ScanProperties
Object containing properties for pattern scanning
Fields:
offset (series int) : Zigzag pivot offset. Set it to 1 for non repainting scan.
numberOfPivots (series int) : Number of pivots to be used in pattern search. Can be either 5 or 6
errorRatio (series float) : Error Threshold to be considered for comparing the slope of lines
flatRatio (series float) : Retracement ratio threshold used to determine if the lines are flat
checkBarRatio (series bool) : Also check bar ratio are within the limits while scanning the patterns
barRatioLimit (series float) : Bar ratio limit used for checking the bars. Used only when checkBarRatio is set to true
avoidOverlap (series bool) : avoid overlapping patterns.
allowedPatterns (bool ) : array of bool encoding the allowed pattern types.
allowedLastPivotDirections (int ) : array of int representing allowed last pivot direction for each pattern types
themeColors (color ) : color array of themes to be used.
Flags and Pennants [Trendoscope®]🎲 An extension to Chart Patterns based on Trend Line Pairs - Flags and Pennants
After exploring Algorithmic Identification and Classification of Chart Patterns and developing Auto Chart Patterns Indicator , we now delve into extensions of these patterns, focusing on Flag and Pennant Chart Patterns. These patterns evolve from basic trend line pair-based structures, often influenced by preceding market impulses.
🎲 Identification rules for the Extension Patterns
🎯 Identify the existence of Base Chart Patterns
Before identifying the flag and pennant patterns, we first need to identify the existence of following base trend line pair based converging or parallel patterns.
Ascending Channel
Descending Channel
Rising Wedge (Contracting)
Falling Wedge (Contracting)
Converging Triangle
Descending Triangle (Contracting)
Ascending Triangle (Contracting)
🎯 Identifying Extension Patterns.
The key to pinpointing these patterns lies in spotting a strong impulsive wave – akin to a flagpole – preceding a base pattern. This setup suggests potential for an extension pattern:
A Bullish Flag emerges from a positive impulse followed by a descending channel or a falling wedge
A Bearish Flag appears after a negative impulse leading to an ascending channel or a rising wedge.
A Bullish Pennant is indicated by a positive thrust preceding a converging triangle or ascending triangle.
A Bearish Pennant follows a negative impulse and a converging or descending triangle.
🎲 Pattern Classifications and Characteristics
🎯 Bullish Flag Pattern
Characteristics of Bullish Flag Pattern are as follows
Starts with a positive impulse wave
Immediately followed by either a short descending channel or a falling wedge
Here is an example of Bullish Flag Pattern
🎯 Bearish Flag Pattern
Characteristics of Bearish Flag Pattern are as follows
Starts with a negative impulse wave
Immediately followed by either a short ascending channel or a rising wedge
Here is an example of Bearish Flag Pattern
🎯 Bullish Pennant Pattern
Characteristics of Bullish Pennant Pattern are as follows
Starts with a positive impulse wave
Immediately followed by either a converging triangle or ascending triangle pattern.
Here is an example of Bullish Pennant Pattern
🎯 Bearish Pennant Pattern
Characteristics of Bearish Pennant Pattern are as follows
Starts with a negative impulse wave
Immediately followed by either a converging triangle or a descending converging triangle pattern.
Here is an example of Bearish Pennant Pattern
🎲 Trading Extension Patterns
In a strong market trend, it's common to see temporary periods of consolidation, forming patterns that either converge or range, often counter to the ongoing trend direction. Such pauses may lay the groundwork for the continuation of the trend post-breakout. The assumption that the trend will resume shapes the underlying bias of Flag and Pennant patterns
It's important, however, not to base decisions solely on past trends. Conducting personal back testing is crucial to ascertain the most effective entry and exit strategies for these patterns. Remember, the behavior of these patterns can vary significantly with the volatility of the asset and the specific timeframe being analyzed.
Approach the interpretation of these patterns with prudence, considering that market dynamics are subject to a wide array of influencing factors that might deviate from expected outcomes. For investors and traders, it's essential to engage in thorough back testing, establishing entry points, stop-loss orders, and target goals that align with your individual trading style and risk appetite. This step is key to assessing the viability of these patterns in line with your personal trading strategies and goals.
It's fairly common to witness a breakout followed by a swift price reversal after these patterns have formed. Additionally, there's room for innovation in trading by going against the bias if the breakout occurs in the opposite direction, specially when the trend before the formation of the pattern is in against the pattern bias.
🎲 Cheat Sheet
🎲 Indicator Settings
Custom Source : Enables users to set custom OHLC - this means, the indicator can also be applied on oscillators and other indicators having OHLC values.
Zigzag Settings : Allows users to enable different zigzag base and set length and depth for each zigzag.
Scanning Settings : Pattern scanning settings set some parameters that define the pattern recognition process.
Display Settings : Determine the display of indicators including colors, lines, labels etc.
Backtest Settings : Allows users to set a predetermined back test bars so that the indicator will not time out while trying to run for all available bars.
Auto Chart Patterns [Trendoscope®]🎲 Introducing our most comprehensive automatic chart pattern recognition indicator.
Last week, we published an idea on how to algorithmically identify and classify chart patterns.
This indicator is nothing but the initial implementation of the idea. Whatever we explained in that publication that users can do manually to identify and classify the pattern, this indicator will do it for them.
🎲 Process of identifying the patterns.
The bulk of the logic is implemented as part of the library - chartpatterns . The indicator is a shell that captures the user inputs and makes use of the library to deliver the outcome.
🎯 Here is the list of steps executed to identify the patterns on the chart.
Derive multi level recursive zigzag for multiple base zigzag length and depth combinations.
For each zigzag and level, check the last 5 pivots or 6 pivots (based on the input setting) for possibility of valid trend line pairs.
If there is a valid trend line pair, then there is pattern.
🎯 Rules for identifying the valid trend line pairs
There should be at least two trend lines that does not intersect between the starting and ending pivots.
The upper trend line should touch all the pivot highs of the last 5 or 6 pivots considered for scanning the patterns
The lower trend line should touch all the pivot lows of the last 5 or 6 pivots considered for scanning the patterns.
None of the candles from starting pivot to ending pivot should fall outside the trend lines (above upper trend line and below lower trend line)
The existence of a valid trend line pair signifies the existence of pattern. What type of pattern it is, to identify that we need to go through the classification rules.
🎲 Process of classification of the patterns.
We need to gather the following information before we classify the pattern.
Direction of upper trend line - rising, falling or flat
Direction of lower trend line - rising, falling or flat
Characteristics of trend line pair - converging, expanding, parallel
🎯 Broader Classifications
Broader classification would include the following types.
🚩 Classification Based on Geometrical Shapes
This includes
Wedges - both trend lines are moving in the same direction. But, the trend lines are either converging or diverging and not parallel to each other.
Triangles - trend lines are moving in different directions. Naturally, they are either converging or diverging.
Channels - Both trend lines are moving in the same direction, and they are parallel to each other within the limits of error.
🚩 Classification Based on Pattern Direction
This includes
Ascending/Rising Patterns - No trend line is moving in the downward direction and at least one trend line is moving upwards
Descending/Falling Patterns - No trend line is moving in the upward direction, and at least one trend line is moving downwards.
Flat - Both Trend Lines are Flat
Bi-Directional - Both trend lines are moving in opposite direction and none of them is flat.
🚩 Classification Based on Formation Dynamics
This includes
Converging Patterns - Trend Lines are converging towards each other
Diverging Patterns - Trend Lines are diverging from each other
Parallel Patterns - Trend Lines are parallel to each others
🎯 Individual Pattern Types
Now we have broader classifications. Let's go through in detail to find out fine-grained classification of each individual patterns.
🚩 Ascending/Uptrend Channel
This pattern belongs to the broader classifications - Ascending Patterns, Parallel Patterns and Channels. The rules for the Ascending/Uptrend Channel pattern are as below
Both trend lines are rising
Trend lines are parallel to each other
🚩 Descending/Downtrend Channel
This pattern belongs to the broader classifications - Descending Patterns, Parallel Patterns and Channels. The rules for the Descending/Downtrend Channel pattern are as below
Both trend lines are falling
Trend lines are parallel to each other
🚩 Ranging Channel
This pattern belongs to the broader classifications - Flat Patterns, Parallel Patterns and Channels. The rules for the Ranging Channel pattern are as below
Both trend lines are flat
Trend lines are parallel to each other
🚩 Rising Wedge - Expanding
This pattern belongs to the broader classifications - Rising Patterns, Diverging Patterns and Wedges. The rules for the Expanding Rising Wedge pattern are as below
Both trend lines are rising
Trend Lines are diverging.
🚩 Rising Wedge - Contracting
This pattern belongs to the broader classifications - Rising Patterns, Converging Patterns and Wedges. The rules for the Contracting Rising Wedge pattern are as below
Both trend lines are rising
Trend Lines are converging.
🚩 Falling Wedge - Expanding
This pattern belongs to the broader classifications - Falling Patterns, Diverging Patterns and Wedges. The rules for the Expanding Falling Wedge pattern are as below
Both trend lines are falling
Trend Lines are diverging.
🚩 Falling Wedge - Contracting
This pattern belongs to the broader classifications - Falling Patterns, Converging Patterns and Wedges. The rules for the Converging Falling Wedge are as below
Both trend lines are falling
Trend Lines are converging.
🚩 Rising/Ascending Triangle - Expanding
This pattern belongs to the broader classifications - Rising Patterns, Diverging Patterns and Triangles. The rules for the Expanding Ascending Triangle pattern are as below
The upper trend line is rising
The lower trend line is flat
Naturally, the trend lines are diverging from each other
🚩 Rising/Ascending Triangle - Contracting
This pattern belongs to the broader classifications - Rising Patterns, Converging Patterns and Triangles. The rules for the Contracting Ascending Triangle pattern are as below
The upper trend line is flat
The lower trend line is rising
Naturally, the trend lines are converging.
🚩 Falling/Descending Triangle - Expanding
This pattern belongs to the broader classifications - Falling Patterns, Diverging Patterns and Triangles. The rules for the Expanding Descending Triangle pattern are as below
The upper trend line is flat
The lower trend line is falling
Naturally, the trend lines are diverging from each other
🚩 Falling/Descending Triangle - Contracting
This pattern belongs to the broader classifications - Falling Patterns, Converging Patterns and Triangles. The rules for the Contracting Descending Triangle pattern are as below
The upper trend line is falling
The lower trend line is flat
Naturally, the trend lines are converging.
🚩 Converging Triangle
This pattern belongs to the broader classifications - Bi-Directional Patterns, Converging Patterns and Triangles. The rules for the Converging Triangle pattern are as below
The upper trend line is falling
The lower trend line is rising
Naturally, the trend lines are converging.
🚩 Diverging Triangle
This pattern belongs to the broader classifications - Bi-Directional Patterns, Diverging Patterns and Triangles. The rules for the Diverging Triangle pattern are as below
The upper trend line is rising
The lower trend line is falling
Naturally, the trend lines are diverging from each other.
🎲 Indicator Settings - Auto Chart Patterns
🎯 Zigzag Settings
Zigzag settings allow users to select the number of zigzag combinations to be used for pattern scanning, and also allows users to set zigzag length and depth combinations.
🎯 Scanning Settings
Number of Pivots - This can be either 5 or 6. Represents the number of pivots used for identification of patterns.
Error Threshold - Error threshold used for initial trend line validation.
Flat Threshold - Flat angle threshold is used to identify the slope and direction of trend lines.
Last Pivot Direction - Filters patterns based on the last pivot direction. The values can be up, down, both, or custom. When custom is selected, then the individual pattern specific last pivot direction setting is used instead of the generic one.
Verify Bar Ratio - Provides option to ignore extreme patterns where the ratios of zigzag lines are not proportionate to each other.
Avoid Overlap - When selected, the patterns that overlap with existing patterns will be ignored while scanning. Meaning, if the new pattern starting point falls between the start and end of an existing pattern, it will be ignored.
🎯 Group Classification Filters
Allows users to enable disable patterns based on group classifications.
🚩 Geometric Shapes Based Classifications
Wedges - Rising Wedge Expanding, Falling Wedge Expanding, Rising Wedge Contracting, Falling Wedge Contracting.
Channels - Ascending Channel, Descending Channel, Ranging Channel
Triangles - Converging Triangle, Diverging Triangle, Ascending Triangle Expanding, Descending Triangle Expanding, Ascending Triangle Contrcting and Descending Triangle Contracting
🚩 Direction Based Classifications
Rising - Rising Wedge Contracting, Rising Wedge Expanding, Ascending Triangle Contracting, Ascending Triangle Expanding and Ascending Channel
Falling - Falling Wedge Contracting, Falling Wedge Expanding, Descending Triangle Contracting, Descending Triangle Expanding and Descending Channel
Flat/Bi-directional - Ranging Channel, Converging Triangle, Diverging Triangle
🚩 Formation Dynamics Based Classifications
Expanding - Rising Wedge Expanding, Falling Wedge Expanding, Ascending Triangle Expanding, Descending Triangle Expanding, Diverging Triangle
Contracting - Rising Wedge Contracting, Falling Wedge Contracting, Ascending Triangle Contracting, Descending Triangle Contracting, Converging Triangle
Parallel - Ascending Channel, Descending Channgel and Ranging Channel
🎯 Individual Pattern Filters
These settings allow users to enable/disable individual patterns and also set last pivot direction filter individually for each pattern. Individual Last Pivot direction filters are only considered if the main "Last Pivot Direction" filter is set to "custom"
🎯 Display Settings
These are the settings that determine the indicator display. The details are provided in the tooltips and are self explanatory.
🎯 Alerts
A basic alert message is enabled upon detection of new pattern on the chart.
ohlcLibrary "ohlc"
Library having OHLC and Indicator type and method implementations.
getOhlcArray(o, h, l, c, barindex, bartime, indicators)
get array of OHLC values when called on every bar
Parameters:
o (float) : Open price
h (float) : High Price
l (float) : Low Price
c (float) : Close Price
barindex (int) : bar_index of OHLC data
bartime (int) : time of OHLC cata
indicators (Indicator ) : array containing indicator
Returns: Array of OHLC objects
push(this, item, maxItems)
Push items to OHLC array with maxItems limit
Parameters:
this (OHLC )
item (OHLC) : OHLC Item to be pushed to the array
maxItems (int) : max Items the array can hold at a time
Returns: current object
push(this, item, maxItems)
Push items to Indicator array with maxItems limit
Parameters:
this (Indicator )
item (Indicator) : Indicator Item to be pushed to the array
maxItems (int) : max Items the array can hold at a time
Returns: current object
unshift(this, item, maxItems)
Unshift items to OHLC array with maxItems limit
Parameters:
this (OHLC )
item (OHLC) : OHLC Item to be unshifted to the array
maxItems (int) : max Items the array can hold at a time
Returns: current object
unshift(this, item, maxItems)
Unshift items to Indicator array with maxItems limit
Parameters:
this (Indicator )
item (Indicator) : Indicator Item to be unshifted to the array
maxItems (int) : max Items the array can hold at a time
Returns: current object
method getPoints(indicators)
get array of points based on array of indicator values
Namespace types: Indicator
Parameters:
indicators (Indicator ) : Array containing indicator objects
Returns: array of indicator points
method plot(indicator, xloc, line_color, line_style, line_width)
plots an array of Indicator using polyline
Namespace types: Indicator
Parameters:
indicator (Indicator ) : Array containing indicator objects
xloc (string) : can have values xloc.bar_index or xloc.bar_time. Used for drawing the line based on either bars or time.
line_color (color) : color in which the plots need to be printed on chart.
line_style (string) : line style line.style_solid, line.style_dotted, line.style_dashed, line.style_arrow_right, line.style_arrow_left, line.style_arrow_both
line_width (int) : width of the plot line
Returns: array of plot polyline
Indicator
Object containing Indicator name and value
Fields:
name (series string) : Indicator Name
value (chart.point) : Indicator Value as a chart point
OHLC
Object containing OHLC and indicator values
Fields:
o (series float) : Open price
h (series float) : High Price
l (series float) : Low Price
c (series float) : Close Price
barindex (series int) : bar_index of OHLC data
bartime (series int) : time of OHLC cata
indicators (Indicator ) : array containing indicator