Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/

//Revision History
//v31.0
//Added label for each High/Low
//Added alert for crossing each High/Low
//v32.0
//Minor correction on labels

//@version=4
//Define indicator name
study("High Low Yesterday & Today & Last week & Last
month",overlay=true,shorttitle="High Low Yesterday/Today/Last week/Last month")

//Users input
chk_yh = input(title="PDH", defval=true)
chk_yl = input(title="PDL", defval=true)
chk_th = input(title="High", defval=true)
chk_tl = input(title="Low", defval=true)
chk_lwh = input(title="Week High", defval=true)
chk_lwl = input(title="Week Low", defval=true)
chk_lmh = input(title="Month High", defval=true)
chk_lml = input(title="Month Low", defval=true)
show_labels = input(title="Show Labels?", defval=true)
size_labels = input(title="Label font size", defval=size.normal, options =
[size.large,size.normal,size.small])
color_labels = input(title="Label font color", defval=color.black)

//Get High&Low Price


isess = session.regular
t = tickerid(syminfo.prefix, syminfo.ticker, session=isess)
igaps = barmerge.gaps_off
yesterdayHigh = security(t,"D",high[1],gaps=igaps, lookahead=barmerge.lookahead_on)
yesterdayLow = security(t,"D",low[1],gaps=igaps, lookahead=barmerge.lookahead_on)
lastweekHigh = security(t,"W",high[1],gaps=igaps, lookahead=barmerge.lookahead_on)
lastweekLow = security(t,"W",low[1],gaps=igaps, lookahead=barmerge.lookahead_on)
lastmonthHigh = security(t,"M",high[1],gaps=igaps, lookahead=barmerge.lookahead_on)
lastmonthLow = security(t,"M",low[1],gaps=igaps, lookahead=barmerge.lookahead_on)
todayHigh = security(t,"D",high[0],gaps=igaps, lookahead=barmerge.lookahead_on)
todayLow = security(t,"D",low[0],gaps=igaps, lookahead=barmerge.lookahead_on)

// Plot the other time frame's data


a=plot(timeframe.isintraday ? chk_yh ? yesterdayHigh : na : na, linewidth=1, title
= "PDH", color=color.green)
b=plot(timeframe.isintraday ? chk_yl ? yesterdayLow : na : na, linewidth=1, title =
"PDL", color=color.red)
c=plot(timeframe.isintraday ? chk_th ? todayHigh : na : na, linewidth=1, title =
"High", color=color.black )
d=plot(timeframe.isintraday ? chk_tl ? todayLow : na : na, linewidth=1, title =
"Low",color=color.maroon )
e=plot(timeframe.isintraday ? chk_lwh ? lastweekHigh : na : timeframe.isdaily ?
chk_lwh ? lastweekHigh : na : na, linewidth=1, title = "Last Week's High",
color=color.navy )
f=plot(timeframe.isintraday ? chk_lwl ? lastweekLow : na : timeframe.isdaily ?
chk_lwl ? lastweekLow : na : na, linewidth=1, title = "Last Week's
Low",color=color.orange)
g=plot(timeframe.isintraday ? chk_lmh ? lastmonthHigh : na : timeframe.isdaily ?
chk_lmh ? lastmonthHigh : na : timeframe.isweekly ? chk_lmh ? lastmonthHigh : na :
na, linewidth=1, title = "Last Month's High", color=color.purple )
h=plot(timeframe.isintraday ? chk_lml ? lastmonthLow : na: timeframe.isdaily ?
chk_lml ? lastmonthLow : na : timeframe.isweekly ? chk_lml ? lastmonthLow : na :
na, linewidth=1, title = "Last Month's Low",color=color.blue)

//Draw labels
if show_labels == true
if chk_yh == true and timeframe.isintraday == true
label YES_HIGH = label.new(bar_index, yesterdayHigh, "PDH",
style=label.style_none, textcolor = color_labels, size = size_labels, textalign =
text.align_right), label.delete(YES_HIGH[1])
if chk_yl == true and timeframe.isintraday == true
label YES_LOW = label.new(bar_index, yesterdayLow, "PDL",
style=label.style_none, textcolor = color_labels, size = size_labels, textalign =
text.align_right), label.delete(YES_LOW[1])
if chk_th == true and timeframe.isintraday == true
label TOD_HIGH = label.new(bar_index, todayHigh, "High",
style=label.style_none, textcolor = color_labels, size = size_labels, textalign =
text.align_right), label.delete(TOD_HIGH[1])
if chk_tl == true and timeframe.isintraday == true
label TOD_LOW = label.new(bar_index, todayLow, "Low",
style=label.style_none, textcolor = color_labels, size = size_labels, textalign =
text.align_right), label.delete(TOD_LOW[1])
if chk_lwh == true and (timeframe.isintraday == true or timeframe.isdaily ==
true)
label LWEEK_HIGH = label.new(bar_index, lastweekHigh, "Week High",
style=label.style_none, textcolor = color_labels, size = size_labels, textalign =
text.align_right), label.delete(LWEEK_HIGH[1])
if chk_lwl == true and (timeframe.isintraday == true or timeframe.isdaily ==
true)
label LWEEK_LOW = label.new(bar_index, lastweekLow, "Week Low",
style=label.style_none, textcolor = color_labels, size = size_labels, textalign =
text.align_right), label.delete(LWEEK_LOW[1])
if chk_lmh == true and (timeframe.isintraday == true or timeframe.isdaily ==
true or timeframe.isweekly == true)
label LMONTH_HIGH = label.new(bar_index, lastmonthHigh, "Month High",
style=label.style_none, textcolor = color_labels, size = size_labels, textalign =
text.align_right), label.delete(LMONTH_HIGH[1])
if chk_lml == true and (timeframe.isintraday == true or timeframe.isdaily ==
true or timeframe.isweekly == true)
label LMONTH_LOW = label.new(bar_index, lastmonthLow, "Month Low",
style=label.style_none, textcolor = color_labels, size = size_labels, textalign =
text.align_right), label.delete(LMONTH_LOW[1])

//Judge cross over/under with high/low


//Yesterday's High/Low
Al_co_yh = crossover(close, yesterdayHigh)
Al_cu_yl = crossunder(close, yesterdayLow)
//Today's High/Low
Al_co_th = crossover(close, todayHigh)
Al_cu_tl = crossunder(close, todayLow)
//Last Week's High/Low
Al_co_lwh = crossover(close, lastweekHigh)
Al_cu_lwl = crossunder(close, lastweekLow)
//Last Month's High/Low
Al_co_lmh = crossover(close, lastmonthHigh)
Al_cu_lml = crossunder(close, lastmonthLow)

//Alert condition
alertcondition(Al_co_yh, title="Cross over yesterday's High", message="Price
crosses over yesterday's High")
alertcondition(Al_cu_yl, title="Cross under yesterday's Low", message="Price
crosses under yesterday's Low")
alertcondition(Al_co_th, title="Cross over today's High", message="Price crosses
over today's High")
alertcondition(Al_cu_tl, title="Cross under today's Low", message="Price crosses
under today's Low")
alertcondition(Al_co_lwh, title="Cross over lastweek's High", message="Price
crosses over last week's High")
alertcondition(Al_cu_lwl, title="Cross under lastweek's Low", message="Price
crosses under last week's Low")
alertcondition(Al_co_lmh, title="Cross over lastmonth's High", message="Price
crosses over last month's High")
alertcondition(Al_cu_lml, title="Cross under lastmonth's Low", message="Price
crosses under last month's Low")

You might also like