last ...
This commit is contained in:
@@ -0,0 +1,182 @@
|
|||||||
|
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||||
|
// © LuxAlgo
|
||||||
|
|
||||||
|
//@version=5
|
||||||
|
indicator("FVG Sessions [LuxAlgo]", overlay = true, max_lines_count = 500, max_boxes_count = 500)
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
//Settings
|
||||||
|
//-----------------------------------------------------------------------------{
|
||||||
|
bullCss = input.color(color.teal, 'FVG Level' , inline = 'bull')
|
||||||
|
bullAreaCss = input.color(color.new(color.teal, 50), 'Area' , inline = 'bull')
|
||||||
|
bullMitigatedCss = input.color(color.new(color.teal, 80), 'Mitigated', inline = 'bull')
|
||||||
|
|
||||||
|
bearCss = input.color(color.red, 'FVG Level' , inline = 'bear')
|
||||||
|
bearAreaCss = input.color(color.new(color.red, 50), 'Area' , inline = 'bear')
|
||||||
|
bearMitigatedCss = input.color(color.new(color.red, 80), 'Mitigated' , inline = 'bear')
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------}
|
||||||
|
//UDT's
|
||||||
|
//-----------------------------------------------------------------------------{
|
||||||
|
type fvg
|
||||||
|
float top
|
||||||
|
float btm
|
||||||
|
bool mitigated
|
||||||
|
bool isnew
|
||||||
|
bool isbull
|
||||||
|
line lvl
|
||||||
|
box area
|
||||||
|
|
||||||
|
type session_range
|
||||||
|
line max
|
||||||
|
line min
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------}
|
||||||
|
//Methods
|
||||||
|
//-----------------------------------------------------------------------------{
|
||||||
|
n = bar_index
|
||||||
|
|
||||||
|
//Method for setting fair value gaps
|
||||||
|
method set_fvg(fvg id, offset, bg_css, l_css)=>
|
||||||
|
avg = math.avg(id.top, id.btm)
|
||||||
|
|
||||||
|
area = box.new(n - offset, id.top, n, id.btm, na, bgcolor = bg_css)
|
||||||
|
avg_l = line.new(n - offset, avg, n, avg, color = l_css, style = line.style_dashed)
|
||||||
|
|
||||||
|
id.lvl := avg_l
|
||||||
|
id.area := area
|
||||||
|
|
||||||
|
//Method for setting session range maximum/minimum
|
||||||
|
method set_range(session_range id)=>
|
||||||
|
max = math.max(high, id.max.get_y2())
|
||||||
|
min = math.min(low, id.min.get_y2())
|
||||||
|
|
||||||
|
id.max.set_xy2(n, max)
|
||||||
|
id.max.set_y1(max)
|
||||||
|
|
||||||
|
id.min.set_xy2(n, min)
|
||||||
|
id.min.set_y1(min)
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------}
|
||||||
|
//Variables
|
||||||
|
//-----------------------------------------------------------------------------{
|
||||||
|
var chartCss = color.new(chart.fg_color, 50)
|
||||||
|
|
||||||
|
var fvg sfvg = fvg.new(na, na, na, true, na)
|
||||||
|
var session_range sesr = na
|
||||||
|
|
||||||
|
var box area = na
|
||||||
|
var line avg = na
|
||||||
|
|
||||||
|
bull_fvg = low > high[2] and close[1] > high[2]
|
||||||
|
bear_fvg = high < low[2] and close[1] < low[2]
|
||||||
|
|
||||||
|
//Alert conditions
|
||||||
|
bull_isnew = false
|
||||||
|
bear_isnew = false
|
||||||
|
bull_mitigated = false
|
||||||
|
bear_mitigated = false
|
||||||
|
within_bull_fvg = false
|
||||||
|
within_bear_fvg = false
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------}
|
||||||
|
//New session
|
||||||
|
//-----------------------------------------------------------------------------{
|
||||||
|
dtf = timeframe.change('D')
|
||||||
|
|
||||||
|
//On new session
|
||||||
|
if dtf
|
||||||
|
//Set delimiter
|
||||||
|
line.new(n, high + syminfo.mintick
|
||||||
|
, n, low - syminfo.mintick
|
||||||
|
, color = chartCss
|
||||||
|
, style = line.style_dashed
|
||||||
|
, extend = extend.both)
|
||||||
|
|
||||||
|
//Set new range
|
||||||
|
sesr := session_range.new(
|
||||||
|
line.new(n, high, n, high, color = chartCss)
|
||||||
|
, line.new(n, low, n, low, color = chartCss))
|
||||||
|
|
||||||
|
sfvg.isnew := true
|
||||||
|
|
||||||
|
//Set prior session fvg right coordinates
|
||||||
|
if not na(sfvg.lvl)
|
||||||
|
sfvg.lvl.set_x2(n-2)
|
||||||
|
sfvg.area.set_right(n-2)
|
||||||
|
|
||||||
|
//Set range
|
||||||
|
else if not na(sesr)
|
||||||
|
sesr.set_range()
|
||||||
|
|
||||||
|
//Set range lines color
|
||||||
|
sesr.max.set_color(sfvg.isbull ? bullCss : bearCss)
|
||||||
|
sesr.min.set_color(sfvg.isbull ? bullCss : bearCss)
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------}
|
||||||
|
//Set FVG
|
||||||
|
//-----------------------------------------------------------------------------{
|
||||||
|
//New session bullish fvg
|
||||||
|
if bull_fvg and sfvg.isnew
|
||||||
|
sfvg := fvg.new(low, high[2], false, false, true)
|
||||||
|
sfvg.set_fvg(2, bullAreaCss, bullCss)
|
||||||
|
|
||||||
|
bull_isnew := true
|
||||||
|
|
||||||
|
//New session bearish fvg
|
||||||
|
else if bear_fvg and sfvg.isnew
|
||||||
|
sfvg := fvg.new(low[2], high, false, false, false)
|
||||||
|
sfvg.set_fvg(2, bearAreaCss, bearCss)
|
||||||
|
|
||||||
|
bear_isnew := true
|
||||||
|
|
||||||
|
//Change object transparencies if mitigated
|
||||||
|
if not sfvg.mitigated
|
||||||
|
//If session fvg is bullish
|
||||||
|
if sfvg.isbull and close < sfvg.btm
|
||||||
|
sfvg.set_fvg(1, bullMitigatedCss, bullCss)
|
||||||
|
|
||||||
|
sfvg.mitigated := true
|
||||||
|
bull_mitigated := true
|
||||||
|
|
||||||
|
//If session fvg is bearish
|
||||||
|
else if not sfvg.isbull and close > sfvg.top
|
||||||
|
sfvg.set_fvg(1, bearMitigatedCss, bearCss)
|
||||||
|
|
||||||
|
sfvg.mitigated := true
|
||||||
|
bear_mitigated := true
|
||||||
|
|
||||||
|
//Set fvg right coordinates to current bar
|
||||||
|
if not sfvg.isnew
|
||||||
|
sfvg.lvl.set_x2(n)
|
||||||
|
sfvg.area.set_right(n)
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------}
|
||||||
|
//Alerts
|
||||||
|
//-----------------------------------------------------------------------------{
|
||||||
|
//On new session fvg
|
||||||
|
alertcondition(bull_isnew, 'Bullish FVG', 'New session bullish fvg')
|
||||||
|
alertcondition(bear_isnew, 'Bearish FVG', 'New session bearish fvg')
|
||||||
|
|
||||||
|
//On fvg mitigation
|
||||||
|
alertcondition(bull_mitigated, 'Mitigated Bullish FVG', 'Session bullish fvg has been mitigated')
|
||||||
|
alertcondition(bear_mitigated, 'Mitigated Bearish FVG', 'Session bearish fvg has been mitigated')
|
||||||
|
|
||||||
|
//If within fvg
|
||||||
|
alertcondition(close >= sfvg.btm and close <= sfvg.top and sfvg.isbull and not sfvg.isnew
|
||||||
|
, 'Price Within Bullish FVG'
|
||||||
|
, 'Price is within bullish fvg')
|
||||||
|
|
||||||
|
alertcondition(close >= sfvg.btm and close <= sfvg.top and not sfvg.isbull and not sfvg.isnew
|
||||||
|
, 'Price Within Bearish FVG'
|
||||||
|
, 'Price is within bearish fvg')
|
||||||
|
|
||||||
|
//On fvg average cross
|
||||||
|
alertcondition(ta.cross(close, math.avg(sfvg.top, sfvg.btm)) and sfvg.isbull and not sfvg.isnew
|
||||||
|
, 'Bullish FVG AVG Cross'
|
||||||
|
, 'Price crossed bullish fvg average')
|
||||||
|
|
||||||
|
alertcondition(ta.cross(close, math.avg(sfvg.top, sfvg.btm)) and not sfvg.isbull and not sfvg.isnew
|
||||||
|
, 'Bearish FVG AVG Cross'
|
||||||
|
, 'Price crossed bearish fvg average')
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------}
|
||||||
@@ -0,0 +1,273 @@
|
|||||||
|
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
|
||||||
|
// © ChartPrime
|
||||||
|
|
||||||
|
//@version=5
|
||||||
|
indicator("Trendline Breakouts With Targets [ Chartprime ]",shorttitle = "TBT [ Chartprime ]",overlay = true,max_bars_back = 500,max_lines_count = 500)
|
||||||
|
|
||||||
|
|
||||||
|
bool ChartTime = time > chart.left_visible_bar_time and time < chart.right_visible_bar_time
|
||||||
|
|
||||||
|
string CORE = "➞ Core Settings 🔸"
|
||||||
|
var bool TradeisON = false
|
||||||
|
var bool LongTrade = false
|
||||||
|
var bool ShortTrade = false
|
||||||
|
var float TP = 0.0
|
||||||
|
var float SL = 0.0
|
||||||
|
int BarTIME = time - time[1]
|
||||||
|
var line tpLine = na
|
||||||
|
var label LAB = na
|
||||||
|
var int UpdatedX = 0
|
||||||
|
var float UpdatedY = 0.0
|
||||||
|
var float UpdatedSLP = 0.0
|
||||||
|
var int UpdatedXLow = 0
|
||||||
|
var float UpdatedYLow = 0.0
|
||||||
|
var float UpdatedSLPLow = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
int Period = input.int(10, title=' Period ➞',
|
||||||
|
group = CORE,
|
||||||
|
inline = "001")
|
||||||
|
|
||||||
|
bool Trendtype = input.string(title = " Type ➞",
|
||||||
|
defval='Wicks',
|
||||||
|
options=['Wicks', 'Body'],
|
||||||
|
group = CORE,
|
||||||
|
inline = "001")
|
||||||
|
== 'Wicks'
|
||||||
|
|
||||||
|
string Extensions = input.string(title=' Extend ➞',
|
||||||
|
defval=' 25',
|
||||||
|
options=[' 25', ' 50', ' 75'],
|
||||||
|
group = CORE,
|
||||||
|
inline = "001")
|
||||||
|
|
||||||
|
|
||||||
|
color LineCol1 = input.color(color.rgb(109, 111, 111, 19),"",group = CORE,inline = "001")
|
||||||
|
bool ShowTargets = input.bool(true,"Show Targets",group = CORE,inline = "002")
|
||||||
|
|
||||||
|
ExtenSwitcher(ex) =>
|
||||||
|
switch ex
|
||||||
|
' 25' => 1 ,
|
||||||
|
' 50' => 2 ,
|
||||||
|
=> 3
|
||||||
|
|
||||||
|
|
||||||
|
WidthSwitcher(ex) =>
|
||||||
|
switch ex
|
||||||
|
'1' => 1 ,
|
||||||
|
'2' => 2 ,
|
||||||
|
=> 3
|
||||||
|
|
||||||
|
StyleSwitcher(style) =>
|
||||||
|
switch style
|
||||||
|
'Dashed' => line.style_dashed ,
|
||||||
|
'Dotted' => line.style_dotted ,
|
||||||
|
=> line.style_solid
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
method volAdj(int len)=>
|
||||||
|
math.min(ta.atr(len) * 0.3, close * (0.3/100)) [20] /2
|
||||||
|
|
||||||
|
Zband = volAdj(30)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
method Trendlines(float src, int timeIndex,bool dir) =>
|
||||||
|
|
||||||
|
var int Start = 1 , var int End = 0 , var int TIME = 1
|
||||||
|
var float YEnd = 0, var float YStart = 0 , var float Slope = 0
|
||||||
|
var line Line1 = line.new(na,na,na,na)
|
||||||
|
var line Line2 = line.new(na,na,na,na)
|
||||||
|
var line Line3 = line.new(na,na,na,na)
|
||||||
|
|
||||||
|
SCR = fixnan(src)
|
||||||
|
if ta.change(SCR) != 0
|
||||||
|
TIME := time[timeIndex]
|
||||||
|
YStart := SCR[1]
|
||||||
|
Start := TIME[1]
|
||||||
|
Slope := (SCR - YStart) / (TIME - Start)
|
||||||
|
Slope
|
||||||
|
|
||||||
|
EXTime = ExtenSwitcher(Extensions) * BarTIME * 25
|
||||||
|
End := TIME + EXTime
|
||||||
|
YEnd := SCR + EXTime * Slope
|
||||||
|
|
||||||
|
if ta.change(SCR) != 0 and not TradeisON[1]
|
||||||
|
LineCond = Slope * time < 0 ? dir ? na : color.rgb(11, 139, 7, 53) : dir ? color.rgb(212, 46, 0, 54) : na
|
||||||
|
if not na(LineCond) //and ChartTime
|
||||||
|
Line1 := line.new(Start,
|
||||||
|
YStart,
|
||||||
|
End,
|
||||||
|
YEnd,
|
||||||
|
xloc.bar_time,
|
||||||
|
extend.none,
|
||||||
|
color=color.new(color.white,100)
|
||||||
|
)
|
||||||
|
|
||||||
|
Line2:=line.new(Start,
|
||||||
|
YStart - (Zband * 2),
|
||||||
|
End,
|
||||||
|
YEnd - (Zband * 2),
|
||||||
|
xloc.bar_time,
|
||||||
|
extend.none,
|
||||||
|
color=color.new(color.black,100)
|
||||||
|
)
|
||||||
|
|
||||||
|
Line3:=line.new(Start,
|
||||||
|
YStart - (Zband * 1),
|
||||||
|
End,
|
||||||
|
YEnd - (Zband * 1),
|
||||||
|
xloc.bar_time,
|
||||||
|
extend.none,
|
||||||
|
color=color.new(color.black,100)
|
||||||
|
)
|
||||||
|
|
||||||
|
linefill.new(Line3,Line2,color= LineCol1)
|
||||||
|
linefill.new(Line3,Line1,color= LineCond)
|
||||||
|
// linefill.new(Line,Line2,color= color.rgb(28, 15, 2, 76))
|
||||||
|
|
||||||
|
[Start, YStart, Slope]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PH = ta.pivothigh(Trendtype ? high : close > open ? close : open, Period, Period / 2)
|
||||||
|
PL = ta.pivotlow(Trendtype ? low : close > open ? open : close, Period, Period / 2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
method GetlinePrice(int TIME, float Price, float SLOP, int LookB) =>
|
||||||
|
var float Current = 0.0
|
||||||
|
EsTime = time - TIME
|
||||||
|
Current := Price + (EsTime - LookB * BarTIME) * SLOP
|
||||||
|
Current
|
||||||
|
|
||||||
|
|
||||||
|
method CheckCross(float Price, int StartTime, float StartPrice, float SLP) =>
|
||||||
|
var float Current = 0.0
|
||||||
|
var float Previous = 0.0
|
||||||
|
if StartPrice[Period] != StartPrice
|
||||||
|
Current := GetlinePrice(StartTime, StartPrice, SLP, 0)
|
||||||
|
Previous := GetlinePrice(StartTime, StartPrice, SLP, 1)
|
||||||
|
Crossover = Price[1] < Previous and Price > Current ? 1 : Price[1] > Previous - (Zband*0.1) and Price < Current - (Zband*0.1) ? -1 : 0
|
||||||
|
Crossover
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[Xx, XZ, SLPXZ] = Trendlines(PH, Period / 2,false)
|
||||||
|
[XxL, XZL, SLPXZL] = Trendlines(PL, Period / 2, true)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if ta.change(fixnan(PH)) != 0
|
||||||
|
UpdatedX := Xx
|
||||||
|
UpdatedY := XZ
|
||||||
|
UpdatedSLP := SLPXZ
|
||||||
|
UpdatedSLP
|
||||||
|
|
||||||
|
if ta.change(fixnan(PL)) != 0
|
||||||
|
UpdatedXLow := XxL
|
||||||
|
UpdatedYLow := XZL
|
||||||
|
UpdatedSLPLow := SLPXZL
|
||||||
|
UpdatedSLPLow
|
||||||
|
|
||||||
|
Long = not (UpdatedSLP * time > 0)
|
||||||
|
and CheckCross(close, UpdatedX, UpdatedY, UpdatedSLP)== 1
|
||||||
|
and not TradeisON
|
||||||
|
Short = not (UpdatedSLPLow * time < 0)
|
||||||
|
and CheckCross(close, UpdatedXLow, UpdatedYLow, UpdatedSLPLow)==-1
|
||||||
|
and not TradeisON
|
||||||
|
|
||||||
|
|
||||||
|
TradeFire = Long or Short
|
||||||
|
|
||||||
|
if Long and not TradeisON
|
||||||
|
LongTrade:= true
|
||||||
|
ShortTrade:= false
|
||||||
|
|
||||||
|
if Short and not TradeisON
|
||||||
|
LongTrade:= false
|
||||||
|
ShortTrade:= true
|
||||||
|
|
||||||
|
|
||||||
|
if true
|
||||||
|
if TradeFire and not TradeisON
|
||||||
|
TP := switch
|
||||||
|
Long => high + (Zband *20)
|
||||||
|
Short => low - (Zband *20)
|
||||||
|
|
||||||
|
SL := switch
|
||||||
|
Long => low - (Zband *20)
|
||||||
|
Short => high + (Zband *20)
|
||||||
|
|
||||||
|
TradeisON:= true
|
||||||
|
if ShowTargets
|
||||||
|
line.new(bar_index,
|
||||||
|
Long ? high : low,
|
||||||
|
bar_index,
|
||||||
|
TP,
|
||||||
|
width=2,
|
||||||
|
color = color.rgb(154, 103, 20),
|
||||||
|
style= line.style_dashed)
|
||||||
|
|
||||||
|
tpLine:= line.new(bar_index,
|
||||||
|
TP,
|
||||||
|
bar_index+2,
|
||||||
|
TP,
|
||||||
|
style= line.style_dashed,
|
||||||
|
color = color.rgb(154, 103, 20)
|
||||||
|
)
|
||||||
|
LAB:=label.new(bar_index,
|
||||||
|
TP,
|
||||||
|
"Target",
|
||||||
|
color = color.rgb(154, 103, 20),
|
||||||
|
style= label.style_label_left,
|
||||||
|
size=size.small,
|
||||||
|
textcolor = color.white
|
||||||
|
)
|
||||||
|
if TradeisON
|
||||||
|
line.set_x2(tpLine,bar_index)
|
||||||
|
label.set_x(LAB,bar_index+1)
|
||||||
|
|
||||||
|
if LongTrade and TradeisON
|
||||||
|
if high >= TP
|
||||||
|
label.set_color(LAB,color.rgb(6, 128, 10, 37))
|
||||||
|
TradeisON:=false
|
||||||
|
if close <= SL
|
||||||
|
label.set_color(LAB,color.new(color.rgb(246, 7, 7),70))
|
||||||
|
TradeisON:=false
|
||||||
|
|
||||||
|
else if ShortTrade and TradeisON
|
||||||
|
|
||||||
|
if low <= TP
|
||||||
|
label.set_color(LAB,color.rgb(6, 128, 10, 37))
|
||||||
|
TradeisON:=false
|
||||||
|
|
||||||
|
if close >= SL
|
||||||
|
label.set_color(LAB,color.new(color.rgb(246, 7, 7),70))
|
||||||
|
TradeisON:=false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
plotshape(Long and not TradeisON[1],
|
||||||
|
size = size.small,
|
||||||
|
color = color.rgb(46, 192, 6, 11),
|
||||||
|
location = location.belowbar,
|
||||||
|
style = shape.labelup ,
|
||||||
|
text = "",
|
||||||
|
textcolor = color.white)
|
||||||
|
|
||||||
|
plotshape(Short and not TradeisON[1],
|
||||||
|
size = size.small,
|
||||||
|
color = color.rgb(241, 2, 2, 11),
|
||||||
|
location = location.abovebar,
|
||||||
|
style = shape.labeldown ,
|
||||||
|
text = "",
|
||||||
|
textcolor = color.white)
|
||||||
|
|
||||||
|
|
||||||
|
// -- END -- .
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||||
|
// © LuxAlgo
|
||||||
|
|
||||||
|
//@version=5
|
||||||
|
indicator("Trendlines with Breaks [LuxAlgo]", "LuxAlgo - Trendlines with Breaks", overlay = true)
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
//Settings
|
||||||
|
//-----------------------------------------------------------------------------{
|
||||||
|
length = input.int(14, 'Swing Detection Lookback')
|
||||||
|
mult = input.float(1., 'Slope', minval = 0, step = .1)
|
||||||
|
calcMethod = input.string('Atr', 'Slope Calculation Method', options = ['Atr','Stdev','Linreg'])
|
||||||
|
backpaint = input(true, tooltip = 'Backpainting offset displayed elements in the past. Disable backpainting to see real time information returned by the indicator.')
|
||||||
|
|
||||||
|
//Style
|
||||||
|
upCss = input.color(color.teal, 'Up Trendline Color', group = 'Style')
|
||||||
|
dnCss = input.color(color.red, 'Down Trendline Color', group = 'Style')
|
||||||
|
showExt = input(true, 'Show Extended Lines')
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------}
|
||||||
|
//Calculations
|
||||||
|
//-----------------------------------------------------------------------------{
|
||||||
|
var upper = 0.
|
||||||
|
var lower = 0.
|
||||||
|
var slope_ph = 0.
|
||||||
|
var slope_pl = 0.
|
||||||
|
|
||||||
|
var offset = backpaint ? length : 0
|
||||||
|
|
||||||
|
n = bar_index
|
||||||
|
src = close
|
||||||
|
|
||||||
|
ph = ta.pivothigh(length, length)
|
||||||
|
pl = ta.pivotlow(length, length)
|
||||||
|
|
||||||
|
//Slope Calculation Method
|
||||||
|
slope = switch calcMethod
|
||||||
|
'Atr' => ta.atr(length) / length * mult
|
||||||
|
'Stdev' => ta.stdev(src,length) / length * mult
|
||||||
|
'Linreg' => math.abs(ta.sma(src * n, length) - ta.sma(src, length) * ta.sma(n, length)) / ta.variance(n, length) / 2 * mult
|
||||||
|
|
||||||
|
//Get slopes and calculate trendlines
|
||||||
|
slope_ph := ph ? slope : slope_ph
|
||||||
|
slope_pl := pl ? slope : slope_pl
|
||||||
|
|
||||||
|
upper := ph ? ph : upper - slope_ph
|
||||||
|
lower := pl ? pl : lower + slope_pl
|
||||||
|
|
||||||
|
var upos = 0
|
||||||
|
var dnos = 0
|
||||||
|
upos := ph ? 0 : close > upper - slope_ph * length ? 1 : upos
|
||||||
|
dnos := pl ? 0 : close < lower + slope_pl * length ? 1 : dnos
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------}
|
||||||
|
//Extended Lines
|
||||||
|
//-----------------------------------------------------------------------------{
|
||||||
|
var uptl = line.new(na,na,na,na, color = upCss, style = line.style_dashed, extend = extend.right)
|
||||||
|
var dntl = line.new(na,na,na,na, color = dnCss, style = line.style_dashed, extend = extend.right)
|
||||||
|
|
||||||
|
if ph and showExt
|
||||||
|
uptl.set_xy1(n-offset, backpaint ? ph : upper - slope_ph * length)
|
||||||
|
uptl.set_xy2(n-offset+1, backpaint ? ph - slope : upper - slope_ph * (length+1))
|
||||||
|
|
||||||
|
if pl and showExt
|
||||||
|
dntl.set_xy1(n-offset, backpaint ? pl : lower + slope_pl * length)
|
||||||
|
dntl.set_xy2(n-offset+1, backpaint ? pl + slope : lower + slope_pl * (length+1))
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------}
|
||||||
|
//Plots
|
||||||
|
//-----------------------------------------------------------------------------{
|
||||||
|
plot(backpaint ? upper : upper - slope_ph * length, 'Upper', color = ph ? na : upCss, offset = -offset)
|
||||||
|
plot(backpaint ? lower : lower + slope_pl * length, 'Lower', color = pl ? na : dnCss, offset = -offset)
|
||||||
|
|
||||||
|
//Breakouts
|
||||||
|
plotshape(upos > upos[1] ? low : na, "Upper Break"
|
||||||
|
, shape.labelup
|
||||||
|
, location.absolute
|
||||||
|
, upCss
|
||||||
|
, text = "B"
|
||||||
|
, textcolor = color.white
|
||||||
|
, size = size.tiny)
|
||||||
|
|
||||||
|
plotshape(dnos > dnos[1] ? high : na, "Lower Break"
|
||||||
|
, shape.labeldown
|
||||||
|
, location.absolute
|
||||||
|
, dnCss
|
||||||
|
, text = "B"
|
||||||
|
, textcolor = color.white
|
||||||
|
, size = size.tiny)
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------}
|
||||||
|
//Alerts
|
||||||
|
//-----------------------------------------------------------------------------{
|
||||||
|
alertcondition(upos > upos[1], 'Upward Breakout', 'Price broke the down-trendline upward')
|
||||||
|
alertcondition(dnos > dnos[1], 'Downward Breakout', 'Price broke the up-trendline downward')
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------}
|
||||||
Reference in New Issue
Block a user