Dual Zigzag [Trendoscope®]🎲 Dual Zigzag indicator is built on recursive zigzag algorithm. It is very similar to other zigzag indicators published by us and other authors. However, the key point here is, the indicator draws zigzag on both price and any other plot based indicator on separate layouts.
Before we get into the indicator, here are some brief descriptions of the underlying concepts and key terminologies
🎯 Zigzag
Zigzag indicator breaks down price or any input series into a series of Pivot Highs and Pivot Lows alternating between each other. Zigzags though shows pivot high and lows, should not be used for buying at low and selling at high. The main application of zigzag indicator is for the visualisation of market structure and this can be used as basic building block for any pattern recognition algorithms.
🎯 Recursive Zigzag Algorithm
Recursive zigzag algorithm builds zigzag on multiple levels and each level of zigzag is based on the previous level pivots. The level zero zigzag is built on price. However, for level 1, instead of price level 0 zigzag pivots are used. Similarly for level 2, level 1 zigzag pivots are used as base.
🎲 Components Dual Zigzag Indicator
Here are the components of Dual zigzag indicator
Built in Oscillator - Indicator has built in oscillator options for plotting RSI (Relative Strength Index), MFI (Money Flow Index), cci (Commodity Channel Index) , CMO (Chande Momentum Oscillator), COG (Center of Gravity), and ROC (Rate of Change). Apart from the given built in oscillators, users can also use a custom external output as base. The oscillators are not printed on the price pane. But, printed on a separate indicator overlay.
Zigzag On Oscillator - Recursive zigzag is calculated and printed on the oscillator series. Each pivot high and pivot low also prints a label having the retracement ratios, and price levels at those points. Zigzag on the oscillator is also printed on the indicator overlay pane.
Zigzag on Price - Recursive zigzag calculated based on price and printed on the price pane. This is made possible by using force_overlay option present in the drawing objects. At each zigzag pivot levels, the label having price retracement ratios, and oscillator values are printed.
It is called dual zigzag because, the indicator calculates the zigzag on both price and oscillator series of values and prints them separately on different panes on the chart.
🎲 Indicator Settings
Settings include
Theme display settings to get the right colour combination to match the background.
Zigzag settings to be used for zigzag calculation and display
Oscillator settings to chose the oscillator to be used as base for 2nd zigzag
🎲 Applications
Useful in spotting divergences with both indicator and price having their own zigzag to highlight pivots
Spotting patterns in indicators/oscillators and correlate them with the patterns on price
🎲 Using External Input
If users want to use an external indicator such as OBV instead of the built in oscillators, then can do so by using the custom option.
Here is how this can be done.
Step1. Add both Dual Zigzag and the intended indicator (in this case OBV) on the chart. Notice that both OBV and Dual zigzag appear on different panes.
Step2. Edit the indicator settings of Dual zigzag and set custom indicator by selecting "custom" as oscillator name and then by setting the custom external indicator name and input.
Step 3. You would notice that the zigzag in Dual Zigzag indictor pane is already showing the zigzag pivots based on the OBV indicator and the price pivots display obv values at the pivot points. We can leave this as is.
Step 4. As an additional step, you can also merge the OBV pane and the Dual zigzag indicator pane into one by going into OBV settings and moving the indicator to above pane. Merge the scales so that there is no two scales on the same pane and the entire scale appear on the right.
At the end, you should see two panes - one with price and other with OBV and both having their zigzag plotted.
Trendoscope
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.
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
Diverging Chart Patterns - Ultimate [Trendoscope®]🎲 Presenting the Diverging Chart Patterns Ultimate Indicator
Much like its counterpart, the Converging Chart Patterns Ultimate indicator, this tool is an offshoot of our premium Auto Chart Patterns - Ultimate offering. However, it is exclusively designed to focus on diverging patterns.
🎲 Built on Extensive Research and Open-Source Foundations
Our journey toward creating this indicator has been guided by thorough research and insights gleaned from our previous works on Chart Patterns, which include:
Algorithmic Identification of Chart Patterns
Flag and Pennant Chart Patterns
Trading Diverging Chart Patterns
Drawing from the groundwork established by our publicly available indicators - Auto Chart Patterns and Flags and Pennants - this tool represents the culmination of our efforts to furnish traders with a refined approach to navigating diverging patterns. It not only facilitates the formulation of technical trading strategies but also aids in assessing their efficacy through historical performance analysis. The specific patterns addressed by this indicator encompass:
Rising Wedge (Diverging Type)
Falling Wedge (Diverging Type)
Diverging Triangle
Rising Triangle (Diverging Type)
Falling Triangle (Diverging Type)
🎲 Chart Pattern Scanning Methodology
Identifying diverging chart patterns follows a structured approach comprising several key steps:
Zigzag Examination : Start by analyzing each zigzag, focusing on the last 5 or 6 pivot points to pinpoint potential trend line pairs.
Divergence Verification : Project these trend lines backward and scrutinize for intersections within a specified number of bars prior. This step confirms the presence of divergence.
Pattern Categorization : Once divergence is confirmed, categorize each pattern based on the directional orientation of its trend lines. Refer to our article - Algorithmic Identification of Chart Patterns for detailed categorization guidelines.
🎲 Methodology or Trading for Chart Patterns
While traditional perspectives often prescribe specific trading biases to diverging patterns—for instance, labeling Rising Wedges as bearish and Falling Wedges as bullish, while acknowledging Triangles' versatility—there's limited empirical evidence to fully support these assumptions. Our indicator is crafted to empower users to explore and validate a wide range of trading hypotheses, including unconventional ones. This approach liberates trading strategies from being confined to historical market behaviors.
We offer extensive customization options to facilitate testing of diverse strategies. The initial setup accommodates both long and short trading scenarios for each identified pattern. Users retain the freedom to adjust trading directions and other parameters within the indicator's settings to align with their analytical preferences.
This open approach is grounded in the methodology detailed in - Trading Diverging Chart Patterns . It is exemplified by the following process, which users can customize and enhance using our indicator.
🎲 Insight into Indicator Components
The chart below provides an illustration of the components comprising our indicator:
Pattern Visualization : This functionality dynamically showcases patterns on the chart, emphasizing presently active ones. Historical patterns are omitted to uphold clarity and optimize performance, considering limitations in drawing object capacity.
Trading Annotations : The indicator conveniently denotes open trades directly on the chart, accommodating both long and short positions based on user preferences and the ongoing status of associated trades for each pattern.
Performance Metrics Table : A comprehensive table meticulously presents backtesting outcomes for individual patterns alongside aggregated results. It encompasses vital metrics such as win rates and the profit factor, calculated in alignment with the designated risk-reward ratio. These insights provide users with valuable assessments of potential profitability and trade strategy effectiveness.
🎲 Delving into the Indicator's Customization Features
Our indicator boasts a wealth of settings, empowering users to customize criteria and refine their trading strategies. Each setting comes with detailed tooltips, offering valuable insights into its functionality. Let's explore each category methodically.
🎯 Zigzag Configuration Options
These settings provide users with the flexibility to fine-tune their pattern analysis by adjusting the length and depth of the zigzag:
Length Adjustment : Altering this parameter modifies the scale of detected patterns. Higher values highlight larger formations, while lower ones focus on more compact patterns.
Depth Enhancement : This parameter adjusts the complexity of the recursive zigzag analysis, potentially revealing larger patterns across multiple levels. Users should exercise caution, as excessive depth may strain the indicator's processing capacity.
🎯 Pattern Scanning Settings
This collection of settings refines the pattern scanning process, typically adjusted to achieve precise geometric alignment of detected patterns. While many settings can be left at their default values for regular use, users are encouraged to customize them, particularly the "Last Pivot Direction," to explore different theoretical approaches to pattern trading.
🎯 Trade Configuration Settings
Arguably the most vital for users, these settings provide full control in shaping trading strategies based on diverging chart patterns. This encompasses the freedom to establish entry, stop, and target prices, fine-tune risk-reward ratios, choose historical depth for backtesting, and integrate filters to guide trade direction.
🎯 Pattern Specific Settings
Here, users have the flexibility to customize settings for individual patterns or groups, thereby refining the precision of their strategies. Alongside the option to enable/disable specific patterns and pattern groups, users can also choose pattern-specific settings such as Last Pivot Direction, Trade Direction Filter, and external filters.
🎯 Fully Customizable Alerts
Utilizing the alert() function, these notifications circumvent the usual template within the alert widget. To address this, we've integrated placeholders in the settings for creating comprehensive alert templates.
Available Categories Include
New - Alerts when a new pattern is identified
Entry - Alerts when an entry condition for a configured pattern based trade is met.
Stop - Alerts when a trade that has reached entry gets stopped out without reaching target
Target - Alerts when a trade reaches its target
Invalidation - Alerts when a trade reaches an invalidation point before reaching the entry.
Each alert type can possess its unique template. Tailorable templates are crucial for effectively utilizing alerts within broker or exchange integration.
Here are some of the placeholders that are defined in the indicator.
{type} - Alert type - new/entry/stop/target/invalid
{pid} - Pattern ID of the pattern belonging to trade. Multiple trades can have same pattern id since a pattern can be traded in both long and short directions.
{tid} - Unique Trade ID for the given trade.
{ticker} - Ticker ID on which the indicator is run
{timeframe} - Chart timeframe on which the indicator is run
{basecurrency} - Base currency of the symbol
{quotecurrency} - Quote currency of the symbol
{pivots} - Pivot values of the pattern
{price} - Current price when the alert is triggered.
{pattern} - Name of the pattern on which the alert is triggered.
{direction} - Direction of the trade.
{entrydirection} - Direction of the entry signal. Used for specific bot integration.
{exitdirection} - Direction of the exit signal. Used for specific bot integration.
{entry} - Entry price of the trade
{stop} - Stop price of the trade
{target} - Target price of the trade
{invalidation} - Invalidation price of the trade
🎯 Display and Stats
These settings regulate the display options on the chart. Closed trade statistics are showcased in a table and appear in the bottom-left corner of the chart. These can be tailored using the display settings.
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)
Converging Chart Patterns - Ultimate [Trendoscope®]🎲 Introducing the Converging Chart Patterns Ultimate Indicator
Derived from the comprehensive capabilities of our premium offering, the Auto Chart Patterns - Ultimate , this new indicator focuses exclusively on converging chart patterns. It marks the beginning of a series that, over time, will encompass the full spectrum of chart pattern analysis, ultimately enhancing and expanding beyond the scope of Auto Chart Patterns.
This strategic separation into more focused indicators is designed to cater to traders seeking precision in specific chart pattern categories.
🎲 Leveraging Research and Open-Source Foundations
Our journey to this indicator has been paved by extensive research and the insights gained from our prior works on Chart Patterns, including:
Algorithmic Identification of Chart Patterns
Flag and Pennant Chart Patterns
Trading Converging Chart Patterns
Drawing upon the foundation laid by our publicly shared indicators - Auto Chart Patterns and Flags and Pennants - this tool is the culmination of our efforts to provide traders with a refined method for strategizing around converging patterns. It not only facilitates the development of technical trading strategies but also aids in evaluating their effectiveness through historical performance analysis. The specific patterns addressed by this indicator include:
Rising Wedge (Converging Type)
Falling Wedge (Converging Type)
Converging Triangle
Rising Triangle (Converging Type)
Falling Triangle (Converging Type)
🎲 Chart Pattern Scanning Methodology
The process of identifying converging chart patterns involves several key steps:
Begin by examining each zigzag for the last 5 or 6 pivot points to identify potential trend line pairs.
Determine if these trend lines are converging by projecting them forwards and checking for an intersection within a specified number of bars ahead.
Upon confirming convergence, categorize each pattern based on the directional orientation of its trend lines, as detailed in our article - Algorithmic Identification of Chart Patterns
🎲 Methodology or Trading for Chart Patterns
While traditional views assign specific trading biases to converging patterns (e.g., Rising Wedges as bearish and Falling Wedges as bullish, with Triangles being more versatile), empirical support for these assumptions is limited. Our indicator is designed to empower users to explore and validate various trading hypotheses, including unconventional ones, thereby not confining trading strategies to past market behaviors.
We enable extensive customization for testing different strategies, with the initial setup allowing for both long and short trading scenarios for each identified pattern. Users have the liberty to adjust trading directions and other parameters within the indicator's settings to suit their analytical needs.
This open approach is rooted in the methodology outlined in - Trading Converging Chart Patterns , exemplified by the following process, which users can adapt and refine through our indicator.
🎲 Overview of Indicator Components
The components of our indicator are illustrated in the chart below
Pattern Visualization : This feature dynamically displays the patterns on the chart, focusing on currently active patterns. To maintain clarity and performance, historical patterns are not shown due to the constraints of drawing objects.
Trading Annotations : The indicator marks open trades directly on the chart, accommodating both long and short positions depending on the user's settings and the current status of trades associated with each pattern.
Performance Metrics Table : A comprehensive table presents the back testing results for individual patterns as well as aggregated outcomes. It includes crucial metrics such as win rates and the profit factor based on the set risk-reward ratio, offering users valuable insights into the potential profitability of their configurations and trade strategies.
🎲 Exploring the Indicator's Customization Options
This indicator is rich in settings, offering users the capability to tailor criteria and adapt their trading rules. Each setting is accompanied by detailed tooltips, providing insights into their use. Let's examine each category systematically.
🎯 Zigzag Configuration Options
These settings enable users to adjust the scope of their pattern analysis by varying the zigzag's length and depth.
Length Adjustment : Modifying this parameter changes the scale of detected patterns, with higher values spotting larger formations and lower ones focusing on more compact patterns.
Depth Enhancement : This alters the intricacy of the recursive zigzag analysis, potentially unveiling larger patterns across several levels. Caution is advised, as excessive depth may lead to the indicator exceeding its processing capacity.
🎯 Pattern Scanning Settings
This suite of settings fine-tunes the pattern scanning process, generally calibrated for precise geometric alignment of identified patterns. While most settings may remain as default for routine use, users are encouraged to tweak them, especially the "Last Pivot Direction," to explore various theoretical approaches to pattern trading.
🎯 Trade Configuration Settings
Arguably the most crucial for users, these settings offer complete autonomy in defining trading strategies around converging chart patterns. This includes the flexibility to set entry, stop, and target prices, adjust risk-reward ratios, select the historical depth for back testing, and incorporate filters to steer trade direction.
🎯 Pattern Specific Settings
Here, users can personalize settings for individual patterns or groups, enhancing the specificity of their strategy. Apart from enabling/disabling individual patterns and pattern groups, users can also select pattern specific Last Pivot Direction, Trade Direction Filter and external filters for each pattern.
🎯 Fully Customizable Alerts
Implemented through the alert() function, these alerts bypass the standard template in the alert widget. To counteract this, we've introduced placeholders within the settings to craft detailed alert templates.
Available Categories Include
New - Alerts when a new pattern is identified
Entry - Alerts when an entry condition for configured pattern based trade is met.
Stop - Alerts when a trade that has reached entry gets stopped out without reaching target
Target - Alerts when a trade reaches its target
Invalidation - Alerts when a trade reaches invalidation point before reaching the entry.
Each alert types can have its own template. Customizable templates are very important in using alerts for broker or exchange integration.
Here are some of the placeholders that are defined in the indicator.
{type} - Alert type - new/entry/stop/target/invalid
{pid} - Pattern ID of the pattern belonging to trade. Multiple trades can have same pattern id since a pattern can be traded in both long and short directions.
{tid} - Unique Trade ID for the given trade.
{ticker} - Ticker ID on which the indicator is run
{timeframe} - Chart timeframe on which the indicator is run
{basecurrency} - Base currency of the symbol
{quotecurrency} - Quote currency of the symbol
{pivots} - Pivot values of the pattern
{price} - Current price when the alert is triggered.
{pattern} - Name of the pattern on which the alert is triggered.
{direction} - Direction of the trade.
{entrydirection} - Direction of the entry signal. Used for specific bot integration.
{exitdirection} - Direction of the exit signal. Used for specific bot integration.
{entry} - Entry price of the trade
{stop} - Stop price of the trade
{target} - Target price of the trade
{invalidation} - Invalidation price of the trade
🎯 Display and Stats
These settings are used to control the display options on the chart. Closed trade stats is displayed in a table and printed in the bottom left corner of the chart. This can be customized by using display settings.
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.