pair trade takipleri...
https://www.tradingview.com/x/nQNyUm06/
https://www.tradingview.com/x/zQkT7rSD/
https://www.tradingview.com/x/ay09Dbki/
Printable View
yedekleme...düzenlenecek...
önceki parçalı çalışmalardan.....
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © YunusEmre32
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © fondDealer96636
//@version=5
indicator('*', overlay=true, max_bars_back=201)
// 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, "Automatic MA", style=plot.style_line, color=#ffeb3b00)
////////////////////////////////////////
start213 = input(0.1)
increment213 = input(0.1)
maximum213 = input(1, "Max Value")
out213 = ta.sar(start213, increment213, maximum213)
plot(out213, "Döngü", style=plot.style_line, color=#ffeb3b00)
////////////////////////////////////////////////////////////////////
//@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=true)
colup = input.color(title='Colors', defval=color.rgb(0, 230, 119, 100), inline='col')
coldn = input.color(title='', defval=color.rgb(255, 82, 82, 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='@@', 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.huge)
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.huge)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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(10, '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.red : color.green
//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, color=color44, style=plot.style_cross, linewidth = 3)
////////////////////////////////////////////////////////////////////////////
//@version=5
import jdehorty/KernelFunctions/2 as kernel
DFT(x, y, Nx, _dir) =>
float _arg = 0.0
float _cos = 0.0
float _sin = 0.0
float xArr_i = 0.0
float yArr_i = 0.0
xArr = array.new_float(array.size(x))
yArr = array.new_float(array.size(y))
for i = 0 to Nx - 1 by 1
xArr_i := 0.0
yArr_i := 0.0
kx = float(i) / float(Nx)
_arg := -_dir * 2 * math.pi * kx
for k = 0 to Nx - 1 by 1
_cos := math.cos(k * _arg)
_sin := math.sin(k * _arg)
xArr_i += array.get(x, k) * _cos - array.get(y, k) * _sin
yArr_i += array.get(x, k) * _sin + array.get(y, k) * _cos
yArr_i
array.set(xArr, i, xArr_i)
array.set(yArr, i, yArr_i)
if _dir == 1
for i = 0 to Nx - 1 by 1
array.set(x, i, array.get(xArr, i) / float(Nx))
array.set(y, i, array.get(yArr, i) / float(Nx))
else
for i = 0 to Nx - 1 by 1
array.set(x, i, array.get(xArr, i))
array.set(y, i, array.get(yArr, i))
//======================================================================================================================
// INPUTS
//======================================================================================================================
N = input.int(5,"Fourier Period")
xval = input.source(close,"Fourier X Series",tooltip = "i.e. the source of the discrete Fourier"+
" transform (with the Y Series being the bars through time.)")
highlighting = input.bool(true,"Highlighting")
smoothing66 = input.int(10,"Kernel Smoothing")
//======================================================================================================================
// CALCULATIONS
//======================================================================================================================
// Fourier transform
x = array.new_float(N, 0.0)
y = array.new_float(N, 0.0)
for i = 0 to N - 1
array.set(x, i, xval[i])
array.set(y, i, 0.0)
DFT(x, y, N, 1)
mag = array.new_float(N, 0.0)
for i = 0 to N - 1
mag_i = math.sqrt(math.pow(array.get(x, i), 2) + math.pow(array.get(y, i), 2))
array.set(mag, i, mag_i)
dft = array.get(mag,0)
dfts = kernel.rationalQuadratic(dft,25,1,smoothing66)
//======================================================================================================================
// DISPLAY
//======================================================================================================================
plot(dfts, "Stop", color=color.rgb(0, 187, 212, 100) )
///////////////////////////////
//@version=5
start21 = input(0.1)
increment21 = input(0.001)
maximum21 = input(1, "Max Value")
out21 = ta.sar(start21, increment21, maximum21)
//plot(out21, "Döngü", style=plot.style_line, color=#f0ce0e)
plot(out21, color=color.aqua, linewidth=3, title="1",style=plot.style_cross)
//////////////////////////////////////////////////////////////////////////////////////
//@version=5
BackStep = input.int(27,"Analysis Period")
lowerValue = input.float(0.382,"Lower Fibonacci Level",options=[0.236, 0.382, 0.50, 0.618, 0.786])
upperValue = input.float(0.618,"Upper Fibonacci Level",options=[0.236, 0.382, 0.50, 0.618, 0.786])
showFill = input.bool(true,"Show Filling")
changeCandle = input.bool(true,"Change Candle Color")
atr77 = ta.atr(200)
max = ta.highest(close,BackStep)
min = ta.lowest(close,BackStep)
lowerFib = min + (max-min)*lowerValue
upperFib = min + (max-min)*upperValue
ma = ta.wma(close,6)
float closeVal = ma
float openVal = ma
color clrToUse = closeVal>upperFib and openVal>upperFib?color.green:closeVal<lowerFib and openVal<lowerFib?color.red:color.yellow
LowerFibLine = plot(lowerFib,title="0.382",color=color.rgb(189, 75, 255, 100))
UpperFibLine = plot(upperFib,title="0.618",color=color.rgb(189, 75, 255, 100))
float LowerRetracement = (max-min)*0.318
float UpperRetracement = (max-min)*0.618
///////////////////////////////////////////////////////////////////////////////////////
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peacefulLizard50262
//@version=5
// Custom cosh function
cosh(float x) =>
(math.exp(x) + math.exp(-x)) / 2
// Custom acosh function
acosh(float x) =>
x < 1 ? na : math.log(x + math.sqrt(x * x - 1))
// Custom sinh function
sinh(float x) =>
(math.exp(x) - math.exp(-x)) / 2
// Custom asinh function
asinh(float x) =>
math.log(x + math.sqrt(x * x + 1))
// Custom inverse tangent function
atan(float x) =>
math.pi / 2 - math.atan(1 / x)
// Chebyshev Type I Moving Average
chebyshevI(float src, float len, float ripple) =>
a = 0.
b = 0.
g = 0.
chebyshev = 0.
a := cosh(1 / len * acosh(1 / (1 - ripple)))
b := sinh(1 / len * asinh(1 / ripple))
g := (a - b) / (a + b)
chebyshev := (1 - g) * src + g * nz(chebyshev[1])
chebyshev
// Chebyshev Type II Moving Average
chebyshevII(float src, float len, float ripple) =>
a = 0.
b = 0.
g = 0.
chebyshev = 0.
a := cosh(1 / len * acosh(1 / ripple))
b := sinh(1 / len * asinh(ripple))
g := (a - b) / (a + b)
chebyshev := (1 - g) * src + g * nz(chebyshev[1], src)
chebyshev
chebyshev(float src, float length, float ripple, bool style) =>
style ?
chebyshevI(src, length, ripple) :
chebyshevII(src, length, ripple)
source44 = input.source(hl2, "Source")
up_color = input.color(color.new(color.green, 20), "Up Color")
down_color = input.color(color.new(color.red, 20), "Down Color")
text_color = input.color(color.black, "Text Color")
mean_length = input.float(24, "Mean Length", 5, 1000, 0.5)
mean_ripple = input.float(0.5, "Mean Ripple", 0.01, 0.99, 0.01)
style44 = input.bool(false, "True Chebyshev I | False : Chebyshev II")
atr_style = input.bool(true, "True: |Open-Close| False: High-Low")
atr_length = input.float(64, "ATR Length", 6, 1000, 0.5)
atr_ripple = input.float(0.05, "Mean Ripple", 0.01, 0.99, 0.01)
multiplier = input.float(1.5, "Multiplier", 0.125, 10, 0.125)
alerts = input.bool(false, "Alerts")
labels = input.bool(false, "Labels")
atr = chebyshev(atr_style ? high - low : math.abs(open - close), atr_length, atr_ripple, style44)
mean = chebyshevI(source44, mean_length, mean_ripple)
var float offset = 0.0
var bool state = na
var float newOffset = 0.0
crossover = ta.crossover(source44, offset)
position = source44 > offset
crossunder = ta.crossunder(source44, offset)
prevOffset = nz(offset[1])
if crossover[2] and position[1] and position or (position and position[1] and position[2])
newOffset := mean - atr * multiplier
offset := newOffset < nz(prevOffset) or close[1] > nz(prevOffset) ? newOffset : nz(prevOffset)
state := true
if crossunder[2] and not position[1] and not position or (not position and not position[1] and not position[2])
newOffset := mean + atr * multiplier
offset := newOffset > nz(prevOffset) or close[1] < nz(prevOffset) ? newOffset : nz(prevOffset)
state := false
cross = ta.cross(close, offset)
down_trend = not state and not state[1]
up_trend = state and state[1]
colour = up_trend ? up_color : down_trend ? down_color : color.new(color.white, 100)
if up_trend and not up_trend[1] and labels
label.new(bar_index, offset, "Up Trend \n" + str.tostring(close), color = up_color, style = label.style_label_up, textcolor = text_color)
alert("Up Trend at " + str.tostring(close))
else
alert("Up Trend at " + str.tostring(close))
if down_trend and not down_trend[1] and labels
label.new(bar_index, offset, "Down Trend \n" + str.tostring(close), color = down_color, style = label.style_label_down, textcolor = text_color)
alert("Down Trend at " + str.tostring(close))
else
alert("Down Trend at " + str.tostring(close))
plot(offset, "Trend", colour, linewidth=3, style = plot.style_cross)
plotshape(cross, "Trend Is Getting Ready To Change", shape.xcross, location.belowbar, color = close > offset ? up_color : down_color)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
swing trade için....
otomatik ma...stop çizgisi yukarı keserse al.....tersi sat.....
trend takibi ile
üsteki kodun sadeleşmiş hali.....
PHP Code:
//@version=5
indicator('*', overlay=true, max_bars_back=201)
// 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, "Otomatik MA", style=plot.style_line, color=#fce305)
////////////////////////////////////////
//@version=5
import jdehorty/KernelFunctions/2 as kernel
DFT(x, y, Nx, _dir) =>
float _arg = 0.0
float _cos = 0.0
float _sin = 0.0
float xArr_i = 0.0
float yArr_i = 0.0
xArr = array.new_float(array.size(x))
yArr = array.new_float(array.size(y))
for i = 0 to Nx - 1 by 1
xArr_i := 0.0
yArr_i := 0.0
kx = float(i) / float(Nx)
_arg := -_dir * 2 * math.pi * kx
for k = 0 to Nx - 1 by 1
_cos := math.cos(k * _arg)
_sin := math.sin(k * _arg)
xArr_i += array.get(x, k) * _cos - array.get(y, k) * _sin
yArr_i += array.get(x, k) * _sin + array.get(y, k) * _cos
yArr_i
array.set(xArr, i, xArr_i)
array.set(yArr, i, yArr_i)
if _dir == 1
for i = 0 to Nx - 1 by 1
array.set(x, i, array.get(xArr, i) / float(Nx))
array.set(y, i, array.get(yArr, i) / float(Nx))
else
for i = 0 to Nx - 1 by 1
array.set(x, i, array.get(xArr, i))
array.set(y, i, array.get(yArr, i))
//======================================================================================================================
// INPUTS
//======================================================================================================================
N = input.int(1,"Fourier Period")
xval = input.source(close,"Fourier X Series",tooltip = "i.e. the source of the discrete Fourier"+
" transform (with the Y Series being the bars through time.)")
highlighting = input.bool(true,"Highlighting")
smoothing66 = input.int(10,"Kernel Smoothing")
//======================================================================================================================
// CALCULATIONS
//======================================================================================================================
// Fourier transform
x = array.new_float(N, 0.0)
y = array.new_float(N, 0.0)
for i = 0 to N - 1
array.set(x, i, xval[i])
array.set(y, i, 0.0)
DFT(x, y, N, 1)
mag = array.new_float(N, 0.0)
for i = 0 to N - 1
mag_i = math.sqrt(math.pow(array.get(x, i), 2) + math.pow(array.get(y, i), 2))
array.set(mag, i, mag_i)
dft = array.get(mag,0)
dfts = kernel.rationalQuadratic(dft,25,1,smoothing66)
//======================================================================================================================
// DISPLAY
//======================================================================================================================
plot(dfts, "Stop", color=color.aqua, style=plot.style_line )
///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peacefulLizard50262
//@version=5
// Custom cosh function
cosh(float x) =>
(math.exp(x) + math.exp(-x)) / 2
// Custom acosh function
acosh(float x) =>
x < 1 ? na : math.log(x + math.sqrt(x * x - 1))
// Custom sinh function
sinh(float x) =>
(math.exp(x) - math.exp(-x)) / 2
// Custom asinh function
asinh(float x) =>
math.log(x + math.sqrt(x * x + 1))
// Custom inverse tangent function
atan(float x) =>
math.pi / 2 - math.atan(1 / x)
// Chebyshev Type I Moving Average
chebyshevI(float src, float len, float ripple) =>
a = 0.
b = 0.
g = 0.
chebyshev = 0.
a := cosh(1 / len * acosh(1 / (1 - ripple)))
b := sinh(1 / len * asinh(1 / ripple))
g := (a - b) / (a + b)
chebyshev := (1 - g) * src + g * nz(chebyshev[1])
chebyshev
// Chebyshev Type II Moving Average
chebyshevII(float src, float len, float ripple) =>
a = 0.
b = 0.
g = 0.
chebyshev = 0.
a := cosh(1 / len * acosh(1 / ripple))
b := sinh(1 / len * asinh(ripple))
g := (a - b) / (a + b)
chebyshev := (1 - g) * src + g * nz(chebyshev[1], src)
chebyshev
chebyshev(float src, float length, float ripple, bool style) =>
style ?
chebyshevI(src, length, ripple) :
chebyshevII(src, length, ripple)
source44 = input.source(close, "Source")
up_color = input.color(color.new(color.green, 20), "Up Color")
down_color = input.color(color.new(color.red, 20), "Down Color")
text_color = input.color(color.black, "Text Color")
mean_length = input.float(24, "Mean Length", 5, 1000, 0.5)
mean_ripple = input.float(0.5, "Mean Ripple", 0.01, 0.99, 0.01)
style44 = input.bool(false, "True Chebyshev I | False : Chebyshev II")
atr_style = input.bool(true, "True: |Open-Close| False: High-Low")
atr_length = input.float(64, "ATR Length", 6, 1000, 0.5)
atr_ripple = input.float(0.05, "Mean Ripple", 0.01, 0.99, 0.01)
multiplier = input.float(1.5, "Multiplier", 0.125, 10, 0.125)
alerts = input.bool(true, "Alerts")
labels = input.bool(true, "Labels")
atr = chebyshev(atr_style ? high - low : math.abs(open - close), atr_length, atr_ripple, style44)
mean = chebyshevI(source44, mean_length, mean_ripple)
var float offset = 0.0
var bool state = na
var float newOffset = 0.0
crossover = ta.crossover(source44, offset)
position = source44 > offset
crossunder = ta.crossunder(source44, offset)
prevOffset = nz(offset[1])
if crossover[2] and position[1] and position or (position and position[1] and position[2])
newOffset := mean - atr * multiplier
offset := newOffset < nz(prevOffset) or close[1] > nz(prevOffset) ? newOffset : nz(prevOffset)
state := true
if crossunder[2] and not position[1] and not position or (not position and not position[1] and not position[2])
newOffset := mean + atr * multiplier
offset := newOffset > nz(prevOffset) or close[1] < nz(prevOffset) ? newOffset : nz(prevOffset)
state := false
cross = ta.cross(close, offset)
down_trend = not state and not state[1]
up_trend = state and state[1]
colour = up_trend ? up_color : down_trend ? down_color : color.new(color.white, 100)
if up_trend and not up_trend[1] and labels
label.new(bar_index, offset, "AL \n" + str.tostring(close), color = up_color, style = label.style_label_up, textcolor = text_color)
alert("AL " + str.tostring(close))
else
alert("Al " + str.tostring(close))
if down_trend and not down_trend[1] and labels
label.new(bar_index, offset, "SAT \n" + str.tostring(close), color = down_color, style = label.style_label_down, textcolor = text_color)
alert("SAT " + str.tostring(close))
else
alert("SAT " + str.tostring(close))
plot(offset, "Trend", colour, linewidth=2, style = plot.style_stepline)
plotshape(cross, "Trend Değişimi", shape.xcross, location.belowbar, color = close > offset ? up_color : down_color)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
düzenlemesi yapılacak örnek çalışma.....PHP Code:
//@version=5
indicator(".",overlay=true, max_labels_count = 100)
a=input(20,"Alpha")
b=input(true,"Maybe Dump Maybe Pump")
a1=2*ta.ema(high,a/10)-ta.sma(low,a/2)
a2=math.sqrt(ta.lowest(ta.highest(close,a),a/4)*a1)
b1=2*ta.ema(low,a/10)-ta.sma(high,a/2)
b2=math.sqrt(ta.highest(ta.lowest(close,a),a/4)*b1)
c1=ta.ema(math.sqrt(a2*b2),a/20)
plot(c1,color=#cd06e7,linewidth=1,transp=00)
barcolor(color=close>c1+ta.atr(20)*0.7?#2eec08:(close<c1-ta.atr(20)*0.7?#f00c0c:#eef109))
d1 = ta.sma(close, 20) + 2 * ta.stdev(close, 20)
d2 = ta.sma(close, 20) - 2 * ta.stdev(close, 20)
buy1 = ta.crossover(close, d2)
sell1 = ta.crossunder(close, d1)
buyrsi=ta.crossover(ta.rsi(close,7),30)
sellrsi=ta.crossunder(ta.rsi(close,7),70)
plotshape(b and buy1 and buyrsi , title = "Pump", text = 'X', style = shape.labelup, location = location.belowbar, color= color.green, textcolor = color.white, size = size.tiny)
plotshape(b and sell1 and sellrsi, title = "Dump", text = 'Y', style = shape.labeldown, location = location.abovebar, color= color.red, textcolor = color.white, size = size.tiny)
/////////////////////////////
///////////////////////////////////
// User inputs
prd = input.int(defval=10, 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, prd, prd)
float pl = ta.pivotlow(low, prd, prd)
plotshape(ph and show_pivots, style=shape.triangledown, location=location.abovebar, offset=-prd, size=size.tiny)
plotshape(pl and show_pivots, style=shape.triangleup, location=location.belowbar, offset=-prd, size=size.tiny)
// 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 - prd)
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 - prd)
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 prd - 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 >= prd
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 prd - 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 >= prd
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)
////////////////////////////////////////////////////
örnek üzerinde çalışılacak....PHP Code:
//@version=5
indicator('*', overlay=true, max_bars_back=201)
// 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, "Otomatik MA", style=plot.style_line, color=#fce305)
////////////////////////////////////////
//@version=5
import jdehorty/KernelFunctions/2 as kernel
DFT(x, y, Nx, _dir) =>
float _arg = 0.0
float _cos = 0.0
float _sin = 0.0
float xArr_i = 0.0
float yArr_i = 0.0
xArr = array.new_float(array.size(x))
yArr = array.new_float(array.size(y))
for i = 0 to Nx - 1 by 1
xArr_i := 0.0
yArr_i := 0.0
kx = float(i) / float(Nx)
_arg := -_dir * 2 * math.pi * kx
for k = 0 to Nx - 1 by 1
_cos := math.cos(k * _arg)
_sin := math.sin(k * _arg)
xArr_i += array.get(x, k) * _cos - array.get(y, k) * _sin
yArr_i += array.get(x, k) * _sin + array.get(y, k) * _cos
yArr_i
array.set(xArr, i, xArr_i)
array.set(yArr, i, yArr_i)
if _dir == 1
for i = 0 to Nx - 1 by 1
array.set(x, i, array.get(xArr, i) / float(Nx))
array.set(y, i, array.get(yArr, i) / float(Nx))
else
for i = 0 to Nx - 1 by 1
array.set(x, i, array.get(xArr, i))
array.set(y, i, array.get(yArr, i))
//======================================================================================================================
// INPUTS
//======================================================================================================================
N = input.int(1,"Fourier Period")
xval = input.source(close,"Fourier X Series",tooltip = "i.e. the source of the discrete Fourier"+
" transform (with the Y Series being the bars through time.)")
highlighting = input.bool(true,"Highlighting")
smoothing66 = input.int(10,"Kernel Smoothing")
//======================================================================================================================
// CALCULATIONS
//======================================================================================================================
// Fourier transform
x = array.new_float(N, 0.0)
y = array.new_float(N, 0.0)
for i = 0 to N - 1
array.set(x, i, xval[i])
array.set(y, i, 0.0)
DFT(x, y, N, 1)
mag = array.new_float(N, 0.0)
for i = 0 to N - 1
mag_i = math.sqrt(math.pow(array.get(x, i), 2) + math.pow(array.get(y, i), 2))
array.set(mag, i, mag_i)
dft = array.get(mag,0)
dfts = kernel.rationalQuadratic(dft,25,1,smoothing66)
//======================================================================================================================
// DISPLAY
//======================================================================================================================
plot(dfts, "Stop", color=color.aqua, style=plot.style_line )
///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peacefulLizard50262
//@version=5
// Custom cosh function
cosh(float x) =>
(math.exp(x) + math.exp(-x)) / 2
// Custom acosh function
acosh(float x) =>
x < 1 ? na : math.log(x + math.sqrt(x * x - 1))
// Custom sinh function
sinh(float x) =>
(math.exp(x) - math.exp(-x)) / 2
// Custom asinh function
asinh(float x) =>
math.log(x + math.sqrt(x * x + 1))
// Custom inverse tangent function
atan(float x) =>
math.pi / 2 - math.atan(1 / x)
// Chebyshev Type I Moving Average
chebyshevI(float src, float len, float ripple) =>
a = 0.
b = 0.
g = 0.
chebyshev = 0.
a := cosh(1 / len * acosh(1 / (1 - ripple)))
b := sinh(1 / len * asinh(1 / ripple))
g := (a - b) / (a + b)
chebyshev := (1 - g) * src + g * nz(chebyshev[1])
chebyshev
// Chebyshev Type II Moving Average
chebyshevII(float src, float len, float ripple) =>
a = 0.
b = 0.
g = 0.
chebyshev = 0.
a := cosh(1 / len * acosh(1 / ripple))
b := sinh(1 / len * asinh(ripple))
g := (a - b) / (a + b)
chebyshev := (1 - g) * src + g * nz(chebyshev[1], src)
chebyshev
chebyshev(float src, float length, float ripple, bool style) =>
style ?
chebyshevI(src, length, ripple) :
chebyshevII(src, length, ripple)
source44 = input.source(close, "Source")
up_color = input.color(color.new(color.green, 20), "Up Color")
down_color = input.color(color.new(color.red, 20), "Down Color")
text_color = input.color(color.black, "Text Color")
mean_length = input.float(24, "Mean Length", 5, 1000, 0.5)
mean_ripple = input.float(0.5, "Mean Ripple", 0.01, 0.99, 0.01)
style44 = input.bool(false, "True Chebyshev I | False : Chebyshev II")
atr_style = input.bool(true, "True: |Open-Close| False: High-Low")
atr_length = input.float(64, "ATR Length", 6, 1000, 0.5)
atr_ripple = input.float(0.05, "Mean Ripple", 0.01, 0.99, 0.01)
multiplier = input.float(1.5, "Multiplier", 0.125, 10, 0.125)
alerts = input.bool(true, "Alerts")
labels = input.bool(true, "Labels")
atr = chebyshev(atr_style ? high - low : math.abs(open - close), atr_length, atr_ripple, style44)
mean = chebyshevI(source44, mean_length, mean_ripple)
var float offset = 0.0
var bool state = na
var float newOffset = 0.0
crossover = ta.crossover(source44, offset)
position = source44 > offset
crossunder = ta.crossunder(source44, offset)
prevOffset = nz(offset[1])
if crossover[2] and position[1] and position or (position and position[1] and position[2])
newOffset := mean - atr * multiplier
offset := newOffset < nz(prevOffset) or close[1] > nz(prevOffset) ? newOffset : nz(prevOffset)
state := true
if crossunder[2] and not position[1] and not position or (not position and not position[1] and not position[2])
newOffset := mean + atr * multiplier
offset := newOffset > nz(prevOffset) or close[1] < nz(prevOffset) ? newOffset : nz(prevOffset)
state := false
cross = ta.cross(close, offset)
down_trend = not state and not state[1]
up_trend = state and state[1]
colour = up_trend ? up_color : down_trend ? down_color : color.new(color.white, 100)
if up_trend and not up_trend[1] and labels
label.new(bar_index, offset, "AL \n" + str.tostring(close), color = up_color, style = label.style_label_up, textcolor = text_color)
alert("AL " + str.tostring(close))
else
alert("Al " + str.tostring(close))
if down_trend and not down_trend[1] and labels
label.new(bar_index, offset, "SAT \n" + str.tostring(close), color = down_color, style = label.style_label_down, textcolor = text_color)
alert("SAT " + str.tostring(close))
else
alert("SAT " + str.tostring(close))
plot(offset, "Trend", colour, linewidth=2, style = plot.style_stepline)
plotshape(cross, "Trend Değişimi", shape.xcross, location.belowbar, color = close > offset ? up_color : down_color)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
üzerinde çalışılacak örnek....PHP Code:
// 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/
// © LuxAlgo
//@version=5
indicator("*", overlay = true)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
mult = input.float(5, 'Multiplicative Factor', minval = 0)
slope = input.float(14, 'Slope', minval = 0)
width = input.float(80, 'Width %', minval = 0, maxval = 100) / 100
//Style
bullCss = input.color(color.yellow, 'Average Color', inline = 'avg', group = 'Style')
bearCss = input.color(color.aqua, '' , inline = 'avg', group = 'Style')
area = input.string('Gradient', 'Area', options = ['Gradient', 'Solid'], group = 'Style')
upperCss = input.color(color.new(color.aqua, 70), 'Upper Area', group = 'Style')
lowerCss = input.color(color.new(color.yellow, 70) , 'Lower Area', group = 'Style')
//-----------------------------------------------------------------------------}
//Calculation
//-----------------------------------------------------------------------------{
var float upper = na
var float lower = na
var float avg = close
var hold = 0.
var os = 1.
atr = nz(ta.atr(200)) * mult
avg := math.abs(close - avg) > atr ?
math.avg(close, avg)
: avg + os * (hold / mult / slope)
os := math.sign(avg - avg[1])
hold := os != os[1] ? atr : hold
upper := avg + width * hold
lower := avg - width * hold
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
css = os == 1 ? bullCss : bearCss
plot_upper = plot(upper, 'Yüksek', na)
plot_avg = plot(avg, 'Ortalama', os != os[1] ? na : css)
plot_lower = plot(lower, 'Düşük', na)
var color upper_topcol = na
var color upper_btmcol = na
var color lower_topcol = na
var color lower_btmcol = na
//Fill
if area == 'Gradient'
upper_topcol := upperCss
upper_btmcol := color.new(chart.bg_color, 100)
lower_topcol := color.new(chart.bg_color, 100)
lower_btmcol := lowerCss
else
upper_topcol := upperCss
upper_btmcol := upperCss
lower_topcol := lowerCss
lower_btmcol := lowerCss
//Upper Area
fill(plot_upper, plot_avg
, top_color = os != os[1] ? na : upper_topcol
, bottom_color = os != os[1] ? na : upper_btmcol
, top_value = upper
, bottom_value = avg)
//Lower Area
fill(plot_avg, plot_lower
, top_color = os != os[1] ? na : lower_topcol
, bottom_color = os != os[1] ? na : lower_btmcol
, top_value = avg
, bottom_value = lower)
//-----------------------------------------------------------------------------}
//
//rodavlas12
//@version=5
// Input settings
ccimomCross = input.string('CCI', 'Entry Signal Source', options=['CCI', 'Momentum'], tooltip='CCI or Momentum will be the final source of the Entry signal if selected.')
ccimomLength = input.int(10, minval=1, title='CCI/Momentum Length')
useDivergence = input.bool(true, title='Find Regular Bullish/Bearish Divergence', tooltip='If checked, it will only consider an overbought or oversold condition that has a regular bullish or bearish divergence formed inside that level.')
rsiOverbought = input.int(65, minval=1, title='RSI Overbought Level', tooltip='Adjusting the level to extremely high may filter out some signals especially when the option to find divergence is checked.')
rsiOversold = input.int(35, minval=1, title='RSI Oversold Level', tooltip='Adjusting this level extremely low may filter out some signals especially when the option to find divergence is checked.')
rsiLength = input.int(14, minval=1, title='RSI Length')
plotMeanReversion = input.bool(false, 'Plot Mean Reversion Bands on the chart', tooltip='This function doesn\'t affect the entry of signal but it suggests buying when the price is at the lower band, and then sell it on the next bounce at the higher bands.')
emaPeriod = input(200, title='Lookback Period (EMA)')
bandMultiplier = input.float(1.8, title='Outer Bands Multiplier', tooltip='Multiplier for both upper and lower bands')
// CCI and Momentum calculation
momLength = ccimomCross == 'Momentum' ? ccimomLength : 10
mom = close - close[momLength]
cci = ta.cci(close, ccimomLength)
ccimomCrossUp = ccimomCross == 'Momentum' ? ta.cross(mom, 0) : ta.cross(cci, 0)
ccimomCrossDown = ccimomCross == 'Momentum' ? ta.cross(0, mom) : ta.cross(0, cci)
// RSI calculation
src = close
up = ta.rma(math.max(ta.change(src), 0), rsiLength)
down = ta.rma(-math.min(ta.change(src), 0), rsiLength)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)
oversoldAgo = rsi[0] <= rsiOversold or rsi[1] <= rsiOversold or rsi[2] <= rsiOversold or rsi[3] <= rsiOversold
overboughtAgo = rsi[0] >= rsiOverbought or rsi[1] >= rsiOverbought or rsi[2] >= rsiOverbought or rsi[3] >= rsiOverbought
// Regular Divergence Conditions
bullishDivergenceCondition = rsi[0] > rsi[1] and rsi[1] < rsi[2]
bearishDivergenceCondition = rsi[0] < rsi[1] and rsi[1] > rsi[2]
// Entry Conditions
longEntryCondition = ccimomCrossUp and oversoldAgo and (not useDivergence or bullishDivergenceCondition)
shortEntryCondition = ccimomCrossDown and overboughtAgo and (not useDivergence or bearishDivergenceCondition)
// Mean Reversion Indicator
meanReversion = plotMeanReversion ? ta.ema(close, emaPeriod) : na
stdDev = plotMeanReversion ? ta.stdev(close, emaPeriod) : na
upperBand = plotMeanReversion ? meanReversion + stdDev * bandMultiplier : na
lowerBand = plotMeanReversion ? meanReversion - stdDev * bandMultiplier : na
// Plotting
plotshape(longEntryCondition, title='BUY', style=shape.triangleup, text='B', location=location.belowbar, color=color.new(color.lime, 0), textcolor=color.new(color.white, 0), size=size.tiny)
plotshape(shortEntryCondition, title='SELL', style=shape.triangledown, text='S', location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), size=size.tiny)
//plot(upperBand, title='Upper Band', color=color.new(color.fuchsia, 0), linewidth=1)
//plot(meanReversion, title='Mean', color=color.new(color.gray, 0), linewidth=1)
//plot(lowerBand, title='Lower Band', color=color.new(color.blue, 0), linewidth=1)
// Entry signal alerts
//alertcondition(longEntryCondition, title='BUY Signal', message='Buy Entry Signal')
//alertcondition(shortEntryCondition, title='SELL Signal', message='Sell Entry Signal')
//alertcondition(longEntryCondition or shortEntryCondition, title='BUY or SELL Signal', message='Entry Signal')
////////////////////////////////////////////
// © TommasoRossini
//@version=5
lnt = input(200, "Lenght")
lnt2 = input.int(10, "Smooth", minval = 1)
lnt3 = input.float(1.00, "Zone Width", minval = 0.5, maxval = 3, step = 0.25)
downcol = input.color(#e91e6200, "Premium color")
upcol = input.color(#2962ff00, "Discount color")
atrs = ta.sma(ta.atr(lnt), lnt) * lnt3
max = ta.highest(high, lnt)
min = ta.lowest(low, lnt)
[middle, upper11, lower11] = ta.bb(close, lnt, 2)
upfirst = ta.sma(math.avg(max, upper11), lnt2)
downfirst = ta.sma(math.avg(min, lower11), lnt2)
upsecond = upfirst + atrs
downsecond = downfirst - atrs
average = math.avg(upfirst, downfirst, math.avg(max, min))
upavg = math.avg(average, upfirst)
downavg = math.avg(average, downfirst)
p1 = plot(upfirst, color = color.new(downcol, 100), editable = false)
p2 = plot(upsecond, color = color.new(downcol, 0), title = "Direnç")
p3 = plot(downfirst, color = color.new(upcol, 100), editable = false)
p4 = plot(downsecond, color = color.new(upcol, 0), title = "Destek")
//fill(p1, p2, color = color.new(downcol, 85), title = "Roof fill")
//fill(p3, p4, color = color.new(upcol, 85), title = "Floor fill")
plot(close > middle ? upavg : na, color = color.new(downcol, 100), style = plot.style_linebr, title = "Yukarı Kırılım")
plot(close < middle ? downavg : na, color = color.new(upcol, 100), style = plot.style_linebr, title = "Aşağı Kırılım")
///////////////////////////////////////////////////////////
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RicardoSantos, midtownsk8rguy
// Cycle functions by: midtownsk8rguy
// https://www.tradingview.com/script/wyyXKHDn-Correlation-Cycle-CorrelationAngle-Market-State-John-Ehlers/
rad2deg(Rad) => // Radians To Degrees
var DEGREES_IN_1_RADIAN = 90.0 / math.asin(1.0) // 57.29577951308 Constant
Rad * DEGREES_IN_1_RADIAN
cc(Series, Period) => // Correlation Cycle Function
var PIx2 = 4.0 * math.asin(1.0) // 6.28318530718 Constant
period = math.max(2, Period)
Rx = 0.0
Rxx = 0.0
Rxy = 0.0
Ryy = 0.0
Ry = 0.0
Ix = 0.0
Ixx = 0.0
Ixy = 0.0
Iyy = 0.0
Iy = 0.0
for i = 1 to period by 1
iMinusOne = i - 1
X = nz(Series[iMinusOne])
temp = PIx2 * iMinusOne / period
Yc = math.cos(temp)
Ys = -math.sin(temp)
Rx += X
Ix += X
Rxx += X * X
Ixx += X * X
Rxy += X * Yc
Ixy += X * Ys
Ryy += Yc * Yc
Iyy += Ys * Ys
Ry += Yc
Iy += Ys
Iy
realPart = 0.0
temp_1 = period * Rxx - Rx * Rx
temp_2 = period * Ryy - Ry * Ry
if temp_1 > 0.0 and temp_2 > 0.0
realPart := (period * Rxy - Rx * Ry) / math.sqrt(temp_1 * temp_2)
realPart
imagPart = 0.0
temp_1 := period * Ixx - Ix * Ix
temp_2 := period * Iyy - Iy * Iy
if temp_1 > 0.0 and temp_2 > 0.0
imagPart := (period * Ixy - Ix * Iy) / math.sqrt(temp_1 * temp_2)
imagPart
[realPart, imagPart]
cap(RealPart, ImaginaryPart) => // Correlation Angle Phasor Function
var HALF_OF_PI = math.asin(1.0) // 1.57079632679 Constant
angle = ImaginaryPart == 0.0 ? 0.0 : rad2deg(math.atan(RealPart / ImaginaryPart) + HALF_OF_PI)
if ImaginaryPart > 0.0
angle -= 180.0
angle
priorAngle = nz(angle[1])
if priorAngle > angle and priorAngle - angle < 270.0
angle := priorAngle
angle
angle
//------------------------------------------------------------------------------
int length = input(23)
bool use_automatic_selection = input(false)
float cycle_length = length
if use_automatic_selection
[_real, _imag] = cc(close, length)
cycle_length := math.round(cap(_real, _imag))
cycle_length
bool is_new_cycle = false
if bar_index % cycle_length == cycle_length - 1
is_new_cycle := true
is_new_cycle
var float avg11 = open
var color pl_color = color.new(color.gray, 0)
var bool is_up = na
var line li_slope = line.new(x1=bar_index, y1=open, x2=bar_index, y2=open, xloc=xloc.bar_index, extend=extend.right, color=color.yellow, style=line.style_dotted, width=2)
var line li_trend = line.new(x1=bar_index, y1=open, x2=bar_index, y2=open, xloc=xloc.bar_index, extend=extend.right, color=color.yellow, style=line.style_dashed, width=2)
var float max11 = high
var float min11 = low
if high > max11
max11 := math.max(high, avg11)
max11
if low < min
min11 := math.min(low, avg11)
min11
if is_new_cycle
avg11 := (nz(avg11) * (1 + 1 / cycle_length) + close * (1 - 1 / cycle_length)) / 2
max11 := high
min11 := low
if avg11 > avg11[1]
is_up := true
pl_color := color.new(color.lime, 0)
if not is_up[1]
line.set_xy1(id=li_trend, x=line.get_x1(id=li_slope), y=avg11[1])
line.set_xy2(id=li_trend, x=bar_index[0], y=avg11)
else
line.set_xy2(id=li_trend, x=bar_index[0], y=avg11)
if avg11 < avg11[1]
is_up := false
pl_color := color.new(color.red, 0)
if is_up[1]
line.set_xy1(id=li_trend, x=line.get_x1(id=li_slope), y=avg11[1])
line.set_xy2(id=li_trend, x=bar_index[0], y=avg11)
else
line.set_xy2(id=li_trend, x=bar_index[0], y=avg11)
line.set_x1(id=li_slope, x=bar_index[1])
line.set_xy2(id=li_slope, x=bar_index[0], y=avg)
// line.new(x1=bar_index[cycle_length], y1=avg[cycle_length], x2=bar_index[0], y2=avg[0], xloc=xloc.bar_index, extend=extend.right, color=color.blue, style=line.style_dotted, width=1)
if is_up
line.set_y1(id=li_slope, y=avg - (max11 - min11) / cycle_length)
else
line.set_y1(id=li_slope, y=avg + (max11 - min11) / cycle_length)
plot(series=avg, title='Trend', color=pl_color, linewidth=2, style=plot.style_stepline)