0% found this document useful (0 votes)
160 views5 pages

LendX Stock Trend Analysis Script

This document describes a Pine Script study that draws trend lines based on pivot points and historical price data. It defines functions to calculate trend lines from high/low values and draw them on the chart. It also implements zigzag identification from high/low prices over multiple periods and displays the resulting zigzag lines and labels on the chart. Configuration options are provided to control display settings.

Uploaded by

Vipul Agrawal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
160 views5 pages

LendX Stock Trend Analysis Script

This document describes a Pine Script study that draws trend lines based on pivot points and historical price data. It defines functions to calculate trend lines from high/low values and draw them on the chart. It also implements zigzag identification from high/low prices over multiple periods and displays the resulting zigzag lines and labels on the chart. Configuration options are provided to control display settings.

Uploaded by

Vipul Agrawal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
  • Trading System Code

//@version=4

//author: wmx_Q_systen_trading
//this study simply draws a trend line base on pivot strength configuration,
// and also provide configuration by using the close price and show historical
trend lines

study( title="ZZ + WMX", shorttitle="ZZ + WMX", overlay=true)


useclose=input(false)

h=useclose?close:high
l=useclose?close:low

strength=input(10,title="left Strength", minval=5, maxval=200)

draw_trend(High, Low, leftlen,rightlen,n)=>

//upper trend line


var int startx=0
var float starty=0.0
var int startx2=0
var float starty2=0.0

var int endx=0


var float endy=0.0
var float endy0=0.0
var float slope=0.0
var bool ispivothigh =false

ispivothigh:=High[rightlen] == pivothigh(High,leftlen,rightlen)

starty2:=valuewhen(ispivothigh,High[rightlen],n+2)
startx2 := valuewhen(ispivothigh,bar_index,n+2)

starty:=valuewhen(ispivothigh,High[rightlen],n+1)
startx := valuewhen(ispivothigh,bar_index,n+1)

endy:=valuewhen(ispivothigh,High[rightlen],n)
endx := valuewhen(ispivothigh,bar_index,n)

slope:=(endy-starty)/(endx-startx)

valend = endy
var float Endy=0.0

Endy:=abs(endx-startx+rightlen)*slope + starty

if slope<0

if n==0
upper0 = [Link](endx, Endy, startx-rightlen, starty, width = 2,
color=[Link], extend=[Link])
[Link](upper0[1])

upper1 = [Link](endx, Endy, startx-rightlen, starty, width = 2,


color=[Link], extend=[Link])
[Link](upper1[1])
var float slope2= (endy-starty2)/(endx-startx2)
var float Endy2=0.0

Endy:=abs(endx-startx2+rightlen)*slope + starty2
if slope2<0
upper2 = [Link](endx, Endy2, startx2-rightlen, starty2, width = 2,
color=[Link], extend=[Link])
[Link](upper2[1])

//lower trend line


var int lstartx=0
var float lstarty=0.0
var int lstartx2=0
var float lstarty2=0.0

var int lendx=0


var float lendy=0.0
var float lendy0=0.0
var float lslope=0.0
var bool ispivotlow =false

ispivotlow:=Low[rightlen] == pivotlow(Low,leftlen,rightlen)

lstarty2:=valuewhen(ispivotlow,Low[rightlen],n+2)
lstartx2 := valuewhen(ispivotlow,bar_index,n+2)

lstarty:=valuewhen(ispivotlow,Low[rightlen],n+1)
lstartx := valuewhen(ispivotlow,bar_index,n+1)

lendy:=valuewhen(ispivotlow,Low[rightlen],n)
lendx := valuewhen(ispivotlow,bar_index,n)

lslope:=(lendy-lstarty)/(lendx-lstartx)
var float lEndy=0.0

lEndy:=abs(lendx-lstartx+rightlen)*lslope + lstarty

if lslope>0

if n==0
Lower0 = [Link](lendx, lEndy, lstartx-rightlen, lstarty, width = 2,
color=[Link], extend=[Link])
[Link](Lower0[1])

Lower1 = [Link](lendx, lEndy, lstartx-rightlen, lstarty, width = 2,


color=[Link], extend=[Link])
[Link](Lower1[1])

var float lslope2= (lendy-lstarty2)/(lendx-lstartx2)


var float lEndy2=0.0

lEndy:=abs(lendx-lstartx2+rightlen)*lslope + lstarty2
if lslope2>0
lower2 = [Link](lendx, lEndy2, lstartx2-rightlen, lstarty2, width = 2,
color=[Link], extend=[Link])
[Link](lower2[1])
left=strength
right=strength

//draw current trendling


draw_trend(h, l,left,right,0)

showhtrend=input(true, title="Show History Trend Line")

if showhtrend
//show history trendling
draw_trend(h, l,left,right,1)
draw_trend(h, l,left,right,2)
draw_trend(h, l,left,right,3)
draw_trend(h, l,left,right,4)
draw_trend(h, l,left,right,5)
draw_trend(h, l,left,right,6)
draw_trend(h, l,left,right,7)
draw_trend(h, l,left,right,8)
draw_trend(h, l,left,right,9)
draw_trend(h, l,left,right,10)
draw_trend(h, l,left,right,11)
draw_trend(h, l,left,right,12)

// This source code is subject to the terms of the Mozilla Public License 2.0 at
[Link]
// © LonesomeTheBlue

//@version=4

prd1 = input(defval = 8, title="ZigZag Period 1", minval = 2, maxval = 20)


prd2 = input(defval = 20, title="ZigZag Period 2", minval = 2, maxval = 50)
showzz = input(defval = "Show Both", title = "Show Zig Zags", options = ["Show Zig
Zag 1", "Show Zig Zag 2", "Show Both", "Show None"])
showhhll = input(defval = "Show Both", title = "Show HHLL", options = ["Show HHLL
1", "Show HHLL 2", "Show Both", "Show None"])
upcol1 = input(defval = [Link], title = "Zig Zag 1 Up Color")
dncol1 = input(defval = [Link], title = "Zig Zag 1 Down Color")
upcol2 = input(defval = [Link], title = "Zig Zag 2 Up Color")
dncol2 = input(defval = [Link], title = "Zig Zag 2 Down Color")
txtcol = input(defval = [Link], title = "Text Color")
zz1style = input(defval = "Dashed", title = "Zig Zag 1 Line Style", options =
["Dashed", "Dotted"])
zz1width = input(defval = 2, title = "Zig zag 1 Line Width", minval = 1, maxval =
4)
zz2width = input(defval = 3, title = "Zig zag 2 Line Width", minval = 1, maxval =
6)

float ph1 = highestbars(high, prd1) == 0 ? high : na


float pl1 = lowestbars(low, prd1) == 0 ? low : na
float ph2 = highestbars(high, prd2) == 0 ? high : na
float pl2 = lowestbars(low, prd2) == 0 ? low : na

var dir1 = 0
var dir2 = 0
dir1 := iff(ph1 and na(pl1), 1, iff(pl1 and na(ph1), -1, dir1))
dir2 := iff(ph2 and na(pl2), 1, iff(pl2 and na(ph2), -1, dir2))
var max_array_size = 10 // [5, 2] matrix
var zigzag1 = array.new_float(0)
var zigzag2 = array.new_float(0)

add_to_zigzag(pointer, value, bindex)=>


[Link](pointer, bindex)
[Link](pointer, value)
if [Link](pointer) > max_array_size
[Link](pointer)
[Link](pointer)

update_zigzag(pointer, value, bindex, dir)=>


if [Link](pointer) == 0
add_to_zigzag(pointer, value, bindex)
else
if (dir == 1 and value > [Link](pointer, 0)) or (dir == -1 and value <
[Link](pointer, 0))
[Link](pointer, 0, value)
[Link](pointer, 1, bindex)
0.

dir1changed = change(dir1)
if ph1 or pl1
if dir1changed
add_to_zigzag(zigzag1, dir1 == 1 ? ph1 : pl1, bar_index)
else
update_zigzag(zigzag1, dir1 == 1 ? ph1 : pl1, bar_index, dir1)

dir2changed = change(dir2)
if ph2 or pl2
if dir2changed
add_to_zigzag(zigzag2, dir2 == 1 ? ph2 : pl2, bar_index)
else
update_zigzag(zigzag2, dir2 == 1 ? ph2 : pl2, bar_index, dir2)

if [Link](zigzag1) >= 6
var line zzline1 = na
var label zzlabel1 = na
float val = [Link](zigzag1, 0)
int point = round([Link](zigzag1, 1))
if change(val) or change(point)
float val1 = [Link](zigzag1, 2)
int point1 = round([Link](zigzag1, 3))
if change(val1) == 0 and change(point1) == 0
[Link](zzline1)
[Link](zzlabel1)
if showzz == "Show Zig Zag 1" or showzz == "Show Both"
zzline1 := [Link](x1 = point, y1 = val, x2 = point1, y2 = val1, color
= dir1 == 1 ? upcol1 : dncol1, width = zz1width, style = zz1style == "Dashed" ?
line.style_dashed : line.style_dotted)
if showhhll == "Show HHLL 1" or showhhll == "Show Both"
hhlltxt = dir1 == 1 ? [Link](zigzag1, 0) > [Link](zigzag1, 4) ?
"HH" : "LH" : [Link](zigzag1, 0) < [Link](zigzag1, 4) ? "LL" : "HL"
labelcol = dir1 == 1 ? [Link](zigzag1, 0) > [Link](zigzag1, 4) ?
upcol1 : dncol1 : [Link](zigzag1, 0) < [Link](zigzag1, 4) ? dncol1 : upcol1
zzlabel1 := [Link](x = point, y = val, text = hhlltxt, color =
labelcol, textcolor = txtcol, style = dir1 == 1 ? label.style_label_down :
label.style_label_up)
if [Link](zigzag2) >= 6
var line zzline2 = na
var label zzlabel2 = na
float val = [Link](zigzag2, 0)
int point = round([Link](zigzag2, 1))
if change(val) or change(point)
float val1 = [Link](zigzag2, 2)
int point1 = round([Link](zigzag2, 3))
if change(val1) == 0 and change(point1) == 0
[Link](zzline2)
[Link](zzlabel2)
if showzz == "Show Zig Zag 2" or showzz == "Show Both"
zzline2 := [Link](x1 = point, y1 = val, x2 = point1, y2 = val1, color
= dir2 == 1 ? upcol2 : dncol2, width = zz2width)
if showhhll == "Show HHLL 2" or showhhll == "Show Both"
hhlltxt = dir2 == 1 ? [Link](zigzag2, 0) > [Link](zigzag2, 4) ?
"HH" : "LH" : [Link](zigzag2, 0) < [Link](zigzag2, 4) ? "LL" : "HL"
labelcol = dir2 == 1 ? [Link](zigzag2, 0) > [Link](zigzag2, 4) ?
upcol2 : dncol2 : [Link](zigzag2, 0) < [Link](zigzag2, 4) ? dncol2 : upcol2
zzlabel2 := [Link](x = point, y = val, text = hhlltxt, color =
labelcol, textcolor = txtcol, style = dir2 == 1 ? label.style_label_down :
label.style_label_up)

//@version=4
//author: wmx_Q_systen_trading
//this study simply draws a trend line base on pivot strength configuration,
// a
var float slope2= (endy-starty2)/(endx-startx2)
    var float Endy2=0.0
    Endy:=abs(endx-startx2+rightlen)*slope + star
left=strength
right=strength
//draw current trendling
draw_trend(h, l,left,right,0) 
showhtrend=input(true, title="Show Histo
var max_array_size = 10 // [5, 2] matrix
var zigzag1 = array.new_float(0)
var zigzag2 = array.new_float(0)
add_to_zigzag(poin
if array.size(zigzag2) >= 6
    var line zzline2 = na
    var label zzlabel2 = na
    float val = array.get(zigzag2, 0)
    i

You might also like