-
PHP Code:
//@version=5
indicator(".", overlay = true, max_boxes_count = 500)
//------------------------------------------------------------------------------
////////////////////////////////
start1 = input(0)
increment1 = input(0.1)
maximum1 = input(1, "Max Value")
out1 = ta.sar(start1, increment1, maximum1)
plot(out1, "HSAR", style=plot.style_line, color=#f0ce0e)
/////////////////////////////////
start2 = input(0)
increment2 = input(0.1)
maximum2 = input(0.1, "Max Value")
out2 = ta.sar(start2, increment2, maximum2)
plot(out2, "YSAR", style=plot.style_line, color=#0af1de)
///////////////////////////////////
start21 = input(0)
increment21 = input(0.01)
maximum21 = input(0.1, "Max Value")
out21 = ta.sar(start21, increment21, maximum21)
plot(out21, "SAR", style=plot.style_line, color=#f2f3f7)
/////////////////////////////////
//@version=5
plot = input.bool(false, title="Display past dots")
OverSold = input(0)
OverBought = input(100)
length1 = input.int(2, title = "Length")
tr = input.int(1, title = "Trigger Length")
// Define the function
func(source, int len, int tr) =>
HP = 0.00, a1 = 0.00, b1 = 0.00, c1 = 0.00, c2 = 0.00, c3 = 0.00, ag = 0.00, Sp = 0.00, X = 0.00, Quotient1 = 0.00, Quotient2 = 0.00, w = math.sqrt(.5)
HP := 2500 * (source - 2 * nz(source[1]) + nz(source[2])) + 1.92 * nz(HP[1]) - .9216 * nz(HP[2])
a1 := math.exp(-math.sqrt(2) * math.pi / len)
b1 := 2 * a1 * math.cos(math.sqrt(2) * math.pi / len)
c2 := b1
c3 := -a1 * a1
c1 := 1 - c2 - c3
ag := c1 * (HP + nz(HP[1])) / 2 + c2 * nz(ag[1]) + c3 * nz(ag[2])
Sp := .991 * nz(Sp[1])
if math.abs(ag) > Sp
Sp := math.abs(ag)
Sp
if Sp != 0
X := ag / Sp
X
q1 = X * 60 + 50
out= ta.sma(q1, tr)
[out]
[k] = func(close, length1,tr)
OverboughtCond = k > OverBought
OversoldCond = k < OverSold
plotshape(plot? OverboughtCond:na, style=shape.circle, location=location.abovebar, color=color.new(color.lime, 0), size=size.tiny)
plotshape(plot? OversoldCond:na, style=shape.circle, location=location.belowbar, color=color.new(color.red, 0), size=size.tiny)
var label myLabel_Overbought = na
if OverboughtCond
// Delete the previous label if there is one
if not na(myLabel_Overbought)
label.delete(myLabel_Overbought[1])
// Create a new label
myLabel_Overbought := label.new(bar_index, high, 'Aşırı Alış',yloc=yloc.abovebar,style=label.style_circle, size=size.normal, color=color.red, textcolor=color.white)
myLabel_Overbought
var label myLabel_Oversold = na
if OversoldCond
// Delete the previous label if there is one
if not na(myLabel_Oversold)
label.delete(myLabel_Oversold[1])
// Create a new label
myLabel_Oversold := label.new(bar_index, low, 'Aşırı Satış',yloc=yloc.belowbar,style=label.style_circle, size=size.normal, color=color.lime, textcolor=color.white)
myLabel_Oversold
alertcondition(OverboughtCond, title="Overbought", message="DOTS [CHE]: Overbought\nSymbol: {{ticker}}\nPrice: {{close}}")
alertcondition(OversoldCond, title="Oversold", message="DOTS [CHE]: DOTS\nSymbol: {{ticker}}\nPrice: {{close}}")
//////////////////////////////////////////
üzerinde çalışılacak örnek...
-
PHP Code:
//@version=5
indicator(".", overlay = true, max_boxes_count = 100)
////////////////////////////////
start1 = input(0)
increment1 = input(0.1)
maximum1 = input(1, "Max Value")
out1 = ta.sar(start1, increment1, maximum1)
plot(out1, "KısaDöngü", style=plot.style_line, color=#f0ce0e)
/////////////////////////////////
start2 = input(0)
increment2 = input(0.1)
maximum2 = input(0.1, "Max Value")
out2 = ta.sar(start2, increment2, maximum2)
plot(out2, "OrtaDöngü", style=plot.style_line, color=#06deee)
///////////////////////////////////
start21 = input(0)
increment21 = input(0.01)
maximum21 = input(0.1, "Max Value")
out21 = ta.sar(start21, increment21, maximum21)
plot(out21, "UzunDöngü", style=plot.style_line, color=#f2f3f7)
/////////////////////////////////
start213 = input(0.1)
increment213 = input(0.1)
maximum213 = input(1, "Max Value")
out213 = ta.sar(start213, increment213, maximum213)
plot(out213, "KıyasDöngü", style=plot.style_line, color=#c20bf0)
////////////////////////////////////////
//@version=5
// User inputs
prd22 = input.int(defval=5, 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)
////////////////////////////////////////////////////
üzerinde çalışılacak örnek...
-
pivotla .... otomatik trend çizdirme ..... 3-5-2 değerleriyle....
PHP Code:
//@version=5
indicator(".", overlay = true, max_boxes_count = 100)
////////////////////////////////////////
//@version=5
// User inputs
prd22 = input.int(defval=3, 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=3, 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)
// 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])
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])
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)
////////////////////////////////////////////////////
-
https://tr.tradingview.com/script/LSmk7DkW/
üstel hareketli ortalamaları kullanan bir kod....
yazan için başlangıç sayılır.....
emeğine saygı gösterip.....
eğer burayı okuma şansı olursa....
tavsiye....
grafiğe çok plot çizdirme yerine.... ortalamasını alsın....
yazdığı bu....https://www.tradingview.com/x/8RHhs4RP/
ortalama alınırsa böyle olur...https://www.tradingview.com/x/kAjzYeT2/
PHP Code:
//@version=5
// author Deniz
indicator(title="Hareketli Ortalama FIBO COMBO", overlay=true, shorttitle="ADOCOMBOEMA")
src = input(title="Source", defval=close)
length1 = input(5, "MOV Length1")
length2 = input(8, "MOV Length2")
length3 = input(13, "MOV Length3")
length4 = input(21, "MOV Length4")
length5 = input(34, "MOV Length5")
length6 = input(55, "MOV Length6")
length7 = input(89, "MOV Length7")
length8 = input(144, "MOV Length8")
length9 = input(17, "HAHO lenght")
xyz=(length1+length2+length3+length4+length5+length6+length7+length8+length9 )/9
plot(ta.sma(src, xyz),color=color.rgb(255, 253, 255),linewidth=2,title="Ort")
-
https://tr.tradingview.com/v/azpwq2BQ/
kodu yazan kişi.... bence uzunluğa dikkat etmeli.....
normal görüntü bu.....https://www.tradingview.com/x/dBhQSvDr/
uzunluğu 20 olsa.....
trend kırılımlarını daha rahat görür.....
https://www.tradingview.com/x/YCCjVNXh/
hatta bunu 20-50 kesişimden sinya ürettirmesi daha mantıklı.....
kodun 20 uzunlukta....
v5 versiyon halini de ben eklemiş olayım.....
kullanmak isteyenlere....
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Millionaiiire
//@version=5
indicator('ابو فليحه', overlay=true, max_bars_back=1000, max_lines_count=300)
src = input(defval=close, title='لا تلعب بيها')
len = input.int(defval=20, title='الشمعات', minval=10)
devlen = input.float(defval=2., title='الانحراف', minval=0.1, step=0.1)
extendit = input(defval=true, title='خط انفنتي')
showfibo = input(defval=false, title='مستويات فيبو')
showbroken = input.bool(defval=true, title='القنوات المكسورة', inline='brk')
brokencol = input.color(defval=color.rgb(207, 4, 248), title='', inline='brk')
upcol = input.color(defval=color.lime, title='لون الترندات الصاعده والنازله', inline='trcols')
dncol = input.color(defval=color.red, title='', inline='trcols')
widt = input(defval=1, title='عرض الخط')
var fibo_ratios = array.new_float(0)
var colors = array.new_color(2)
if barstate.isfirst
array.unshift(colors, upcol)
array.unshift(colors, dncol)
array.push(fibo_ratios, 0.236)
array.push(fibo_ratios, 0.382)
array.push(fibo_ratios, 0.618)
array.push(fibo_ratios, 0.786)
get_channel(src, len) =>
mid = math.sum(src, len) / len
slope = ta.linreg(src, len, 0) - ta.linreg(src, len, 1)
intercept = mid - slope * math.floor(len / 2) + (1 - len % 2) / 2 * slope
endy = intercept + slope * (len - 1)
dev = 0.0
for x = 0 to len - 1 by 1
dev += math.pow(src[x] - (slope * (len - x) + intercept), 2)
dev
dev := math.sqrt(dev / len)
[intercept, endy, dev, slope]
[y1_, y2_, dev, slope] = get_channel(src, len)
outofchannel = slope > 0 and close < y2_ - dev * devlen ? 0 : slope < 0 and close > y2_ + dev * devlen ? 2 : -1
var reglines = array.new_line(3)
var fibolines = array.new_line(4)
for x = 0 to 2 by 1
if not showbroken or outofchannel != x or nz(outofchannel[1], -1) != -1
line.delete(array.get(reglines, x))
else
line.set_color(array.get(reglines, x), color=brokencol)
line.set_width(array.get(reglines, x), width=2)
line.set_style(array.get(reglines, x), style=line.style_dotted)
line.set_extend(array.get(reglines, x), extend=extend.none)
array.set(reglines, x, line.new(x1=bar_index - (len - 1), y1=y1_ + dev * devlen * (x - 1), x2=bar_index, y2=y2_ + dev * devlen * (x - 1), color=array.get(colors, math.round(math.max(math.sign(slope), 0))), style=x % 2 == 1 ? line.style_solid : line.style_dashed, width=widt, extend=extendit ? extend.right : extend.none))
if showfibo
for x = 0 to 3 by 1
line.delete(array.get(fibolines, x))
array.set(fibolines, x, line.new(x1=bar_index - (len - 1), y1=y1_ - dev * devlen + dev * devlen * 2 * array.get(fibo_ratios, x), x2=bar_index, y2=y2_ - dev * devlen + dev * devlen * 2 * array.get(fibo_ratios, x), color=array.get(colors, math.round(math.max(math.sign(slope), 0))), style=line.style_dotted, width=widt, extend=extendit ? extend.right : extend.none))
var label sidelab = label.new(x=bar_index - (len - 1), y=y1_, text='S', size=size.large)
txt = slope > 0 ? slope > slope[1] ? '⇑' : '⇗' : slope < 0 ? slope < slope[1] ? '⇓' : '⇘' : '⇒'
stl = slope > 0 ? slope > slope[1] ? label.style_label_up : label.style_label_upper_right : slope < 0 ? slope < slope[1] ? label.style_label_down : label.style_label_lower_right : label.style_label_right
label.set_style(sidelab, stl)
label.set_text(sidelab, txt)
label.set_x(sidelab, bar_index - (len - 1))
label.set_y(sidelab, slope > 0 ? y1_ - dev * devlen : slope < 0 ? y1_ + dev * devlen : y1_)
label.set_color(sidelab, slope > 0 ? upcol : slope < 0 ? dncol : color.blue)
alertcondition(outofchannel, title='انكسرت القناة', message='انكسرت القناة')
// direction
trendisup = math.sign(slope) != math.sign(slope[1]) and slope > 0
trendisdown = math.sign(slope) != math.sign(slope[1]) and slope < 0
alertcondition(trendisup, title='ترند صاعد', message='ترند صاعد')
alertcondition(trendisdown, title='ترند هابط', message='ترند هابط')
-
https://tr.tradingview.com/v/vOLgkYa8/
uzunluğu 20 yapsak... forecast ....sonrası için kanal belirleme....
-
https://tr.tradingview.com/v/fSkHm23m/
güzel bir strateji trend kodu....
neden derseniz...hesaplamada...fama ve mama kullanmış.... ortalamaların anası yani...
https://www.tradingview.com/x/vrNpmQL8/
plotlar kapatılıp...sade bar renkli kullanılmalı diğer birleşmeler buna uygulanabilir.....
https://www.tradingview.com/x/AjQUsLeg/
kullanmak isteyenler kodun versiyon 5 hali.....
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © wielkieef
//@version=5
src = close
strategy('Get your trend', overlay=true, pyramiding=1, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_order_fills=false, slippage=0, commission_type=strategy.commission.percent, commission_value=0.04)
//Inputs -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Length1 = input.int(5, title=' 1-SMA Lenght', minval=1)
Length2 = input.int(15, title=' 2-SMA Lenght', minval=1)
Length3 = input.int(25, title=' 3-SMA Lenght', minval=1)
prd = input.int(15, title=' PP period', group='Average True Range')
Factor = input.int(1, title=' ATR Factor', group='Average True Range')
Pd = input.int(1, title=' ATR Period', group='Average True Range')
ADX_options = input.string('CLASSIC', title=' Adx Type', options=['CLASSIC', 'MASANAKAMURA'], group='ADX')
ADX_len = input.int(20, title=' Adx lenght', minval=1, group='ADX')
th = input.float(15, title=' Adx Treshold', minval=0, step=0.5, group='ADX')
len = input.int(30, title=' Cloud Length', group='Cloud')
volume_f = input.float(1.8, title=' Volume mult.', minval=0, step=0.1, group='Volume')
sma_length = input.int(30, title=' Volume lenght', minval=1, group='Volume')
//Indicators -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
calcADX(_len) =>
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : up > down and up > 0 ? up : 0
minusDM = na(down) ? na : down > up and down > 0 ? down : 0
truerange = ta.rma(ta.tr, _len)
_plus = fixnan(100 * ta.rma(plusDM, _len) / truerange)
_minus = fixnan(100 * ta.rma(minusDM, _len) / truerange)
sum = _plus + _minus
_adx = 100 * ta.rma(math.abs(_plus - _minus) / (sum == 0 ? 1 : sum), _len)
[_plus, _minus, _adx]
calcADX_Masanakamura(_len) =>
SmoothedTrueRange = 0.0
SmoothedDirectionalMovementPlus = 0.0
SmoothedDirectionalMovementMinus = 0.0
TrueRange = math.max(math.max(high - low, math.abs(high - nz(close[1]))), math.abs(low - nz(close[1])))
DirectionalMovementPlus = high - nz(high[1]) > nz(low[1]) - low ? math.max(high - nz(high[1]), 0) : 0
DirectionalMovementMinus = nz(low[1]) - low > high - nz(high[1]) ? math.max(nz(low[1]) - low, 0) : 0
SmoothedTrueRange := nz(SmoothedTrueRange[1]) - nz(SmoothedTrueRange[1]) / _len + TrueRange
SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - nz(SmoothedDirectionalMovementPlus[1]) / _len + DirectionalMovementPlus
SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - nz(SmoothedDirectionalMovementMinus[1]) / _len + DirectionalMovementMinus
DIP = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIM = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = math.abs(DIP - DIM) / (DIP + DIM) * 100
adx = ta.sma(DX, _len)
[DIP, DIM, adx]
[DIPlusC, DIMinusC, ADXC] = calcADX(ADX_len)
[DIPlusM, DIMinusM, ADXM] = calcADX_Masanakamura(ADX_len)
DIPlus = ADX_options == 'CLASSIC' ? DIPlusC : DIPlusM
DIMinus = ADX_options == 'CLASSIC' ? DIMinusC : DIMinusM
ADX = ADX_options == 'CLASSIC' ? ADXC : ADXM
L_adx = DIPlus > DIMinus and ADX > th
S_adx = DIPlus < DIMinus and ADX > th
float ph = ta.pivothigh(prd, prd)
float pl = ta.pivotlow(prd, prd)
var float center = na
float lastpp = ph ? ph : pl ? pl : na
if lastpp
if na(center)
center := lastpp
center
else
center := (center * 2 + lastpp) / 3
center
Up = center - Factor * ta.atr(Pd)
Dn = center + Factor * ta.atr(Pd)
float TUp = na
float TDown = na
Trend = 0
TUp := close[1] > TUp[1] ? math.max(Up, TUp[1]) : Up
TDown := close[1] < TDown[1] ? math.min(Dn, TDown[1]) : Dn
Trend := close > TDown[1] ? 1 : close < TUp[1] ? -1 : nz(Trend[1], 1)
Trailingsl = Trend == 1 ? TUp : TDown
bsignal = Trend == 1 and Trend[1] == -1
ssignal = Trend == -1 and Trend[1] == 1
L_ATR = Trend == 1
S_ATR = Trend == -1
SMA1 = ta.sma(src, Length1)
SMA2 = ta.sma(src, Length2)
SMA3 = ta.sma(src, Length3)
Volume_condt = volume > ta.sma(volume, sma_length) * volume_f
Long_MA = SMA1 < close and SMA2 < close and SMA3 < close
Short_MA = SMA1 > close and SMA2 > close and SMA3 > close
PI = 2 * math.asin(1)
hilbertTransform(src) =>
0.0962 * src + 0.5769 * nz(src[2]) - 0.5769 * nz(src[4]) - 0.0962 * nz(src[6])
computeComponent(src, mesaPeriodMult) =>
hilbertTransform(src) * mesaPeriodMult
computeAlpha(src, fastLimit, slowLimit) =>
mesaPeriod = 0.0
mesaPeriodMult = 0.075 * nz(mesaPeriod[1]) + 0.54
smooth = 0.0
smooth := (4 * src + 3 * nz(src[1]) + 2 * nz(src[2]) + nz(src[3])) / 10
detrender = 0.0
detrender := computeComponent(smooth, mesaPeriodMult)
I1 = nz(detrender[3])
Q1 = computeComponent(detrender, mesaPeriodMult)
jI = computeComponent(I1, mesaPeriodMult)
jQ = computeComponent(Q1, mesaPeriodMult)
I2 = 0.0
Q2 = 0.0
I2 := I1 - jQ
Q2 := Q1 + jI
I2 := 0.2 * I2 + 0.8 * nz(I2[1])
Q2 := 0.2 * Q2 + 0.8 * nz(Q2[1])
Re = I2 * nz(I2[1]) + Q2 * nz(Q2[1])
Im = I2 * nz(Q2[1]) - Q2 * nz(I2[1])
Re := 0.2 * Re + 0.8 * nz(Re[1])
Im := 0.2 * Im + 0.8 * nz(Im[1])
if Re != 0 and Im != 0
mesaPeriod := 2 * PI / math.atan(Im / Re)
mesaPeriod
if mesaPeriod > 1.5 * nz(mesaPeriod[1])
mesaPeriod := 1.5 * nz(mesaPeriod[1])
mesaPeriod
if mesaPeriod < 0.67 * nz(mesaPeriod[1])
mesaPeriod := 0.67 * nz(mesaPeriod[1])
mesaPeriod
if mesaPeriod < 6
mesaPeriod := 6
mesaPeriod
if mesaPeriod > 50
mesaPeriod := 50
mesaPeriod
mesaPeriod := 0.2 * mesaPeriod + 0.8 * nz(mesaPeriod[1])
phase = 0.0
if I1 != 0
phase := 180 / PI * math.atan(Q1 / I1)
phase
deltaPhase = nz(phase[1]) - phase
if deltaPhase < 1
deltaPhase := 1
deltaPhase
alpha = fastLimit / deltaPhase
if alpha < slowLimit
alpha := slowLimit
alpha
[alpha, alpha / 2.0]
er = math.abs(ta.change(src, len)) / math.sum(math.abs(ta.change(src)), len)
[a, b] = computeAlpha(src, er, er * 0.1)
mama = 0.0
mama := a * src + (1 - a) * nz(mama[1])
fama = 0.0
fama := b * mama + (1 - b) * nz(fama[1])
alpha = math.pow(er * (b - a) + a, 2)
kama = 0.0
kama := alpha * src + (1 - alpha) * nz(kama[1])
L_cloud = kama > kama[1]
S_cloud = kama < kama[1]
// STRATEGY LOGIC -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var bool longCond = na
var bool shortCond = na
longCond := nz(longCond[1])
shortCond := nz(shortCond[1])
var int CondIni_long = 0
var int CondIni_short = 0
CondIni_long := nz(CondIni_long[1])
CondIni_short := nz(CondIni_short[1])
var bool Final_longCondition = na
var bool Final_shortCondition = na
Final_longCondition := nz(Final_longCondition[1])
Final_shortCondition := nz(Final_shortCondition[1])
var bool BT_Final_longCondition = na
var bool BT_Final_shortCondition = na
BT_Final_longCondition := nz(BT_Final_longCondition[1])
BT_Final_shortCondition := nz(BT_Final_shortCondition[1])
var float last_open_longCondition = na
var float last_open_shortCondition = na
var int last_longCondition = na
var int last_shortCondition = na
var int nLongs = na
var int nShorts = na
nLongs := nz(nLongs[1])
nShorts := nz(nShorts[1])
Bulls_on_the_control = Long_MA and Volume_condt and L_adx and not S_cloud
close_condt = S_cloud and S_ATR
longCond := Bulls_on_the_control
shortCond := close_condt
CondIni_long := longCond[1] ? 1 : shortCond[1] ? -1 : nz(CondIni_long[1])
CondIni_short := longCond[1] ? 1 : shortCond[1] ? -1 : nz(CondIni_short[1])
longCondition = longCond[1] and nz(CondIni_long[1]) == -1
shortCondition = shortCond[1] and nz(CondIni_short[1]) == 1
var int last_long_sl = na
var int last_short_sl = na
last_open_longCondition := longCondition ? close[1] : nz(last_open_longCondition[1])
last_open_shortCondition := shortCondition ? close[1] : nz(last_open_shortCondition[1])
last_longCondition := longCondition ? time : nz(last_longCondition[1])
last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])
in_longCondition = last_longCondition > last_shortCondition
in_shortCondition = last_shortCondition > last_longCondition
if longCondition
nLongs += 1
nShorts := na
nShorts
if shortCondition
nLongs := na
nShorts += 1
nShorts
var int sectionLongs = 0
sectionLongs := nz(sectionLongs[1])
var int sectionShorts = 0
sectionShorts := nz(sectionShorts[1])
if longCondition
sectionLongs += 1
sectionShorts := 0
sectionShorts
if shortCondition
sectionLongs := 0
sectionShorts += 1
sectionShorts
var float PositionPrice = 0.0
PositionPrice := nz(PositionPrice[1])
var float sum_long = 0.0
var float sum_short = 0.0
if longCondition
sum_long := nz(last_open_longCondition) + nz(sum_long[1])
sum_short := 0.0
sum_short
if shortCondition
sum_short := nz(last_open_shortCondition) + nz(sum_short[1])
sum_long := 0.0
sum_long
PositionPrice := longCondition ? sum_long / sectionLongs : shortCondition ? sum_short / sectionShorts : na
// Colors ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ADX_COLOR = L_adx ? color.lime : S_adx ? color.red : color.orange
barcolor(color=ADX_COLOR)
//PLOTSPAHES =======================================================================================================================================================================================================================================================================================================
mama_p = plot(mama, title='Cloud A', color=ADX_COLOR)
fama_p = plot(fama, title='Cloud B', color=ADX_COLOR)
fill(mama_p, fama_p, color=ADX_COLOR, transp=90)
plot(SMA1, color=color.new(color.gray, 0), style=plot.style_stepline, title='5', linewidth=1)
plot(SMA2, color=color.new(color.gray, 0), style=plot.style_stepline, title='15', linewidth=2)
plot(SMA3, color=color.new(color.black, 0), style=plot.style_stepline, title='55', linewidth=3)
plotshape(longCondition, title='Long', style=shape.triangleup, location=location.belowbar, text='Long', textcolor=color.new(color.blue, 0), color=color.new(color.blue, 0), size=size.small)
plotshape(shortCondition, title='Close', style=shape.xcross, location=location.abovebar, text='Close', textcolor=color.new(color.fuchsia, 0), color=color.new(color.fuchsia, 0), size=size.small)
plot(PositionPrice, title='Average Price', color=color.new(color.white, 0), linewidth=7, style=plot.style_circles, editable=false)
if Long_MA and Volume_condt and L_adx and not S_cloud
strategy.entry('L', strategy.long)
strategy.close_all(when=close_condt)
// By wielkieef
-