Chart Pine
Chart Pine
// Inputs
method1 = input.string('Median', options=['EMA', 'Median', 'SMA'])
length1 = input(56)
mult1 = input.int(1, minval=0, maxval=1)
// Calculation of medians
Avg(x, length, method) =>
sma_1 = ta.sma(x, length)
ema_1 = ta.ema(x, length)
percentile_linear_interpolation_1 = ta.percentile_linear_interpolation(x,
length, 50)
method == 'SMA' ? sma_1 : method == 'EMA' ? ema_1 :
percentile_linear_interpolation_1
// Calculation of volume
volLength = input.int(20, minval=1, title='Volume Length')
volMultiplier = input.float(1.0, title='Volume Multiplier')
//@version=5
m1 = close - close[len1]
lowest_1 = ta.lowest(math.abs(m1), len1)
highest_1 = ta.highest(math.abs(m1), len1)
controlPoint = counterTrend ? lowest_1 == math.abs(m1) : highest_1 == math.abs(m1)
baseLine = ta.valuewhen(controlPoint, math.avg(close, close[len1]), 0)
// trap line
atr = ta.valuewhen(controlPoint, ta.highest(math.max(math.max(ta.atr(len1),
ta.atr(len1 * 2)), ta.atr(len1 * 3)), len1), 0)
line1Up = baseLine + atr * multiple
line2Up = baseLine + atr * 2 * multiple
line3Up = baseLine + atr * 3 * multiple
line4Up = baseLine + atr * 4 * multiple
line5Up = baseLine + atr * 5 * multiple
line6Up = baseLine + atr * 6 * multiple
line7Up = baseLine + atr * 7 * multiple
line8Up = baseLine + atr * 8 * multiple
line9Up = baseLine + atr * 9 * multiple
line10Up = baseLine + atr * 10 * multiple
line1Down = baseLine - atr * multiple
line2Down = baseLine - atr * 2 * multiple
line3Down = baseLine - atr * 3 * multiple
line4Down = baseLine - atr * 4 * multiple
line5Down = baseLine - atr * 5 * multiple
line6Down = baseLine - atr * 6 * multiple
line7Down = baseLine - atr * 7 * multiple
line8Down = baseLine - atr * 8 * multiple
line9Down = baseLine - atr * 9 * multiple
line10Down = baseLine - atr * 10 * multiple
// draw
//barcolor(controlPoint ? color.yellow : close >= baseLine ? color.teal :
color.red, title="Candle Color")
L1 = input.float(1.272, "L1")
L2 = input.float(1.618, "L2")
// L3 = input.float(2.618, "L3")
if newSession
orh := high
orl := low
orbars := 0
extL1up := na
extL2up := na
extL3up := na
extL1dn := na
extL2dn := na
extL3dn := na
if inSession
orh := math.max(high, orh)
orl := math.min(low, orl)
orbars += 1
if endSession
extL1up := orl + (orh - orl) * L1
extL2up := orl + (orh - orl) * L2
// extL3up := orl + (orh - orl) * L3
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © Lenny_Kiruthu
//@version=5
//indicator(title = "Multi Timeframe Supply & Demand zones"
//, shorttitle = "MTF SnD"
//, overlay = true
//, max_bars_back = 500
//, max_lines_count = 500
//, max_boxes_count = 500)
// Constants
Transparent_Color = color.new(color.white, 100)
// Groups
General_Settings_group = "-------General Settings-------"
Timeframe_1_Group = "-------Timeframe 1 Settings--------"
Timeframe_2_Group = "-------Timeframe 2 Settings--------"
Timeframe_3_Group = "-------Timeframe 3 Settings--------"
// Tooltips
Timeframe_Tooltip = "If set to chart is true no need to alter these two inputs."
Set_To_Chart_Tooltip = "If set to chart is set to true, there is no need to alter
the Timeframe inputs, it will automatically configure itself to the charts
timeframe."
Lower_Timeframe_Tooltip = "If set to true and chart timeframe is higher than the
choosen timeframe, supply and demand will not display. Note plotting ltf structure
on a htf will provide inaccurate plots."
Mitigation_Tooltip = "If set to true supply zones with a high above them or a
demand zone with a low below them will be removed since they are considered
mitigated if false the close value will be used for both supply and demand."
Alert_Tooltip = "After setting the alert to true or false head over to the alert
dialog box and activate the any alert function under the indicator."
Hide_Demand = "Hide or show the demand zones of the specific timeframe."
Hide_Supply = "Hide or show the supply zones of the specific timeframe."
Hide_Timeframe = "Hide or show the entire timeframe."
// General Settings
Hide_All_Demand = input.bool(defval = false, title = "Hide all demand zones", group
= General_Settings_group)
Hide_All_Supply = input.bool(defval = false, title = "Hide all supply zones", group
= General_Settings_group)
Show_Only_On_Lower_Timeframes = input.bool(defval = true, title = "Show Supply and
Demand only on Lower Timeframes", group = General_Settings_group, tooltip =
Lower_Timeframe_Tooltip)
// User Inputs
// Timeframe 1 Settings
TF_1_Chart_Feature = input.bool(defval = false, title = "Set Timeframe to Chart",
group = Timeframe_1_Group, tooltip = Set_To_Chart_Tooltip)
TF_1_Use_High_Low = input.bool(defval = false, title = "Use High/Low to mitigates
zones", group = Timeframe_1_Group, tooltip = Mitigation_Tooltip)
TF_1_Show_Demand = input.bool(defval = true, title = "Show Demand", group =
Timeframe_1_Group, tooltip = Hide_Demand)
TF_1_Show_Supply = input.bool(defval = true, title = "Show Supply", group =
Timeframe_1_Group, tooltip = Hide_Supply)
TF_1_Demand_Alert = input.bool(defval = true, title = "Use TF 1 Demand Alert",
group = Timeframe_1_Group, tooltip = Alert_Tooltip)
TF_1_Supply_Alert = input.bool(defval = true, title = "Use TF 1 Supply Alert",
group = Timeframe_1_Group, tooltip = Alert_Tooltip)
TF_1_Multip = input.int(defval=2, minval=1, maxval=1440, title="Timeframe 1",
group=Timeframe_1_Group, inline="T1")
TF_1_Period = input.string(defval="Hour", title="", options=["Minute", "Hour",
"Day", "Week", "Month"], group=Timeframe_1_Group, inline="T1",
tooltip=Timeframe_Tooltip)
TF_1_Swing_Length = input.int(defval = 7, title = "Swing Length", minval = 1, group
= Timeframe_1_Group)
TF_1_Line_Type = input.string(defval = "Solid", title = "Border Type", options =
["Solid", "Dashed", "Dotted"], group = Timeframe_1_Group)
TF_1_Text_Size = input.string(defval = "Small", title = "Text Size", options =
["Normal", "Tiny", "Small", "Large", "Huge", "Auto"], group = Timeframe_1_Group)
TF_1_Line_Width = input.int(defval = 1, title = "Border Width", group =
Timeframe_1_Group)
TF_1_Demand_Show_Last = input.int(defval = 2, title = "Show last (Demand)", group =
Timeframe_1_Group)
TF_1_Supply_Show_Last = input.int(defval = 2, title = "Show last (Supply)", group =
Timeframe_1_Group)
TF_1_Demand_Color = input.color(defval = #c6f89560, title = "Demand Color", group =
Timeframe_1_Group, inline = "TF 1 Color")
TF_1_Supply_Color = input.color(defval = #fb726a60, title = "Supply Color", group =
Timeframe_1_Group, inline = "TF 1 Color")
TF_1_Text_Color = input.color(defval = color.white, title = "Text Color", group =
Timeframe_1_Group)
// Timeframe 2 Settings
TF_2_Chart_Feature = input.bool(defval = false, title = "Set Timeframe to Chart",
group = Timeframe_2_Group, tooltip = Set_To_Chart_Tooltip)
TF_2_Use_High_Low = input.bool(defval = false, title = "Use High/Low to mitigates
zones", group = Timeframe_2_Group, tooltip = Mitigation_Tooltip)
TF_2_Show_Demand = input.bool(defval = true, title = "Show Demand", group =
Timeframe_2_Group, tooltip = Hide_Demand)
TF_2_Show_Supply = input.bool(defval = true, title = "Show Supply", group =
Timeframe_2_Group, tooltip = Hide_Supply)
TF_2_Demand_Alert = input.bool(defval = true, title = "Use TF 2 Demand Alert",
group = Timeframe_2_Group, tooltip = Alert_Tooltip)
TF_2_Supply_Alert = input.bool(defval = true, title = "Use TF 2 Supply Alert",
group = Timeframe_2_Group, tooltip = Alert_Tooltip)
TF_2_Multip = input.int(defval=30, minval=1, maxval=1440, title="Timeframe 2",
group=Timeframe_2_Group, inline="T2")
TF_2_Period = input.string(defval="Minute", title="", options=["Minute", "Hour",
"Day", "Week", "Month"], group=Timeframe_2_Group, inline="T2",
tooltip=Timeframe_Tooltip)
TF_2_Swing_Length = input.int(defval = 7, title = "Swing Length", minval = 1, group
= Timeframe_2_Group)
TF_2_Line_Type = input.string(defval = "Solid", title = "Border Type", options =
["Solid", "Dashed", "Dotted"], group = Timeframe_2_Group)
TF_2_Text_Size = input.string(defval = "Small", title = "Text Size", options =
["Normal", "Tiny", "Small", "Large", "Huge", "Auto"], group = Timeframe_2_Group)
TF_2_Line_Width = input.int(defval = 1, title = "Border Width", group =
Timeframe_2_Group)
TF_2_Demand_Show_Last = input.int(defval = 2, title = "Show last (Demand)", group =
Timeframe_2_Group)
TF_2_Supply_Show_Last = input.int(defval = 2, title = "Show last (Supply)", group =
Timeframe_2_Group)
TF_2_Demand_Color = input.color(defval = #5794f860, title = "Demand Color", group =
Timeframe_2_Group, inline = "TF 2 Color")
TF_2_Supply_Color = input.color(defval = #f9c9fe60, title = "Supply Color", group =
Timeframe_2_Group, inline = "TF 2 Color")
TF_2_Text_Color = input.color(defval = color.white, title = "Text Color", group =
Timeframe_2_Group)
// General functions
// Getting the line type from the user.
Line_Type_Control(Type) =>
Line_Functionality = switch Type
"Solid" => line.style_solid
"Dashed" => line.style_dashed
"Dotted" => line.style_dotted
Line_Functionality
// Timeframe functionality
// Timeframe for security functions
TF(TF_Period, TF_Multip) =>
switch TF_Period
"Minute" => str.tostring(TF_Multip)
"Hour" => str.tostring(TF_Multip*60)
"Day" => str.tostring(TF_Multip) + "D"
"Week" => str.tostring(TF_Multip) + "W"
"Month" => str.tostring(TF_Multip) + "M"
=> timeframe.period
// Arrays
var Bullish_SnD_Top_TF_1 = array.new_float(0)
var Bullish_SnD_Btm_TF_1 = array.new_float(0)
var Bullish_SnD_Left_TF_1 = array.new_int(0)
var Bullish_SnD_Type_TF_1 = array.new_int(0)
var Bearish_SnD_Top_TF_1 = array.new_float(0)
var Bearish_SnD_Btm_TF_1 = array.new_float(0)
var Bearish_SnD_Left_TF_1 = array.new_int(0)
var Bearish_SnD_Type_TF_1 = array.new_int(0)
// TF Pivot values
// TF_1_Calc_High = ta.pivothigh(high, TF_1_Swing_Length, TF_1_Swing_Length)
// Functions //
// The function below is designed to loop through the arrays holding the box plot
values for supply and demand box plots
// and remove the mitigated (unnecessary plots) on the chart.
// array.set()
// The function below is designed to find the necessary swing points in our chart
that fit the description
// of demand and supply zones
if not na(TF_SL)
if TF_SL >= TF_Prev_Low
HL := true
else
LL := true
TF_Prev_Low := TF_SL
TF_Prev_Low_Time := TF_Prev_Low != TF_Prev_Low[1] ?
time[MTF_MS_Display(Chart_as_Timeframe, TF_Period, TF_Multip, Swing_Length)] :
TF_Prev_Low_Time[1]
TF_Low_Present := true
// Displaying Swing Level
// Demand zones
if LL and (math.abs(TF_SL_High - TF_Prev_Low) < TF_Atr * 2)
array.unshift(Bullish_SnD_Top, TF_SL_High)
array.unshift(Bullish_SnD_Btm, TF_Prev_Low)
array.unshift(Bullish_SnD_Left, TF_Prev_Low_Time)
array.unshift(Bullish_SnD_Type, 1)
if Use_Demand_Alert
alert(message = "New demand zone formed on " + +
TF_Display(Chart_as_Timeframe, TF_Period, TF_Multip), freq =
alert.freq_once_per_bar_close)
// Supply zones
if HH and (math.abs(TF_Prev_High - TF_SH_Low) < TF_Atr * 2)
array.unshift(Bearish_SnD_Top, TF_Prev_High)
array.unshift(Bearish_SnD_Btm, TF_SH_Low)
array.unshift(Bearish_SnD_Left, TF_Prev_High_Time)
array.unshift(Bearish_SnD_Type, -1)
if Use_Supply_Alert
alert(message = "New supply zone formed on " + +
TF_Display(Chart_as_Timeframe, TF_Period, TF_Multip), freq =
alert.freq_once_per_bar_close)
// The function below is designed to sift through our boxes, plot them on the chart
and apply the necessary formatting.
if Box_Type == "Bullish"
box.set_bgcolor(get_box, TF_Demand_Color)
box.set_border_color(get_box, TF_Demand_Color)
box.set_text(get_box, TF_Display(Chart_as_Timeframe, TF_Period,
TF_Multip))
box.set_text_color(get_box, TF_Text_Color)
box.set_text_font_family(get_box, font.family_default)
box.set_text_halign(get_box, text.align_right)
box.set_text_valign(get_box, text.align_top)
box.set_text_size(get_box, TF_Text_Size)
box.set_border_style(get_box, TF_Border_style)
box.set_border_width(get_box, TF_Border_width)
else if Box_Type == "Bearish"
box.set_bgcolor(get_box, TF_Supply_Color)
box.set_border_color(get_box, TF_Supply_Color)
box.set_text(get_box, TF_Display(Chart_as_Timeframe, TF_Period,
TF_Multip))
box.set_text_color(get_box, TF_Text_Color)
box.set_text_font_family(get_box, font.family_default)
box.set_text_halign(get_box, text.align_right)
box.set_text_valign(get_box, text.align_bottom)
box.set_text_size(get_box, TF_Text_Size)
box.set_border_style(get_box, TF_Border_style)
box.set_border_width(get_box, TF_Border_width)
// Calling functions
Supply_and_Demand_Functionality(TF_1_SH, TF_1_SL, TF_1_SH_Low, TF_1_SL_High,
TF_1_Atr
, TF_1_Swing_Length, TF_1_Chart_Feature, TF_1_Period, TF_1_Multip
, Bullish_SnD_Top_TF_1, Bullish_SnD_Btm_TF_1,
Bullish_SnD_Left_TF_1 ,Bullish_SnD_Type_TF_1
, Bearish_SnD_Top_TF_1, Bearish_SnD_Btm_TF_1, Bearish_SnD_Left_TF_1,
Bearish_SnD_Type_TF_1
, TF_1_Demand_Alert, TF_1_Supply_Alert)
TF_1_Bullish_Size = array.size(Bullish_SnD_Top_TF_1)
TF_1_Bearish_Size = array.size(Bearish_SnD_Top_TF_1)
TF_2_Bullish_Size = array.size(Bullish_SnD_Top_TF_2)
TF_2_Bearish_Size = array.size(Bearish_SnD_Top_TF_2)
Supply_and_Demand_Mitigation(Bullish_SnD_Top_TF_1, Bullish_SnD_Btm_TF_1,
Bullish_SnD_Left_TF_1, Bullish_SnD_Type_TF_1, "Bullish", TF_1_Use_High_Low)
Supply_and_Demand_Mitigation(Bearish_SnD_Top_TF_1, Bearish_SnD_Btm_TF_1,
Bearish_SnD_Left_TF_1, Bearish_SnD_Type_TF_1, "Bearish", TF_1_Use_High_Low)
Supply_and_Demand_Mitigation(Bullish_SnD_Top_TF_2, Bullish_SnD_Btm_TF_2,
Bullish_SnD_Left_TF_2, Bullish_SnD_Type_TF_2, "Bullish", TF_2_Use_High_Low)
Supply_and_Demand_Mitigation(Bearish_SnD_Top_TF_2, Bearish_SnD_Btm_TF_2,
Bearish_SnD_Left_TF_2, Bearish_SnD_Type_TF_2, "Bearish", TF_2_Use_High_Low)
if barstate.isfirst
for i = 0 to 125
array.push(TF_1_Bullish_Box_PLots, box.new(na,na,na,na, xloc =
xloc.bar_time))
array.push(TF_1_Bearish_Box_PLots, box.new(na,na,na,na, xloc =
xloc.bar_time))
array.push(TF_2_Bullish_Box_PLots, box.new(na,na,na,na, xloc =
xloc.bar_time))
array.push(TF_2_Bearish_Box_PLots, box.new(na,na,na,na, xloc =
xloc.bar_time))
//@version=5
//indicator("Predictive Ranges [LuxAlgo]", "LuxAlgo - Predictive Ranges", overlay =
true)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
lengthd = input.int(200, 'Length', minval = 2)
mult = input.float(6., 'Factor', minval = 0, step = .5)
tf = input.timeframe('', 'Timeframe')
src = input(close, 'Source')
//-----------------------------------------------------------------------------}
//Function
//-----------------------------------------------------------------------------{
pred_ranges(lengthd, mult)=>
var avg = src
var hold_atr = 0.
//-----------------------------------------------------------------------------}
//Calculation
//-----------------------------------------------------------------------------{
[prR2
, prR1
, avg
, prS1
, prS2] = request.security(syminfo.tickerid, tf, pred_ranges(lengthd, mult))
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
plot_pru2 = plot(prR2, 'PR Upper 2', avg != avg[1] ? na : #f23645)
plot_pru1 = plot(prR1, 'PR Upper 1', avg != avg[1] ? na : #f23645)
plot_pravg = plot(avg , 'PR Average', avg != avg[1] ? na : #5b9cf6)
plot_prl1 = plot(prS1, 'PR Lower 1', avg != avg[1] ? na : #089981)
plot_prl2 = plot(prS2, 'PR Lower 2', avg != avg[1] ? na : #089981)
//Fills
fill(plot_pru2, plot_pru1, avg != avg[1] ? na : color.new(#f23645, 95))
fill(plot_prl1, plot_prl2, avg != avg[1] ? na : color.new(#089981, 95))
//-----------------------------------------------------------------------------}
//@version=5
//indicator('Linear Regression Channel 200', 'LRC200', true)
// 0. Inputs
// 1. Custom function
// 2. Variables
// 3. Contructs
// 4. Alerts
//@version=5
//@author Eugene
//
// HOLP (High of the low period) and LOHP (Low of the high period)
// Catching Trend Reversals by shorting tops and buying bottoms
// using this Swing High/Low Indicator
//
// Trading Strategy comes from Mastering the Trade, by John Carter pg 300.
// Trading Rules for Sells, Buys are reversed
//
// 1. Identifying a trending market, where today's price is making a 20-day high
(17-18 day highs are also fine)
// Note this is configurable by setting the trending period variable (defaults
to 20)
// For example if price is making a 20 period high or 20 period low, it will
show a triangle up/down above the candle.
// 2. Identify the high bar in the uptrend
// 3. Go short once the price action closes below the low of this high bar
// 4. The intial stop is the high of the high bar.
// 5. If you are in the trade on the third day or period, use a 2 bar trailing
stop.
// You can check 2-bar trailing stop to draw the line, defaults to off.
// Stop is indicated by the white dot.
//
// Code Converted from TradeStation EasyLanguage
// I can't find the original source anymore for the swing high/low plots, but if
someone knows,
// let me know and I'll credit here.
//
//indicator(shorttitle='HOLP/LOHP', title='Catching Trend Reversals by shorting
tops and buying bottoms', overlay=true)
bartype() =>
if timeframe.period == "D"
2
else if timeframe.period == "W"
3
else if timeframe.period == "M"
4
else
1
barinterval() =>
timeframe.multiplier
fPushPeriods(iInterval) =>
if iInterval < 5
60
else if iInterval < 10
45
else if iInterval == 10
6
else if iInterval == 15
12
else if iInterval == 30
4
else if iInterval == 60
6
else if iInterval > 60
10
var xPeriods = 60
var xInterval = 0
var sFirstPass = true
var havePrevLines = false
var tLHigh = 0.0
var tLLow = 0.0
var pushHigh = 0.0
var pushHighBar = 0
var pushLow = 0.0
var pushLowBar = 0
var oldPushHigh = 0.0
var oldPushLow = 0.0
var prevPushHigh = 0.0
var prevPushLow = 0.0
var K = 0.0
var R = 0.0
var H0C1 = 0.0
var L0C1 = 0.0
var H0L0 = 0.0
var C1O1 = 0.0
var DL = 1.0
var SI =0.0
var ASI = 0.0
var SLOW_K =0.0
var SLOW_D = 0.0
var SWING_HIGH = 0.0
var SWING_LOW = 0.0
if R != 0
SI := 50 * ( ( ( close - close[1] ) + 0.50 * ( close - open ) + 0.25 *
( close[1] - open[1] ) ) / R ) * K / DL
else
SI := 0
ASI := ASI + SI
if sFirstPass
sFirstPass := false
if bartype() == 4 // monthly
xInterval := 94
else if bartype() == 3 // weekly
xInterval := 93
else if bartype() == 2 // daily
xInterval := 92
else if bartype() == 1 // minute
xInterval := barinterval()
if pushHigh != prevPushHigh
oldPushHigh := prevPushHigh
if pushLow != prevPushLow
oldPushLow := prevPushLow
oldPushHigh := prevPushHigh
oldPushLow := prevPushLow
prevPushHigh := pushHigh
prevPushLow := pushLow
if pushHigh != pushHigh[1]
lowBreakout := low
if pushLow != pushLow[1]
highBreakout := high
import HeWhoMustNotBeNamed/utils/1 as ut
indicators = matrix.new<float>()
indicatorNames = array.new<string>()
type ABCProperties
int base = 1
float entryRatio = 0.23
float targetRatio = 1.0
float stopRatio = -0.1
bool logScale = false
bool useClosePricesForEntry = true
bool useClosePricesForTarget = false
bool useClosePricesForStop = true
bool useClosePricesForRetest = false
int condition = 0
type ABCDrawing
dr.Line ab
dr.Line bc
dr.Line ac
dr.Label a
dr.Label b
dr.Label c
dr.Label abcRatio
dr.Box entryBox
dr.Box targetBox
type ABC
int id
int direction
zg.Pivot a
zg.Pivot b
zg.Pivot c
color patternColor
ABCProperties properties
float entryPrice
float stopPrice
float targetPrice
int status = 0
ABCDrawing drawing
initialiseCounts(int numberOfStatus)=>
countMap = map.new<int, int>()
for i=0 to numberOfStatus-1
countMap.put(i, 0)
countMap
this.targetPrice := this.properties.base == 1 ?
fibs.extension(this.a.point.price, this.b.point.price, this.c.point.price,
this.properties.targetRatio, this.properties.logScale) :
fibs.retracement(this.b.point.price, this.c.point.price,
this.properties.targetRatio, this.properties.logScale)
this.stopPrice := this.properties.base == 1 ?
fibs.extension(this.a.point.price, this.b.point.price, this.c.point.price,
this.properties.stopRatio, this.properties.logScale) :
fibs.retracement(this.b.point.price, this.c.point.price,
this.properties.stopRatio, this.properties.logScale)
this
dr.LineProperties patternLineProps =
dr.LineProperties.new(color=this.patternColor, width = 1, style = line.style_solid)
ab = this.a.point.createLine(this.b.point, patternLineProps)
bc = this.b.point.createLine(this.c.point, patternLineProps)
dr.LineProperties angleLineProps =
dr.LineProperties.new(color=this.patternColor, width = 0, style =
line.style_dotted)
ac = dr.Line.new(this.a.point, this.c.point, angleLineProps)
acMidPoint = dr.Point.new((this.a.point.price+this.c.point.price)/2,
(this.a.point.bar + this.c.point.bar)/2, (this.a.point.bartime +
this.c.point.bartime)/2)
abcRatioValue = fibs.retracementRatio(this.a.point.price, this.b.point.price,
this.c.point.price)
ratioLabelProperties = dr.LabelProperties.new(yloc = yloc.price, textcolor =
this.patternColor, style = label.style_none)
abcRatio = dr.Label.new(acMidPoint, str.tostring(abcRatioValue), properties =
ratioLabelProperties)
pivotLabelPropertiesAC = dr.LabelProperties.new(yloc = this.a.point.price <
this.b.point.price? yloc.belowbar : yloc.abovebar, textcolor = this.patternColor)
pivotLabelPropertiesBD = dr.LabelProperties.new(yloc = this.a.point.price >
this.b.point.price? yloc.belowbar : yloc.abovebar, textcolor = this.patternColor)
a = dr.Label.new(this.a.point, 'A', properties = pivotLabelPropertiesAC)
b = dr.Label.new(this.b.point, 'B', properties = pivotLabelPropertiesBD)
c = dr.Label.new(this.c.point, 'C', properties = pivotLabelPropertiesAC)
boxPropertiesEntry = dr.BoxProperties.new(this.patternColor,
color.new(color.red, 90))
boxPropertiesTarget = dr.BoxProperties.new(this.patternColor,
color.new(color.green, 90))
entryBox = dr.Box.new(entryPoint, entryBoxEndPoint, boxPropertiesEntry)
targetBox = dr.Box.new(entryPoint, targetBoxEndPoint, boxPropertiesTarget)
this.drawing := ABCDrawing.new(ab, bc, ac, a, b, c, abcRatio, entryBox,
targetBox)
this
method update(ABC this, zg.Pivot c)=>
this.c := c
alert('ABC Pattern Coordinates Updated')
this.calculateTargets()
if(this.withinEntry())
this.deleteDrawing().
createDrawing().
draw()
this
if(this.zigzagPivots.size() >= 4)
c = this.zigzagPivots.get(0)
b = this.zigzagPivots.get(1)
a = this.zigzagPivots.get(2)
aDir = math.abs(a.dir)
bDir = math.abs(b.dir)
conditionInLine = props.condition == 0 or
(props.condition == 1 and aDir == 1 and bDir == 2) or
(props.condition == 2 and aDir == 2 and bDir == 1) or
(props.condition == 3 and aDir == 1 and bDir == 1) or
(props.condition == 4 and aDir == 2 and bDir == 2)
ratioInLine = c.ratio >= 0.618 and c.ratio <= 0.786
if(ratioInLine and conditionInLine)
existingPattern = false
isAbc := true
for p in abcdPatterns
existingPattern := p.a.point.price == a.point.price and
p.b.point.price == b.point.price
if(existingPattern)
if(p.c.point.bar > c.point.bar and p.status == 0)
p.update(c)
isAbc:=false
break
isAbc
abcdPatterns.traverse()
oldPatterns.traverse()
if zigzag.flags.newPivot
mlzigzag = zigzag
while(mlzigzag.zigzagPivots.size() >= 3)
if(mlzigzag.level >= minimumZigZagLevel)
isAbcd = mlzigzag.scanAbc(properties)
if(isAbcd)
patternColor = themeColors.shift()
alert('New ABC Pattern Detected')
pattern = mlzigzag.createAbc(properties,
patternColor).calculateTargets()
if(pattern.withinEntry())
pattern.createDrawing().draw()
abcdPatterns.push(pattern)
while(abcdPatterns.size() > 10)
last = abcdPatterns.shift()
oldPatterns.push(last)
last.deleteDrawing()
themeColors.push(patternColor)
mlzigzag := mlzigzag.nextlevel()
if barstate.islast
var closedStatsTable = table.new(position.top_right, 6, 3, border_color =
chart.bg_color)
closedStatsTable.clear(0, 0, 5, 2)
closedStatsTable.cell(0, 0, 'Direction\\Status', text_color=color.white,
bgcolor = color.maroon)
closedStatsTable.cell(1, 0, 'Invalid', text_color=color.white, bgcolor =
color.maroon)
closedStatsTable.cell(2, 0, 'Stopped', text_color=color.white, bgcolor =
color.maroon)
closedStatsTable.cell(3, 0, 'Complete', text_color=color.white, bgcolor =
color.maroon)
closedStatsTable.cell(4, 0, 'Win Ratio', text_color=color.white, bgcolor =
color.maroon)
closedStatsTable.cell(5, 0, 'Risk Reward', text_color=color.white, bgcolor =
color.maroon)
closedStatsTable.cell(0, 1, 'Bullish', text_color=color.white, bgcolor =
color.new(color.green, 50))
closedStatsTable.cell(0, 2, 'Bearish', text_color=color.white, bgcolor =
color.new(color.red, 50))
bullishInvalid = bullishCounts.get(0)
bullishStopped = bullishCounts.get(1)
bullishCompleted = bullishCounts.get(2)
riskReward =(targetRatio - entryRatio)/(entryRatio - stopRatio)
bullishBgColor = color.new(color.green, 70)
closedStatsTable.cell(1, 1, str.tostring(bullishInvalid),
text_color=color.white, bgcolor = bullishBgColor)
closedStatsTable.cell(2, 1, str.tostring(bullishStopped),
text_color=color.white, bgcolor = bullishBgColor)
closedStatsTable.cell(3, 1, str.tostring(bullishCompleted),
text_color=color.white, bgcolor = bullishBgColor)
closedStatsTable.cell(4, 1,
str.tostring(bullishCompleted*100/(bullishCompleted+bullishStopped),
format.percent), text_color=color.white, bgcolor = bullishBgColor)
closedStatsTable.cell(5, 1, str.tostring(riskReward, '#.##'),
text_color=color.white, bgcolor = bullishBgColor)
bearishInvalid = bearishCounts.get(0)
bearishStopped = bearishCounts.get(1)
bearishCompleted = bearishCounts.get(2)
bearishBgColor = color.new(color.red, 70)
closedStatsTable.cell(1, 2, str.tostring(bearishInvalid),
text_color=color.white, bgcolor = bearishBgColor)
closedStatsTable.cell(2, 2, str.tostring(bearishStopped),
text_color=color.white, bgcolor = bearishBgColor)
closedStatsTable.cell(3, 2, str.tostring(bearishCompleted),
text_color=color.white, bgcolor = bearishBgColor)
closedStatsTable.cell(4, 2,
str.tostring(bearishCompleted*100/(bearishCompleted+bearishStopped),
format.percent), text_color=color.white, bgcolor = bearishBgColor)
closedStatsTable.cell(5, 2, str.tostring(riskReward, '#.##'),
text_color=color.white, bgcolor = bearishBgColor)
//@version=5
//indicator("Trend Lines, Supports and Resistances", shorttitle = "TSR", overlay =
true, max_bars_back = 5000)
//
╔══════════════════════════════════════════════════════════════════════════════════
═══════════╗
// ║ * * * I N P U T S * * *
║
//
╚══════════════════════════════════════════════════════════════════════════════════
═══════════╝
grpVisual = "Style"
stlHighColor = input.color(color.blue, title = "High Color", inline = "colors",
group = grpVisual)
stlLowColor = input.color(color.red, title = "Low Color", inline = "colors", group
= grpVisual)
lineWidth = input.int(1, title = "Line Width", minval = 1, group = grpVisual)
//
╔══════════════════════════════════════════════════════════════════════════════════
═══════════╗
// ║ * * * T Y P E S * * *
║
//
╚══════════════════════════════════════════════════════════════════════════════════
═══════════╝
//
╔══════════════════════════════════════════════════════════════════════════════════
═══════════╗
// ║ * * * V A R I A B L E S * * *
║
//
╚══════════════════════════════════════════════════════════════════════════════════
═══════════╝
//
╔══════════════════════════════════════════════════════════════════════════════════
═══════════╗
// ║ * * * M E T H O D S * * *
║
//
╚══════════════════════════════════════════════════════════════════════════════════
═══════════╝
// @function Checks for the bars if highs above trend line price.
// @param id (trendLine) Trend line object.
// @param exceptBars (int) Count of last bars for exception.
// @returns (int) Count of the bars above trend line price.
method getHighsAbovePrice(trendLine id, int exceptBars) =>
historyReference = bar_index - id.mainLine.get_x1()
count = 0
if exceptBars < historyReference
for i = historyReference to exceptBars
if high[i] > line.get_price(id.mainLine, bar_index - i)
count += 1
count
// @function Checks for the bars if lows below trend line price.
// @param id (trendLine) Trend line object.
// @param exceptBars (int) Count of last bars for exception.
// @returns (int) Count of the bars below trend line price.
method getLowsBelowPrice(trendLine id, int exceptBars) =>
historyReference = bar_index - id.mainLine.get_x1()
count = 0
if exceptBars < historyReference
for i = historyReference to exceptBars
if low[i] < line.get_price(id.mainLine, bar_index - i)
count += 1
count
//
╔══════════════════════════════════════════════════════════════════════════════════
═══════════╗
// ║ * * * F U N C T I O N S * * *
║
//
╚══════════════════════════════════════════════════════════════════════════════════
═══════════╝
// @function Compares two points and returns true if first one is higher.
// @param firstPoint (chart.point) First point to compare.
// @param secondPoint (chart.point) Second point to compare.
// @returns (bool) Whether the first point is higher than the second.
f_isHigher (chart.point firstPoint, chart.point secondPoint) =>
firstPoint.price > secondPoint.price
// @function Compares two points and returns true if first one is lower.
// @param firstPoint (chart.point) First point to compare.
// @param secondPoint (chart.point) Second point to compare.
// @returns (bool) Whether the first point is lower than the second.
f_isLower (chart.point firstPoint, chart.point secondPoint) =>
firstPoint.price < secondPoint.price
// @function Clears all lines, boxes, labels off the chart and empties all trend
line, support and resistance arrays.
// @returns (void)
f_clearAll() =>
for [i, v] in line.all
line.delete(v)
supports.clear()
resistances.clear()
uptrends.clear()
downtrends.clear()
//
╔══════════════════════════════════════════════════════════════════════════════════
═══════════╗
// ║ * * * C A L C U L A T I O N S * * *
║
//
╚══════════════════════════════════════════════════════════════════════════════════
═══════════╝
ph = ta.pivothigh(pvtLength, pvtLength)
pl = ta.pivotlow(pvtLength, pvtLength)
if not na(ph)
highPivots.unshift(chart.point.from_index(bar_index[pvtLength], ph))
if not na(pl)
lowPivots.unshift(chart.point.from_index(bar_index[pvtLength], pl))
//
╔══════════════════════════════════════════════════════════════════════════════════
═══════════╗
// ║ * * * P L O T S * * *
║
//
╚══════════════════════════════════════════════════════════════════════════════════
═══════════╝
if barstate.islast
f_clearAll()
if tlEnabled
for [i, v] in f_getAllPairCombinations(lowPivots.slice(0,
tlPointsToCheck).reversed())
if f_isLower(v.firstPoint, v.secondPoint)
f_drawUptrend(v.firstPoint, v.secondPoint)
if srEnabled
sCount = 0, lIndex = 0
rCount = 0, hIndex = 0
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © blackcat1402
//@version=5
//indicator(title="[blackcat] L1 Fibonacci MA Band", shorttitle="FMAB",
overlay=true)
// plot candles
plotcandle(whales, resoline, whales, resoline, color=(whales > resoline) ?
color.new(color.blue, 0) : na)
plotcandle(whales, resoline, whales, resoline, color=(whales < resoline) ?
color.new(color.green, 0) : na)
// plot lines
plot(whales, color=color.new(#FF7F00, 0), linewidth=2, style=plot.style_linebr)
plot(resoline, color=color.yellow, linewidth=1, style=plot.style_linebr)
plot(trendline, color=color.red, linewidth=3, style=plot.style_linebr)
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © traderharikrishna
// Idea and Code by @traderharikrishna
//@version=5
//indicator("RSI TREND FILTER",overlay=true)
showrsi=input.bool(false,title='Show RSI Cloud',group='RSI ')
showmidband=input.bool(false,title='Show RSI Mid Band',group='RSI ')
showgrid=input.bool(false,title='Show RSI Levels',group='RSI Levels')
grid=input.color(color.rgb(26, 22, 22, 34),'RSI LEVELS',group='RSI Levels')
rsilen=input.int(14,'RSI LENGTH',group='RSI')
rsima=input.int(100,'RSI 50 level',group='RSI')
emalen=input.int(20,'RSI EMA Length',group='RSI')
orsi=ta.rsi(close,rsilen)
adjrsi=close+ta.atr(100)*orsi/100
rma=ta.ema(adjrsi,rsima)
r1=plot(showrsi?adjrsi:na,display=display.all,title='RSI')
r2=plot(rma,color=open>rma?#00ff08:open<rma?#ff0404:color.white,title='RSI
MA',linewidth=2)
fill(r1,r2,color=adjrsi>rma?color.rgb(76, 175, 79, 70):color.rgb(255, 82, 82,
75),title='RSI Cloud',display=showrsi?display.all:display.none)
level2=input.float(10,'RSI LEVEL2',minval=10,maxval=100,group='RSI Levels')
rmau=rma+ta.atr(100)*level2/10
rmal=rma-ta.atr(100)*level2/10
u=plot(rmau,display=showgrid?display.all:display.none,title='70',color=grid)
l=plot(rmal,display=showgrid?display.all:display.none,title='30',color=grid)
fill(u,l,color=color.rgb(232, 237, 242, 82),title='RSI
ZeroBand',display=showmidband?display.all:display.none)
level3=input.float(40,'RSI LEVEL3',minval=10,maxval=100,group='RSI Levels')
rmau3=rma+ta.atr(100)*level3/10
rmal3=rma-ta.atr(100)*level3/10
o8=plot(rmau3,display=showgrid?display.all:display.none,title='80',color=grid)
o2=plot(rmal3,display=showgrid?display.all:display.none,title='20',color=grid)
level5=input.float(50,'RSI LEVEL5',minval=10,maxval=100,group='RSI Levels')
rmau5=rma+ta.atr(100)*level5/10
rmal5=rma-ta.atr(100)*level5/10
ul=plot(rmau5,color=grid,display=showgrid?display.all:display.none,title='100')
ll=plot(rmal5,color=grid,display=showgrid?display.all:display.none,title='0')
fill(o8,ul,color=color.rgb(232, 4, 205, 45),title='OverBought')
fill(o2,ll,color=color.rgb(9, 198, 15, 53),title='OverSold')
fill(r2,ul,color=color.rgb(76, 175, 79, 85),title='UP TREND')
fill(r2,ll,color=color.rgb(175, 76, 167, 85),title='DOWN TREND')
rsiMA=ta.ema(adjrsi,emalen)
plot(rsiMA,color=color.yellow)
//end of this part
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
at https://mozilla.org/MPL/2.0/
// © TFlab
//@version=5
//indicator("ZigZag Multi [TradingFinder] Trend & Wave Lines - Structures", overlay
= true , max_bars_back = 1000 , max_lines_count = 500 , max_labels_count = 500)
// // Input and Setting
// //Short Term Zig Zag Line
ShShTZ = input.bool(true , 'Show Short term Zig Zag Line', group = 'Short Term Zig
Zag') //Show Short Term Zig Zag
PPShTZ = input.int(3 ,'Pivot Period Short Term Zig Zag Line' , group = 'Short Term
Zig Zag') //Pivot Period Short Term Zig Zag
ShTZLS = input.string(line.style_dashed , 'Short Term Zig Zag Line Style' , options
= [line.style_solid ,line.style_dotted , line.style_dashed], group = 'Short Term
Zig Zag' ) //Short Term Zig Zag Line Style
ShTZLC = input.color(color.rgb(0, 0, 0) , 'Short Term Zig Zag Line Color' , group =
'Short Term Zig Zag') //Short Term Zig Zag Line Color
ShTZLW = input.int(1 ,'Short Term Zig Zag Line Width' , group = 'Short Term Zig
Zag')//Short Term Zig Zag Line Width
//Short Term Label
ShShTL = input.bool(true , 'Show Short Term Label', group = 'Short Term Label')
//Show Short Term Label
ShTLC = input.color(color.rgb(0, 0, 0) , 'Short Term Label Color' , group = 'Short
Term Label')//Short Term Label Color
ShTLS = input.string(size.tiny , 'Short Term Label size' , options = [size.auto,
size.tiny, size.small, size.normal, size.large, size.huge], group = 'Short Term
Label' )//Short Term Label size
if line.get_x1(ZZLine) == line.get_x1(ZZLine[1])
label.delete(Label[1])
line.delete(ZZLine[1])
//Call Function
ZigZag(open ,high ,low ,close ,bar_index ,PPShTZ , ShShTZ ,ShTZLS , ShTZLC,
ShTZLW ,ShShTL ,ShTLC , ShTLS )
ZigZag(open ,high ,low ,close ,bar_index ,PPLTZ , ShLTZ ,LTZLS , LTZLC,
LTZLW ,LShTL ,LTLC ,LTLS )