PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carefulCode53358
//@version=5
strategy("*", overlay = true, max_lines_count = 100, max_labels_count = 100, format=format.price)
//@version=5
// User inputs
prd22 = input.int(defval=2, title=' Period for Pivot Points', minval=1, maxval=50)
max_num_of_pivots = input.int(defval=5, title=' Maximum Number of Pivots', minval=5, maxval=10)
max_lines = input.int(defval=1, title=' Maximum number of trend lines', minval=1, maxval=10)
show_lines = input.bool(defval=true, title=' Show trend lines')
show_pivots = input.bool(defval=true, title=' Show Pivot Points')
float ph = ta.pivothigh(high, prd22, prd22)
float pl = ta.pivotlow(low, prd22, prd22)
//plotshape(ph and show_pivots, style=shape.triangledown, location=location.abovebar, offset=-prd22, size=size.small)
//plotshape(pl and show_pivots, style=shape.triangleup, location=location.belowbar, offset=-prd22, size=size.small)
// Creating array of pivots
var pivots_high = array.new_float(0)
var pivots_low = array.new_float(0)
var high_ind = array.new_int(0)
var low_ind = array.new_int(0)
if ph
array.push(pivots_high, ph)
array.push(high_ind, bar_index - prd22)
if array.size(pivots_high) > max_num_of_pivots // limit the array size
array.shift(pivots_high)
array.shift(high_ind)
if pl
array.push(pivots_low, pl)
array.push(low_ind, bar_index - prd22)
if array.size(pivots_low) > max_num_of_pivots // limit the array size
array.shift(pivots_low)
array.shift(low_ind)
// Create arrays to store slopes and lines
var res_lines = array.new_line()
var res_slopes = array.new_float()
len_lines = array.size(res_lines)
if (len_lines >= 1)
for ind = 0 to len_lines - 1
to_delete = array.pop(res_lines)
array.pop(res_slopes)
line.delete(to_delete)
// line.set_extend(to_delete, extend=extend.none)
count_slope(ph1, ph2, pos1, pos2) => (ph2 - ph1) / (pos2 - pos1)
if array.size(pivots_high) == max_num_of_pivots
index_of_biggest_slope = 0
for ind1 = 0 to max_num_of_pivots - 2
for ind2 = ind1 + 1 to max_num_of_pivots - 1
p1 = array.get(pivots_high, ind1)
p2 = array.get(pivots_high, ind2)
pos1 = array.get(high_ind, ind1)
pos2 = array.get(high_ind, ind2)
k = count_slope(p1, p2, pos1, pos2)
b = p1 - k * pos1
// ok = k * bar_index + b > high
ok = true
// label.new(pos1, p1, str.tostring(ok))
for ind3 = ind2 to max_num_of_pivots - 1
p3 = array.get(pivots_high, ind3)
pos3 = array.get(high_ind, ind3)
if p3 > k * pos3 + b
ok := false
// label.new(pos3, p3, 'cross')
break
if ind2 - ind1 >= 1
for ind3 = ind1 + 1 to ind2 - 1
p3 = array.get(pivots_high, ind3)
pos3 = array.get(high_ind, ind3)
if p3 > k * pos3 + b
ok := false
// label.new(pos3, p3, 'cross')
break
for ind = 0 to prd22 - 1
if high[ind] * 0.996 > k * bar_index[ind] + b
ok := false
break
if ok //and not (high > k * bar_index + b) // 'and not' for the last line to check if the crosses the price action
if array.size(res_slopes) < max_lines // max_lines // for now only 1 lines is to be shown
line = line.new(pos1, p1, pos2, p2, extend=extend.right)
array.push(res_lines, line)
array.push(res_slopes, k)
else
max_slope = array.max(res_slopes)
max_slope_ind = array.indexof(res_slopes, max_slope)
if max_lines == 1
max_slope_ind := 0
if k < max_slope
line_to_delete = array.get(res_lines, max_slope_ind)
line.delete(line_to_delete)
new_line = line.new(pos1, p1, pos2, p2, extend=extend.right)
array.insert(res_lines, max_slope_ind, new_line)
array.insert(res_slopes, max_slope_ind, k)
array.remove(res_lines, max_slope_ind + 1)
array.remove(res_slopes, max_slope_ind + 1)
// label.new(pos1, p1, str.tostring(res_slopes))
// if barstate.islast
// label.new(bar_index, high, str.tostring(array.size(res_lines)))
if array.size(res_lines) >= 1 and barstate.islast
for ind=0 to array.size(res_lines) - 1
l = array.get(res_lines, ind)
s = array.get(res_slopes, ind)
x1 = line.get_x1(l)
x2 = line.get_x2(l)
prev_lable_ind = 0//x2 + prd - 5
for ind1=x2 to bar_index
p = line.get_price(l, ind1)
if (math.abs(p - high[bar_index - ind1]) < p * 0.005)
if ind1 - prev_lable_ind > 10 and ind1 - x2 >= prd22
//label.new(ind1, high[bar_index - ind1], text='S', style=label.style_label_down, color=color.red)
prev_lable_ind := ind1
if not show_lines
len_l = array.size(res_lines)
if (len_l >= 1)
for ind = 0 to len_l - 1
to_delete = array.pop(res_lines)
array.pop(res_slopes)
line.delete(to_delete)
var sup_lines = array.new_line()
var sup_slopes = array.new_float()
len_lines1 = array.size(sup_lines)
if (len_lines1 >= 1)
for ind = 0 to len_lines1 - 1
to_delete = array.pop(sup_lines)
array.pop(sup_slopes)
line.delete(to_delete)
if array.size(pivots_low) == max_num_of_pivots
for ind1 = 0 to max_num_of_pivots - 2
for ind2 = ind1 + 1 to max_num_of_pivots - 1
p1 = array.get(pivots_low, ind1)
p2 = array.get(pivots_low, ind2)
pos1 = array.get(low_ind, ind1)
pos2 = array.get(low_ind, ind2)
k = count_slope(p1, p2, pos1, pos2)
b = p1 - k * pos1
// check if pivot points in the future are lower than the line between two points
ok = true
for ind3 = ind2 to max_num_of_pivots - 1
p3 = array.get(pivots_low, ind3)
pos3 = array.get(low_ind, ind3)
if p3 < k * pos3 + b
ok := false
// label.new(pos3, p3, 'cross')
break
// check if pivot points in the middle of two points is lower
if ind2 - ind1 >= 1
for ind3 = ind1 + 1 to ind2 - 1
p3 = array.get(pivots_low, ind3)
pos3 = array.get(low_ind, ind3)
if p3 < k * pos3 + b
ok := false
// label.new(pos3, p3, 'cross')
break
for ind = 0 to prd22 - 2
if low[ind] * 1.008 < k * bar_index[ind] + b
ok := false
break
if ok //and not (low < k * bar_index + b) // 'and not' for the last line to check if the it crosses the price action
if array.size(sup_slopes) < max_lines // max_lines // for now only 1 lines is to be shown
line = line.new(pos1, p1, pos2, p2, extend=extend.right)
// label.new(pos1, p1, 'ok to print')
array.push(sup_lines, line)
array.push(sup_slopes, k)
else
max_slope = array.min(sup_slopes)
max_slope_ind = array.indexof(sup_slopes, max_slope)
if max_lines == 1
max_slope_ind := 0
if k > max_slope
line_to_delete = array.get(sup_lines, max_slope_ind)
line.delete(line_to_delete)
new_line = line.new(pos1, p1, pos2, p2, extend=extend.right)
array.insert(sup_lines, max_slope_ind, new_line)
array.insert(sup_slopes, max_slope_ind, k)
array.remove(sup_lines, max_slope_ind + 1)
array.remove(sup_slopes, max_slope_ind + 1)
// label.new(pos1, p1, str.tostring(sup_slopes))
if array.size(sup_lines) >= 1 and barstate.islast
for ind=0 to array.size(sup_lines) - 1
l = array.get(sup_lines, ind)
s = array.get(sup_slopes, ind)
x1 = line.get_x1(l)
x2 = line.get_x2(l)
prev_lable_ind = 0//x2 + prd - 5
for ind1=x2 to bar_index
p = line.get_price(l, ind1)
if (math.abs(p - low[bar_index - ind1]) < p * 0.005)
if ind1 - prev_lable_ind > 10 and ind1 - x2 >= prd22
//label.new(ind1, low[bar_index - ind1], text='A', style=label.style_label_up, color=color.green)
prev_lable_ind := ind1
if not show_lines
len_l = array.size(sup_lines)
if (len_l >= 1)
for ind = 0 to len_l - 1
to_delete = array.pop(sup_lines)
array.pop(sup_slopes)
line.delete(to_delete)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © starbolt
//@version=5
len44 = input.int(27, 'Length', step=1, minval=1)
displace = input.int(0, 'Displace', step=1, minval=0)
ma_type = input.string('HMA', 'MA Type', options=['SMA', 'HMA'])
//Hilo Activator
float hilo = na
hi = ta.sma(high, len44)
lo = ta.sma(low, len44)
// Hull Moving Average (HMA)
if ma_type == 'HMA'
hi := ta.wma(2 * ta.wma(high, len44 / 2) - ta.wma(high, len44), math.round(math.sqrt(len44)))
lo := ta.wma(2 * ta.wma(low, len44 / 2) - ta.wma(low, len44), math.round(math.sqrt(len44)))
hilo := close > hi[displace] ? 1 : close < lo[displace] ? -1 : hilo[1]
ghla = hilo == -1 ? hi[displace] : lo[displace]
color44 = hilo == -1 ? color.rgb(255, 82, 82, 100) : color.rgb(76, 175, 79, 100)
//Alerts
buyCondition = hilo == 1 and hilo[1] == -1
sellCondition = hilo == -1 and hilo[1] == 1
if buyCondition
alert('Long', alert.freq_once_per_bar)
if sellCondition
alert('Short', alert.freq_once_per_bar)
//Plots
plot(ghla, "TR--@R", color=color44, style=plot.style_circles, linewidth = 3)
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carefulCode53358
//@version=5
start1 = input.float(title='Start', defval=0.1, step=0.1)
increment1 = input.float(title='Increment', defval=0.1, step=0.1)
maximum1 = input.float(title='Max Value', defval=1, step=0.1)
putlabel1 = input(title='Put Labels', defval=false)
colup1 = input.color(title='Colors', defval=color.rgb(0, 230, 119, 100), inline='col')
coldn1 = input.color(title='', defval=color.rgb(255, 82, 82, 100), inline='col')
int trend1 = 0
float sar1 = 0.0
float ep1 = 0.0
float af1 = 0.0
trend1 := nz(trend1[1])
ep1 := nz(ep1[1])
af1 := nz(af1[1])
sar1 := sar1[1]
if trend1 == 0 and not na(high[1])
trend1 := high >= high[1] or low >= low[1] ? 1 : -1
sar1 := trend1 > 0 ? low[1] : high[1]
ep1 := trend1 > 0 ? high[1] : low[1]
af1 := start1
af1
else
nextsar1 = sar1
if trend1 > 0
if high[1] > ep1
ep1 := high[1]
af1 := math.min(maximum1, af1 + increment1)
af1
nextsar1 := sar1 + af1 * (ep1 - sar1)
nextsar1 := math.min(math.min(low[1], low[2]), nextsar1)
//Reversal
if nextsar1 > low
trend1 := -1
nextsar1 := ep1
ep1 := low
af1 := start1
af1
else
if low[1] < ep1
ep1 := low[1]
af1 := math.min(maximum1, af1 + increment1)
af1
nextsar1 := sar1 + af1 * (ep1 - sar1)
nextsar1 := math.max(math.max(high[1], high[2]), nextsar1)
//Reversal
if nextsar1 < high
trend1 := 1
nextsar1 := ep1
ep1 := high
af1 := start1
af1
sar1 := nextsar1
sar1
plot(sar1, title='İV--@Ü', color=trend1 > 0 ? colup1 : coldn1, linewidth=1, style=plot.style_line)
alertcondition(ta.change(trend1) > 0, title='PSAR Trend UP', message='PSAR Trend UP')
alertcondition(ta.change(trend1) < 0, title='PSAR Trend DOWN', message='PSAR Trend DOWN')
if ta.change(trend1) > 0 and putlabel1
label.new(bar_index, sar1, text=str.tostring(math.round_to_mintick(sar1)), color=colup1, style=label.style_label_up, size=size.small)
if ta.change(trend1) < 0 and putlabel1
label.new(bar_index, sar1, text=str.tostring(math.round_to_mintick(sar1)), color=coldn1, style=label.style_label_down, size=size.small)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
start12 = input.float(title='Start', defval=0, step=0.1)
increment12 = input.float(title='Increment', defval=0.1, step=0.1)
maximum12 = input.float(title='Max Value', defval=1, step=0.1)
putlabel12 = input(title='Put Labels', defval=false)
colup12 = input.color(title='Colors', defval=color.rgb(0, 230, 119, 100), inline='col')
coldn12 = input.color(title='', defval=color.rgb(255, 82, 82, 100), inline='col')
int trend12 = 0
float sar12 = 0.0
float ep12 = 0.0
float af12 = 0.0
trend12 := nz(trend12[1])
ep12 := nz(ep12[1])
af12 := nz(af12[1])
sar12 := sar12[1]
if trend12 == 0 and not na(high[1])
trend1 := high >= high[1] or low >= low[1] ? 1 : -1
sar12 := trend12 > 0 ? low[1] : high[1]
ep12 := trend12 > 0 ? high[1] : low[1]
af12 := start12
af12
else
nextsar12 = sar12
if trend12 > 0
if high[1] > ep12
ep12 := high[1]
af12 := math.min(maximum12, af12 + increment12)
af12
nextsar12 := sar12 + af12 * (ep12 - sar12)
nextsar12 := math.min(math.min(low[1], low[2]), nextsar12)
//Reversal
if nextsar12 > low
trend12 := -1
nextsar12 := ep12
ep12 := low
af12 := start12
af12
else
if low[1] < ep12
ep12 := low[1]
af12 := math.min(maximum12, af12 + increment12)
af12
nextsar12 := sar12 + af12 * (ep12 - sar12)
nextsar12 := math.max(math.max(high[1], high[2]), nextsar12)
//Reversal
if nextsar12 < high
trend12 := 1
nextsar12 := ep12
ep12 := high
af12 := start12
af12
sar12 := nextsar12
sar12
plot(sar12, title='KV--@K', color=trend12 > 0 ? colup12 : coldn12, linewidth=1, style=plot.style_line)
alertcondition(ta.change(trend12) > 0, title='PSAR Trend UP', message='PSAR Trend UP')
alertcondition(ta.change(trend12) < 0, title='PSAR Trend DOWN', message='PSAR Trend DOWN')
if ta.change(trend12) > 0 and putlabel12
label.new(bar_index, sar12, text=str.tostring(math.round_to_mintick(sar12)), color=colup12, style=label.style_label_up, size=size.small)
if ta.change(trend12) < 0 and putlabel12
label.new(bar_index, sar12, text=str.tostring(math.round_to_mintick(sar12)), color=coldn12, style=label.style_label_down, size=size.small)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
start123 = input.float(title='Start', defval=0, step=0.1)
increment123 = input.float(title='Increment', defval=0.1, step=0.1)
maximum123 = input.float(title='Max Value', defval=0.1, step=0.1)
putlabel123 = input(title='Put Labels', defval=false)
colup123 = input.color(title='Colors', defval=color.rgb(0, 230, 119, 100), inline='col')
coldn123 = input.color(title='', defval=color.rgb(255, 82, 82, 100), inline='col')
int trend123 = 0
float sar123 = 0.0
float ep123 = 0.0
float af123 = 0.0
trend123 := nz(trend123[1])
ep123 := nz(ep123[1])
af123 := nz(af123[1])
sar123 := sar123[1]
if trend123 == 0 and not na(high[1])
trend123 := high >= high[1] or low >= low[1] ? 1 : -1
sar123 := trend123 > 0 ? low[1] : high[1]
ep123 := trend123 > 0 ? high[1] : low[1]
af123 := start123
af123
else
nextsar123 = sar123
if trend123 > 0
if high[1] > ep123
ep123 := high[1]
af123 := math.min(maximum123, af123 + increment123)
af123
nextsar123 := sar123 + af123 * (ep123 - sar123)
nextsar123 := math.min(math.min(low[1], low[2]), nextsar123)
//Reversal
if nextsar123 > low
trend123 := -1
nextsar123 := ep123
ep123 := low
af123 := start123
af123
else
if low[1] < ep123
ep123 := low[1]
af123 := math.min(maximum123, af123 + increment123)
af123
nextsar123 := sar123 + af123 * (ep123 - sar123)
nextsar123 := math.max(math.max(high[1], high[2]), nextsar123)
//Reversal
if nextsar123 < high
trend123 := 1
nextsar123 := ep123
ep123 := high
af123 := start123
af123
sar123 := nextsar123
sar123
plot(sar123, title='OV--@Ö', color=trend123 > 0 ? colup123 : coldn123, linewidth=1, style=plot.style_line)
alertcondition(ta.change(trend123) > 0, title='PSAR Trend UP', message='PSAR Trend UP')
alertcondition(ta.change(trend123) < 0, title='PSAR Trend DOWN', message='PSAR Trend DOWN')
if ta.change(trend123) > 0 and putlabel123
label.new(bar_index, sar123, text=str.tostring(math.round_to_mintick(sar123)), color=colup123, style=label.style_label_up, size=size.small)
if ta.change(trend123) < 0 and putlabel123
label.new(bar_index, sar123, text=str.tostring(math.round_to_mintick(sar123)), color=coldn123, style=label.style_label_down, size=size.small)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
start1234 = input.float(title='Start', defval=0, step=0.1)
increment1234 = input.float(title='Increment', defval=0.01, step=0.1)
maximum1234 = input.float(title='Max Value', defval=0.1, step=0.1)
putlabel1234 = input(title='Put Labels', defval=false)
colup1234 = input.color(title='Colors', defval=color.rgb(0, 230, 119, 100), inline='col')
coldn1234 = input.color(title='', defval=color.rgb(255, 82, 82, 100), inline='col')
int trend1234 = 0
float sar1234 = 0.0
float ep1234 = 0.0
float af1234 = 0.0
trend1234 := nz(trend1234[1])
ep1234 := nz(ep1234[1])
af1234 := nz(af1234[1])
sar1234 := sar1234[1]
if trend1234 == 0 and not na(high[1])
trend1234 := high >= high[1] or low >= low[1] ? 1 : -1
sar1234 := trend1234 > 0 ? low[1] : high[1]
ep1234 := trend1234 > 0 ? high[1] : low[1]
af1234 := start1234
af1234
else
nextsar1234 = sar1234
if trend1234 > 0
if high[1] > ep1234
ep1234 := high[1]
af1234 := math.min(maximum1234, af1234 + increment1234)
af1234
nextsar1234 := sar1234 + af1234 * (ep1234 - sar1234)
nextsar1234 := math.min(math.min(low[1], low[2]), nextsar1234)
//Reversal
if nextsar1234 > low
trend1234 := -1
nextsar1234 := ep1234
ep1234 := low
af1234 := start1234
af1234
else
if low[1] < ep1234
ep1234 := low[1]
af1234 := math.min(maximum1234, af1234 + increment1234)
af1234
nextsar1234 := sar1234 + af1234 * (ep1234 - sar1234)
nextsar1234 := math.max(math.max(high[1], high[2]), nextsar1234)
//Reversal
if nextsar1234 < high
trend1234 := 1
nextsar1234 := ep1234
ep1234 := high
af1234 := start1234
af1234
sar1234 := nextsar1234
sar1234
plot(sar1234, title='UV--@Y', color=trend1234 > 0 ? colup1234 : coldn1234, linewidth=1, style=plot.style_line)
alertcondition(ta.change(trend1234) > 0, title='PSAR Trend UP', message='PSAR Trend UP')
alertcondition(ta.change(trend1234) < 0, title='PSAR Trend DOWN', message='PSAR Trend DOWN')
if ta.change(trend1234) > 0 and putlabel1234
label.new(bar_index, sar1234, text=str.tostring(math.round_to_mintick(sar1234)), color=colup1234, style=label.style_label_up, size=size.small)
if ta.change(trend1234) < 0 and putlabel1234
label.new(bar_index, sar123, text=str.tostring(math.round_to_mintick(sar1234)), color=coldn1234, style=label.style_label_down, size=size.small)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//@version=5
start22 = input.float(title='Start', defval=0.05, step=0.1)
increment = input.float(title='Increment', defval=0.075, step=0.1)
maximum = input.float(title='Max Value', defval=0.35, step=0.1)
putlabel = input(title='Put Labels', defval=false)
colup = input.color(title='Colors', defval=color.rgb(223, 64, 251, 100), inline='col')
coldn = input.color(title='', defval=color.rgb(223, 64, 251, 100), inline='col')
int trend = 0
float sar = 0.0
float ep = 0.0
float af = 0.0
trend := nz(trend[1])
ep := nz(ep[1])
af := nz(af[1])
sar := sar[1]
if trend == 0 and not na(high[1])
trend := high >= high[1] or low >= low[1] ? 1 : -1
sar := trend > 0 ? low[1] : high[1]
ep := trend > 0 ? high[1] : low[1]
af := start22
af
else
nextsar = sar
if trend > 0
if high[1] > ep
ep := high[1]
af := math.min(maximum, af + increment)
af
nextsar := sar + af * (ep - sar)
nextsar := math.min(math.min(low[1], low[2]), nextsar)
//Reversal
if nextsar > low
trend := -1
nextsar := ep
ep := low
af := start22
af
else
if low[1] < ep
ep := low[1]
af := math.min(maximum, af + increment)
af
nextsar := sar + af * (ep - sar)
nextsar := math.max(math.max(high[1], high[2]), nextsar)
//Reversal
if nextsar < high
trend := 1
nextsar := ep
ep := high
af := start22
af
sar := nextsar
sar
plot(sar, title='Yörük', color=trend > 0 ? colup : coldn, linewidth=1, style=plot.style_line)
alertcondition(ta.change(trend) > 0, title='PSAR Trend UP', message='PSAR Trend UP')
alertcondition(ta.change(trend) < 0, title='PSAR Trend DOWN', message='PSAR Trend DOWN')
if ta.change(trend) > 0 and putlabel
label.new(bar_index, sar, text=str.tostring(math.round_to_mintick(sar)), color=colup, style=label.style_label_up, size=size.small)
if ta.change(trend) < 0 and putlabel
label.new(bar_index, sar, text=str.tostring(math.round_to_mintick(sar)), color=coldn, style=label.style_label_down, size=size.small)
////////////////////////////////////////////////////////
// input
start = 20
lookback = input(1, "Sensitivity", tooltip="Low (High Sensitivity), High (Low Sensitivity).\n\nAdjust according to timeframe and asset.")
resp = 1
smoothing = input(3, "Smoothing")
source = input(close, "Source")
// global
var ix = -1
var mal = array.new_int(0)
// functions
avg(source, len) =>
sum = 0.0
for i = 0 to len-1
sum += source[i]
sum/len
bull = close > open
wick_touch(x) =>
bull ? ((close <= x and x <= high) or (low <= x and x <= open)) : ((open <= x and x <= high) or (low <= x and x <= close))
body_touch(x) =>
bull ? (open < x and x < close) : (close < x and x < open)
touches(t) =>
touches = 0
for i = 0 to lookback-1
touches += t[i] ? 1 : 0
touches
// local
ix := ix+1
prev_mal = ix >= 1 ? array.get(mal, ix-1) : start
cma = avg(source, prev_mal)
cma_p1 = avg(source, prev_mal+1)
cma_m1 = avg(source, prev_mal-1)
d = touches(wick_touch(cma))
d_p1 = touches(wick_touch(cma_p1))
d_m1 = touches(wick_touch(cma_m1))
d_b = touches(body_touch(cma))
d_p1_b = touches(body_touch(cma_p1))
d_m1_b = touches(body_touch(cma_m1))
any_body_touch = d_b > 0 or d_p1_b > 0 or d_m1_b > 0
no_wick_touch = d <= 0 and d_p1 <= 0 and d_m1 <= 0
wick_maximized = d >= d_p1 and d >= d_m1 ? prev_mal : (d_p1 >= d and d_p1 >= d_m1 ? prev_mal+resp : (d_m1 >= d and d_m1 >= d_p1 ? prev_mal-resp : na))
uptrend = cma > cma[1]
downtrend = cma < cma[1]
against_trend = (uptrend and close < cma) or (downtrend and close > cma)
new_mal = no_wick_touch or against_trend ? prev_mal-resp : (any_body_touch ? prev_mal+resp : wick_maximized)
next_mal = na(new_mal) ? prev_mal : new_mal
array.push(mal, next_mal < 2 ? 2 : (next_mal > 200 ? 200 : next_mal))
// graph
scma = ta.ema(cma, smoothing)
plot(scma, "--Stop--", style=plot.style_line, color=#ffeb3b00)
////////////////////////////////////////
length7=(1)
src7=close
start17 = input(0.1)
increment17 = input(0.1)
maximum17 = input(1, "Max Value")
out17 = ta.sar(start17, increment17, maximum17)
momo1 = src7 - src7[length7]
smdo1 = out17 - momo1
plot(smdo1, "---DD---", style=plot.style_line, color=color.rgb(255, 255, 255, 100))
//////////////////////////////////////////////////////////////////////////////////////////////////////////
changebarcol = input.bool(true, title='Change Bar Color', inline='bcol')
bcolup = input.color(color.lime, title='', inline='bcol')
bcoldn = input.color(color.red, title='', inline='bcol')
var color lastBarColor = na
// BACAP 21 EMA TREND
//Linesize = input.int(3, title='Line Size', minval=1)
BullishColor = input.color(color.lime)
BearishColor = input.color(color.red)
// Determine the color based on 21 DEMA Trend
barColorBasedOnDEMATrend = close > sar1 and close > sar12 and close > sar and close > ghla ? BullishColor : close < sar1 and close < sar12 and close < sar and close < ghla ? BearishColor : nz(lastBarColor[1])
// Change bar color
lastBarColor := barColorBasedOnDEMATrend
barcolor(color=changebarcol ? barColorBasedOnDEMATrend : na)
x = ta.crossover(close,sar) and ta.crossover(close,sar1) and ta.crossover(close,sar12) and ta.crossover(close,ghla) and ta.crossover(close,scma) and ta.crossover(close,smdo1)
y = ta.crossunder(close,sar) and ta.crossunder(close,sar1) and ta.crossunder(close,sar12) and ta.crossunder(close,ghla) and ta.crossunder(close,scma) and ta.crossunder(close,smdo1)
in_b = ta.barssince(x)[1] < ta.barssince(y)[1]
in_s = ta.barssince(y)[1] < ta.barssince(x)[1]
if x
strategy.entry("Long",strategy.long)
if y
strategy.close("Long")
////////////////////////////////////////////////////////////////////////////////////
// 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/
// © Zeiierman
//@version=5
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
//~~ Tooltips {
string t1 = "The candle lookback length refers to the number of bars, starting from the current one, that will be examined in order to find a similar event in the past."
string t2 = "The amount of Forecast candles that should be displayed in the future."
string t3 = "Background color divider between price and forecast."
string t4 = "Displays the current events found"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
//~~ Inputs {
Series = input.int(1,"Candle Series",1,20,tooltip=t1)
Forecast = input.int(166,"Forecast Candles",1,166,tooltip=t2)
Divider = input.bool(true,"Forecast Divider",t3)
Display = input.bool(true,"Display Event",t4)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
//~~ Types {
type Event
box currentEvent
box pastEvent
box prediction
array<box> candle
array<line> wick
type Data
array<int> b
array<int> d
array<float> o
array<float> h
array<float> l
array<float> c
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
//~~ Variables & Arrays {
b = bar_index
var data = Data.new(array.new<int>(),
array.new<int>(),
array.new<float>(),
array.new<float>(),
array.new<float>(),
array.new<float>())
var event = Event.new(box.new(na,na,na,na,chart.fg_color,border_style=line.style_dashed,bgcolor=color(na)),
box.new(na,na,na,na,chart.fg_color,border_style=line.style_dashed,bgcolor=color(na)),
box.new(na,na,na,na,chart.fg_color,border_style=line.style_dotted,
bgcolor=color.new(color.teal,75)),
array.new<box>(Forecast),
array.new<line>(Forecast))
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
//~~ Methods {
//Store Data
method Store(Data x)=>
int B = b
int bin = close>open?1:close<open?-1:0
float O = open
float H = high
float L = low
float C = close
x.b.unshift(B)
x.d.unshift(bin)
x.o.unshift(O)
x.h.unshift(H)
x.l.unshift(L)
x.c.unshift(C)
//Candle Plots
method Candle(Event e,x,i)=>
int dist = 1
float prev = x.c.get(i)
float diff = ((close-prev)/prev)+1
for j=i-1 to i-Forecast
idx = j-i+Forecast
if j<0
break
else
pos = x.d.get(j)
top = (pos>0?x.c.get(j):x.o.get(j))*diff
bot = (pos>0?x.o.get(j):x.c.get(j))*diff
hi = (x.h.get(j))*diff
lo = (x.l.get(j))*diff
col = pos==1?#26a69a:pos==-1?#ef5350:chart.fg_color
candle = e.candle.get(idx)
if na(candle)
e.candle.set(idx,box.new(b+dist,top,b+dist+2,bot,na,bgcolor=col))
e.wick.set(idx,line.new(b+dist+1,hi,b+dist+1,lo,color=col))
else
box.set_lefttop(e.candle.get(idx),b+dist,top)
box.set_rightbottom(e.candle.get(idx),b+dist+2,bot)
box.set_bgcolor(e.candle.get(idx),col)
line.set_xy1(e.wick.get(idx),b+dist+1,hi)
line.set_xy2(e.wick.get(idx),b+dist+1,lo)
line.set_color(e.wick.get(idx),col)
dist += 3
//Events Display
method Events(Event e,idx,h1,l1,h2,l2,fh,fl)=>
int start = idx.get(Series-1)
int end = idx.get(0)
e.currentEvent.set_lefttop(b-Series+1,h1.max())
e.currentEvent.set_rightbottom(b,l1.min())
e.pastEvent.set_lefttop(start,h2.max())
e.pastEvent.set_rightbottom(end,l2.min())
e.prediction.set_lefttop(end+1,fh.max())
e.prediction.set_rightbottom(math.min(b,end+Forecast),fl.min())
//Current Event
method Series(Data x)=>
data.Store()
bool found = false
if barstate.islast
events = x.d.slice(0,Series)
for i=Series to x.d.size()-Series
elements = x.d.slice(i,i+Series)
equal = 0
for [k,this] in elements
if this==events.get(k)
equal += 1
if equal==Series
found := true
event.Candle(data,i)
if Display
bar = x.b.slice(i,i+Series)
h1 = x.h.slice(0,Series)
l1 = x.l.slice(0,Series)
h2 = x.h.slice(i,i+Series)
l2 = x.l.slice(i,i+Series)
fh = i-Forecast<0?x.h.slice(0,i-1):x.h.slice(i-Forecast,i-1)
fl = i-Forecast<0?x.l.slice(0,i-1):x.l.slice(i-Forecast,i-1)
event.Events(bar,h1,l1,h2,l2,fh,fl)
break
if barstate.islast and not found
runtime.error("Couldn't find similar candle series event. \nFix: Decrease Candle Series length")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
//~~ Divider {
//bgcolor(Divider and barstate.islast?color.new(chart.fg_color,80):na,1)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
//~~ Run Code {
data.Series()
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
//////////////////////////////////////////////////////////////////////////////////////
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Sainath_Jayaraman
//@version=5
//SAR
SAR = input(true, title='*')
OSAR = input(true, title='Other Time frame SAR')
start88 = input(0.05, title="start", group="Parabolic SAR")
increment88 = input(0.075, title="Increment", group="Parabolic SAR")
maximum88 = input(0.35, title="Maximum", group="Parabolic SAR")
out88 = ta.sar(start88, increment88, maximum88)
sarChange = ta.change(out88<high)
var prevSar = out88
if(sarChange)
prevSar := out88[1] + ((out88[1]/100)*0.002)
plot(SAR and sarChange?na:prevSar, style=plot.style_linebr, offset=-1, color=out88<high?color.green:color.red, title="Kırılım", linewidth=1)
plot(SAR and out88 ? out88 : na, title='Sar-Trend', color=#ff990000, style=plot.style_circles, linewidth=2)
//sar_15
//15min sar
startD_15 = input(0.05, title="start", group="Parabolic SAR")
incrementD_15 = input(0.075, title="Increment", group="Parabolic SAR")
maximumD_15 = input(0.35, title="Maximum", group="Parabolic SAR")
outD_15 = request.security(syminfo.ticker, "1", ta.sar(startD_15, incrementD_15,maximumD_15))
sarChange5 = ta.change(outD_15<high)
var prevSar5 = outD_15
if(sarChange5)
prevSar5 := outD_15[1] + ((outD_15[1]/100)*0.002)
plot(SAR and sarChange5?na:prevSar5, style=plot.style_linebr, offset=-1, color=outD_15<high?color.rgb(78, 238, 243, 100):color.rgb(78, 238, 243, 100), title="Kırılım-1", linewidth=1)
plot(OSAR and outD_15 ? outD_15 : na, title='Sar_1', color=#ff990000, style=plot.style_circles, linewidth=1)
//sar_30
//30min sar
startD_30 = input(0.05, title="start", group="Parabolic SAR")
incrementD_30 = input(0.075, title="Increment", group="Parabolic SAR")
maximumD_30 = input(0.35, title="Maximum", group="Parabolic SAR")
outD_30 = request.security(syminfo.ticker, "5", ta.sar(startD_30, incrementD_30,maximumD_30))
sarChange56 = ta.change(outD_30<high)
var prevSar56 = outD_30
if(sarChange56)
prevSar56 := outD_30[1] + ((outD_30[1]/100)*0.002)
plot(SAR and sarChange56?na:prevSar56, style=plot.style_linebr, offset=-1, color=outD_30<high?color.rgb(78, 238, 243, 100):color.rgb(78, 238, 243, 100), title="Kırılım-5", linewidth=1)
plot(OSAR and outD_30 ? outD_30 : na, title='Sar_5', color=#ff990000, style=plot.style_circles, linewidth=1)
//sar_01
//01Hr sar
startD_60 = input(0.05, title="start", group="Parabolic SAR")
incrementD_60 = input(0.075, title="Increment", group="Parabolic SAR")
maximumD_60 = input(0.35, title="Maximum", group="Parabolic SAR")
outD_60 = request.security(syminfo.ticker, "15", ta.sar(startD_60, incrementD_60,maximumD_60))
sarChange567 = ta.change(outD_60<high)
var prevSar567 = outD_60
if(sarChange567)
prevSar567 := outD_60[1] + ((outD_60[1]/100)*0.002)
plot(SAR and sarChange567?na:prevSar567, style=plot.style_linebr, offset=-1, color=outD_60<high?color.rgb(78, 238, 243, 100):color.rgb(78, 238, 243, 100), title="Kırılım-15", linewidth=1)
plot(OSAR and outD_60 ? outD_60 : na, title='Sar_15', color=#ff990000, style=plot.style_circles, linewidth=1)
//sar_02
//02Hr sar
startD_120 = input(0.05, title="start", group="Parabolic SAR")
incrementD_120 = input(0.075, title="Increment", group="Parabolic SAR")
maximumD_120 = input(0.35, title="Maximum", group="Parabolic SAR")
outD_120 = request.security(syminfo.ticker, "30", ta.sar(startD_120, incrementD_120,maximumD_120))
sarChange5678 = ta.change(outD_120<high)
var prevSar5678 = outD_120
if(sarChange5678)
prevSar5678 := outD_120[1] + ((outD_120[1]/100)*0.002)
plot(SAR and sarChange5678?na:prevSar5678, style=plot.style_linebr, offset=-1, color=outD_120<high?color.rgb(78, 238, 243, 100):color.rgb(78, 238, 243, 100), title="Kırılım-30", linewidth=1)
plot(OSAR and outD_120 ? outD_120 : na, title='Sar_30', color=#ff990000, style=plot.style_circles, linewidth=1)
//sar_03
//03Hr sar
startD_180 = input(0.05, title="start", group="Parabolic SAR")
incrementD_180 = input(0.075, title="Increment", group="Parabolic SAR")
maximumD_180 = input(0.35, title="Maximum", group="Parabolic SAR")
outD_180 = request.security(syminfo.ticker, "60", ta.sar(startD_180, incrementD_180,maximumD_180))
sarChange56789 = ta.change(outD_180<high)
var prevSar56789 = outD_180
if(sarChange56789)
prevSar56789 := outD_180[1] + ((outD_180[1]/100)*0.002)
plot(SAR and sarChange56789?na:prevSar56789, style=plot.style_linebr, offset=-1, color=outD_180<high?color.rgb(78, 238, 243, 100):color.rgb(78, 238, 243, 100), title="Kırılım-60", linewidth=1)
plot(OSAR and outD_180 ? outD_180 : na, title='Sar_60', color=#ff990000, style=plot.style_circles, linewidth=1)
///////////////////////////////////////////////////////////////////////////////
Yer İmleri