0% found this document useful (0 votes)
9 views

HV

The document is a source code for a trading indicator named 'Semafor' written in Pine Script version 5. It includes functions for calculating daily open lines, average daily range, and various zigzag patterns with customizable parameters. The code is subject to the Mozilla Public License 2.0 and allows for user interaction through input parameters.

Uploaded by

zakarie
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)
9 views

HV

The document is a source code for a trading indicator named 'Semafor' written in Pine Script version 5. It includes functions for calculating daily open lines, average daily range, and various zigzag patterns with customizable parameters. The code is subject to the Mozilla Public License 2.0 and allows for user interaction through input parameters.

Uploaded by

zakarie
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
You are on page 1/ 7

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

0 at
https://mozilla.org/MPL/2.0/
// © DevLucem
// you can request code usage by messaging me

//@version=5

////////
// Preheat Oven
// [
indicator('Semafor', overlay=true, max_labels_count=300)
// ]

////////
// Bake Water With Vinegar For 20 Minutes
// [
repaint = input(false, 'Allow Drawing Of Unconfirmed Levels')
zigzag(Depth, Deviation, Color, Size, Type) =>
var lw = 1
var hg = 1
lw += 1
hg += 1
p_lw = -ta.lowestbars(Depth)
p_hg = -ta.highestbars(Depth)
lowing = lw == p_lw or low - low[p_lw] > Deviation * syminfo.mintick
highing = hg == p_hg or high[p_hg] - high > Deviation * syminfo.mintick
lh = ta.barssince(not highing)
ll = ta.barssince(not lowing)
down = lh > ll
lower = low[lw] > low[p_lw]
higher = high[hg] < high[p_hg]
if lw != p_lw and (not down[1] or lower)
lw := p_lw < hg ? p_lw : 0
lw
if hg != p_hg and (down[1] or higher)
hg := p_hg < lw ? p_hg : 0
hg
x1 = down ? lw : hg
y1 = down ? low[lw] : high[hg]
lb = down ? label.style_label_up : label.style_label_down
label point = na
if repaint
point := label.new(bar_index - x1, y1, color=Color,
style=label.style_circle, size=Size)
if down == down[1]
label.delete(point[1])
if not repaint and down != down[1]
nx = down ? hg : lw
point := label.new(bar_index - nx, down ? high[nx] : low[nx], color=Color,
style=label.style_circle, size=Size)
point
down != down[1]
// ]

////////
// Serve While Hot
// [
switch_1 = false
if input(true, 'X-Large')
switch_1 := zigzag(input(615, 'Depth'), input(36.0, 'Deviation'),
input(color.yellow, 'Color'), size.huge, 'X-Large') or switch_1
switch_1
if input(true, 'Large')
switch_1 := zigzag(input(150, 'Depth'), input(24.0, 'Deviation'),
input(#f9f3f3, 'Color'), size.large, 'Large') or switch_1
switch_1
if input(true, 'Medium')
switch_1 := zigzag(input(41, 'Depth'), input(6.0, 'Deviation'), input(#2b00ff,
'Color'), size.small, 'Medium') or switch_1
switch_1
if input(false, 'X-Small')
switch_1 := zigzag(input(10, 'Depth'), input(3.0, 'Deviation'), input(#090909,
'Color'), size.tiny, 'Small') or switch_1
// ]

////////
// Monchoka Juu Unajinauwo
// [

switch_1 := zigzag(input(144, 'Depth'), input(24.0, 'Deviation'),


input(#f9f3f3, 'Color'), size.normal, 'Large') or switch_1
switch_1 := zigzag(input(144, 'Depth'), input(24.0, 'Deviation'),
input(#f9f3f3, 'Color'), size.normal, 'Large') or switch_1
switch_1 := zigzag(input(144, 'Depth'), input(24.0, 'Deviation'),
input(#f9f3f3, 'Color'), size.normal, 'Large') or switch_1
switch_1
// ]
// Daily Open Line (DOL)
bool showPrev = input(false, 'Print Previous Daily Open Alongside Next',
group='------------------------------ Daily Open ------------------------------')
bool showMore = input(false, 'Print Daily Open From Two Days Ago',
group='------------------------------ Daily Open ------------------------------')
bool showAvg = input(false, 'Show Average of Current and Previous',
group='------------------------------ Daily Open ------------------------------')

daily_open(x) =>
trigger = na(time('D')) or ta.change(time('D'))
ta.valuewhen(trigger, open, x)

plot(daily_open(0), 'Daily Open', color.new(color.blue, 0), 2, plot.style_circles)


plot(showPrev ? daily_open(1) : na, 'Previous Daily Open', color.new(color.gray,
0), 2, plot.style_circles)
plot(showMore ? daily_open(2) : na, 'Previously Previous Daily Open',
color.new(color.gray, 0), 2, plot.style_circles)

plot(showAvg ? math.avg(daily_open(0), daily_open(1)) : na, 'DOL Average line.',


color.new(color.silver, 0), 1, plot.style_circles)

//Average Daily Range (ADR)


hist_values = input.bool(defval = false, title = 'Show Past ADRs?', group =
'------------------------------ ADR ------------------------------')
res = input.timeframe(defval = 'D', title = 'Resolution', options =
['D','W','M'], group = '------------------------------ ADR
------------------------------')

//Functions
daily_calc() =>
[day_one_high, day_one_low] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), res, [high[1], low[1]], lookahead = barmerge.lookahead_on)
[day_two_high, day_two_low] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), res, [high[2], low[2]], lookahead = barmerge.lookahead_on)
[day_three_high, day_three_low] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), res, [high[3], low[3]], lookahead = barmerge.lookahead_on)
[day_four_high, day_four_low] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), res, [high[4], low[4]], lookahead = barmerge.lookahead_on)
[day_five_high, day_five_low] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), res, [high[5], low[5]], lookahead = barmerge.lookahead_on)

adr = ((day_one_high - day_one_low) + (day_two_high - day_two_low) +


(day_three_high - day_three_low) + (day_four_high - day_four_low) + (day_five_high
- day_five_low)) / 5

yesterday_calc() =>
[day_one_high, day_one_low] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), res, [high[1], low[1]], lookahead = barmerge.lookahead_on)

y_move = day_one_high - day_one_low

yesterday_adr() =>
[day_one_high, day_one_low] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), res, [high[2], low[2]], lookahead = barmerge.lookahead_on)
[day_two_high, day_two_low] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), res, [high[3], low[3]], lookahead = barmerge.lookahead_on)
[day_three_high, day_three_low] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), res, [high[4], low[4]], lookahead = barmerge.lookahead_on)
[day_four_high, day_four_low] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), res, [high[5], low[5]], lookahead = barmerge.lookahead_on)
[day_five_high, day_five_low] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), res, [high[6], low[6]], lookahead = barmerge.lookahead_on)

y_adr = ((day_one_high - day_one_low) + (day_two_high - day_two_low) +


(day_three_high - day_three_low) + (day_four_high - day_four_low) + (day_five_high
- day_five_low)) / 5

nround(x) =>
n = math.round(x / syminfo.mintick) * syminfo.mintick

pip_to_whole(number) =>
atr = ta.atr(14)
if syminfo.type == 'forex'
pips = atr < 1.0 ? (number / syminfo.mintick) / 10 : number
pips := atr >= 1.0 and atr < 100.0 and (syminfo.currency == 'JPY' or
syminfo.currency == 'HUF' or syminfo.currency == 'INR') ? pips * 100 : pips
else if syminfo.type == 'crypto'
pips = atr < 1.0 ? (number / syminfo.mintick) / 10 : number
pips := atr >= 1.0 ? pips * 100 : pips
else
number

//Function Calls
adr = daily_calc()
adr_pips = pip_to_whole(adr)
adr_pips := math.round(adr_pips)

y_move = yesterday_calc()
y_move_pips = pip_to_whole(y_move)
y_move_pips := math.round(y_move_pips)

y_move_75 = yesterday_adr()
y_move_p = pip_to_whole(y_move_75)
y_move_p := math.round(y_move_p)
y_move_75_pips = y_move_p * 0.75
y_move_75_pips := math.round(y_move_75_pips)

//Daily Open Calls


dopen = request.security(ticker.new(syminfo.prefix, syminfo.ticker), res, open,
lookahead = barmerge.lookahead_on)
[dday, dclose_y, dclose_t] = request.security(ticker.new(syminfo.prefix,
syminfo.ticker), res, [time_tradingday, time_close(res)[1], time_close(res)],
lookahead = barmerge.lookahead_on)

//Line / Label Vars and ADR Calculations


var line tl = na
var line high_100 = na
var line high_75 = na
var line high_50 = na
var line high_25 = na
var line high_15 = na
var line low_15 = na
var line low_25 = na
var line low_50 = na
var line low_75 = na
var line low_100 = na

//Labels
var label label_t1_open = na
var label label_high_100 = na
var label label_high_75 = na
var label label_high_50 = na
var label label_high_25 = na
var label label_high_15 = na
var label label_low_15 = na
var label label_low_25 = na
var label label_low_50 = na
var label label_low_75 = na
var label label_low_100 = na

//ADR Percentage Calculations


high_100_p = dopen + adr
high_75_p = dopen + adr * 0.75
high_50_P = dopen + adr * 0.50
high_25_p = dopen + adr * 0.25
high_15_p = dopen + adr * 0.15

low_15_p = dopen - adr * 0.15


low_25_p = dopen - adr * 0.25
low_50_p = dopen - adr * 0.50
low_75_p = dopen - adr * 0.75
low_100_p = dopen - adr

//Lines and Labels


if hist_values
if ta.change(dclose_y)
tl := line.new(dclose_y, dopen, dclose_t, dopen , xloc =
xloc.bar_time, color = color.new(color.white, 40), style = line.style_solid)
high_100 := line.new(dclose_y, high_100_p, dclose_t, high_100_p, color
= color.new(#5bd50f, 10), style = line.style_solid, xloc = xloc.bar_time)
high_75 := line.new(dclose_y, high_75_p, dclose_t, high_75_p, color
= color.new(#5bd50f, 20), style = line.style_solid, xloc = xloc.bar_time)
high_50 := line.new(dclose_y, high_50_P, dclose_t, high_50_P, color
= color.new(#5bd50f, 30), style = line.style_solid, xloc = xloc.bar_time)
high_25 := line.new(dclose_y, high_25_p, dclose_t, high_25_p, color
= color.new(#5bd50f, 40), style = line.style_solid, xloc = xloc.bar_time)
high_15 := line.new(dclose_y, high_15_p, dclose_t, high_15_p, color
= color.new(#5bd50f, 40), style = line.style_solid, xloc = xloc.bar_time)
low_15 := line.new(dclose_y, low_15_p, dclose_t, low_15_p, color
= color.new(#ea2700, 40), style = line.style_solid, xloc = xloc.bar_time)
low_25 := line.new(dclose_y, low_25_p, dclose_t, low_25_p, color
= color.new(#ea2700, 40), style = line.style_solid, xloc = xloc.bar_time)
low_50 := line.new(dclose_y, low_50_p, dclose_t, low_50_p, color
= color.new(#ea2700, 30), style = line.style_solid, xloc = xloc.bar_time)
low_75 := line.new(dclose_y, low_75_p, dclose_t, low_75_p, color
= color.new(#ea2700, 20), style = line.style_solid, xloc = xloc.bar_time)
low_100 := line.new(dclose_y, low_100_p, dclose_t, low_100_p, color
= color.new(#ea2700, 10), style = line.style_solid, xloc = xloc.bar_time)
else
tl := line.new(dclose_y, dopen, last_bar_time, dopen , xloc =
xloc.bar_time, color = color.new(color.white, 40), style = line.style_solid)
high_100 := line.new(dclose_y, high_100_p, last_bar_time, high_100_p, color
= color.new(#5bd50f, 10), style = line.style_solid, xloc = xloc.bar_time)
high_75 := line.new(dclose_y, high_75_p, last_bar_time, high_75_p, color
= color.new(#5bd50f, 20), style = line.style_solid, xloc = xloc.bar_time)
high_50 := line.new(dclose_y, high_50_P, last_bar_time, high_50_P, color
= color.new(#5bd50f, 30), style = line.style_solid, xloc = xloc.bar_time)
high_25 := line.new(dclose_y, high_25_p, last_bar_time, high_25_p, color
= color.new(#5bd50f, 40), style = line.style_solid, xloc = xloc.bar_time)
high_15 := line.new(dclose_y, high_15_p, last_bar_time, high_15_p, color
= color.new(#5bd50f, 40), style = line.style_solid, xloc = xloc.bar_time)
low_15 := line.new(dclose_y, low_15_p, last_bar_time, low_15_p, color
= color.new(#ea2700, 40), style = line.style_solid, xloc = xloc.bar_time)
low_25 := line.new(dclose_y, low_25_p, last_bar_time, low_25_p, color
= color.new(#ea2700, 40), style = line.style_solid, xloc = xloc.bar_time)
low_50 := line.new(dclose_y, low_50_p, last_bar_time, low_50_p, color
= color.new(#ea2700, 30), style = line.style_solid, xloc = xloc.bar_time)
low_75 := line.new(dclose_y, low_75_p, last_bar_time, low_75_p, color
= color.new(#ea2700, 20), style = line.style_solid, xloc = xloc.bar_time)
low_100 := line.new(dclose_y, low_100_p, last_bar_time, low_100_p, color
= color.new(#ea2700, 10), style = line.style_solid, xloc = xloc.bar_time)

//Labels
label_t1_open := label.new(last_bar_time, dopen, size = size.normal, text
= ' ' + 'Open | ' + str.tostring(dopen,
format.mintick), style = label.style_none, textcolor = color.new(color.white, 10),
xloc = xloc.bar_time)
label_high_100 := label.new(last_bar_time, high_100_p, size = size.normal, text
= ' ' + '100% | ' +
str.tostring(math.round(adr_pips)) + ' Pips' + ' | ' + str.tostring(high_100_p,
format.mintick), style = label.style_none, textcolor = color.new(#5bd50f, 10), xloc
= xloc.bar_time)
label_high_75 := label.new(last_bar_time, high_75_p, size = size.normal, text
= ' ' + '75% | ' +
str.tostring(math.round(adr_pips * 0.75)) + ' Pips' + ' | ' +
str.tostring(high_75_p, format.mintick), style = label.style_none, textcolor =
color.new(#5bd50f, 10), xloc = xloc.bar_time)
label_high_50 := label.new(last_bar_time, high_50_P, size = size.normal, text
= ' ' + '50% | ' +
str.tostring(math.round(adr_pips * 0.50)) + ' Pips' + ' | ' +
str.tostring(high_50_P, format.mintick), style = label.style_none, textcolor =
color.new(#5bd50f, 10), xloc = xloc.bar_time)
label_high_25 := label.new(last_bar_time, high_25_p, size = size.normal, text
= ' ' + '25% | ' +
str.tostring(math.round(adr_pips * 0.25)) + ' Pips' + ' | ' +
str.tostring(high_25_p, format.mintick), style = label.style_none, textcolor =
color.new(#5bd50f, 10), xloc = xloc.bar_time)
label_high_15 := label.new(last_bar_time, high_15_p, size = size.normal, text
= ' ' + '15% | ' +
str.tostring(math.round(adr_pips * 0.15)) + ' Pips' + ' | ' +
str.tostring(high_15_p, format.mintick), style = label.style_none, textcolor =
color.new(#5bd50f, 10), xloc = xloc.bar_time)
label_low_15 := label.new(last_bar_time, low_15_p, size = size.normal, text
= ' ' + '15% | ' +
str.tostring(math.round(adr_pips * 0.15)) + ' Pips' + ' | ' +
str.tostring(low_15_p, format.mintick), style = label.style_none, textcolor =
color.new(#ea2700, 10), xloc = xloc.bar_time)
label_low_25 := label.new(last_bar_time, low_25_p, size = size.normal, text
= ' ' + '25% | ' +
str.tostring(math.round(adr_pips * 0.25)) + ' Pips' + ' | ' +
str.tostring(low_25_p, format.mintick), style = label.style_none, textcolor =
color.new(#ea2700, 10), xloc = xloc.bar_time)
label_low_50 := label.new(last_bar_time, low_50_p, size = size.normal, text
= ' ' + '50% | ' +
str.tostring(math.round(adr_pips * 0.50)) + ' Pips' + ' | ' +
str.tostring(low_50_p, format.mintick), style = label.style_none, textcolor =
color.new(#ea2700, 10), xloc = xloc.bar_time)
label_low_75 := label.new(last_bar_time, low_75_p, size = size.normal, text
= ' ' + '75% | ' +
str.tostring(math.round(adr_pips * 0.75)) + ' Pips' + ' | ' +
str.tostring(low_75_p, format.mintick), style = label.style_none, textcolor =
color.new(#ea2700, 10), xloc = xloc.bar_time)
label_low_100 := label.new(last_bar_time, low_100_p, size = size.normal, text
= ' ' + '100% | ' +
str.tostring(math.round(adr_pips)) + ' Pips' + ' | ' + str.tostring(low_100_p,
format.mintick), style = label.style_none, textcolor = color.new(#ea2700, 10), xloc
= xloc.bar_time)

//Delete Label
label.delete(label_t1_open[1])
label.delete(label_high_100[1])
label.delete(label_high_75[1])
label.delete(label_high_50[1])
label.delete(label_high_25[1])
label.delete(label_high_15[1])
label.delete(label_low_15[1])
label.delete(label_low_25[1])
label.delete(label_low_50[1])
label.delete(label_low_75[1])
label.delete(label_low_100[1])

//Delete Line
line.delete(tl[1])
line.delete(high_100[1])
line.delete(high_75[1])
line.delete(high_50[1])
line.delete(high_25[1])
line.delete(high_15[1])
line.delete(low_15[1])
line.delete(low_25[1])
line.delete(low_50[1])
line.delete(low_75[1])
line.delete(low_100[1])

// ( (
// )\ ) )\ )
// (()/( ( ) (()/( ( ( )
// /(_)) ))\ /(( /(_)) ))\ ( ))\ (
// (_))_ /((_)(_))\ (_)) /((_) )\ /((_) )\ '
// | \ (_)) _)((_) | | (_))( ((_)(_)) _((_))
// | |) |/ -_) \ V / | |__| || |/ _| / -_)| ' \()
// |___/ \___| \_/ |____|\_,_|\__| \___||_|_|_|

// ** you can request code usage by messaging me! ** //

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy