-
ozgurhan'dan
lux algo'nun ücretli satılan indikatörünün free alarmlı olanı.
Mutlaka 2. bir indikatör ile teyit alınız.
https://www.tradingview.com/script/T...cation_publish
range filter indikatörünün daha da güçlendirilmiş hali olan strateji indikatörü, alarmları da var.
Nasdaq hisselerinde aşağıda vereceğim linkte 1 ay sonrası için minimum %2 temettü verecek hisseye bakıyoruz.
Örneğin 20 temmuzda %5.2 temettü verecek CBRL hissesini görüyoruz ve teknik analizine bakıyoruz ve firma hakkında araştırmalara başlıyoruz.
Dolar üzerinden hep trade hem de %5 almak iyi para.
https://www.nasdaq.com/market-activity/dividends
NASDAQ TSLA
nadaraya tarzı bir indikatör fakat repaint yapsada sizin çizeceğiniz pullback hareketlere göre çizgi yeşil olduğu ve yeni bir HH yaptığı yerden al, tersi sat.
https://tr.tradingview.com/script/N2...or-ChartPrime/
Trend dönüşümleri ve pulback hareketlerde ema 50 kullanılır.
Fiyat ema 50 üstünde ve yeni HH hareketde ve linkini vereceğim macd indikatöründe yeşil ise işleme girilir.
Yeni bir LL'de ise macd kırmızı ise satış onayı alınır.
https://tr.tradingview.com/script/o5...tum-LinearReg/
-
strateji deneme örnekleri.....
https://www.tradingview.com/x/VcGKrVW7/
PHP Code:
// 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
strategy('deneme', overlay=true, max_bars_back=201)
///////////////////////////////////////////////////////////////////////////////////////
// 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, "deneme", 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)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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 > offset ? BullishColor : close < offset ? BearishColor : nz(lastBarColor[1])
// Change bar color
lastBarColor := barColorBasedOnDEMATrend
barcolor(color=changebarcol ? barColorBasedOnDEMATrend : na)
b = ta.crossover(close,offset)
s = ta.crossunder(close,offset)
in_b = ta.barssince(b)[1] < ta.barssince(s)[1]
in_s = ta.barssince(s)[1] < ta.barssince(b)[1]
if b
strategy.entry("Long",strategy.long)
if s
strategy.close("Long")
-
https://www.tradingview.com/x/AjuWHk7x/
PHP Code:
//@version=5
strategy('deneme', overlay=true, max_bars_back=500)
///////////////////////////////////////////////////////////////////////////////////////
//@version=5
// 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, "deneme", style=plot.style_line, color=#ffeb3b00)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
BullishColor = input.color(color.lime)
BearishColor = input.color(color.red)
barColorBasedOnDEMATrend = close > scma ? BullishColor : close < scma ? BearishColor : nz(lastBarColor[1])
lastBarColor := barColorBasedOnDEMATrend
barcolor(color=changebarcol ? barColorBasedOnDEMATrend : na)
b = ta.crossover(close,scma)
s = ta.crossunder(close,scma)
if b
strategy.entry("Long",strategy.long)
if s
strategy.close("Long")
-
https://www.tradingview.com/x/GSS2ikPS/
PHP Code:
//@version=5
strategy('deneme', overlay=true, max_bars_back=500)
///////////////////////////////////////////////////////////////////////////////////////
length=(1)
src=close
start1 = input(0.1)
increment1 = input(0.1)
maximum1 = input(1, "Max Value")
out1 = ta.sar(start1, increment1, maximum1)
momo1 = src - src[length]
smdo1 = out1 - momo1
plot(smdo1, "deneme", style=plot.style_line, color=#f0ce0e00)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
BullishColor = input.color(color.lime)
BearishColor = input.color(color.red)
barColorBasedOnDEMATrend = close > smdo1 ? BullishColor : close < smdo1 ? BearishColor : nz(lastBarColor[1])
lastBarColor := barColorBasedOnDEMATrend
barcolor(color=changebarcol ? barColorBasedOnDEMATrend : na)
b = ta.crossover(close,smdo1)
s = ta.crossunder(close,smdo1)
if b
strategy.entry("Long",strategy.long)
if s
strategy.close("Long")
-
https://www.tradingview.com/x/v14kGcFZ/
PHP Code:
//@version=5
strategy('deneme', overlay=true, max_bars_back=500)
///////////////////////////////////////////////////////////////////////////////////////
// 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, "deneme", color=color44, style=plot.style_cross, linewidth = 3)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
BullishColor = input.color(color.lime)
BearishColor = input.color(color.red)
barColorBasedOnDEMATrend = close > ghla ? BullishColor : close < ghla ? BearishColor : nz(lastBarColor[1])
lastBarColor := barColorBasedOnDEMATrend
barcolor(color=changebarcol ? barColorBasedOnDEMATrend : na)
b = ta.crossover(close,ghla)
s = ta.crossunder(close,ghla)
if b
strategy.entry("Long",strategy.long)
if s
strategy.close("Long")
-
https://www.tradingview.com/x/TdbKesMQ/
PHP Code:
//@version=5
strategy('deneme', overlay=true, max_bars_back=500)
///////////////////////////////////////////////////////////////////////////////////////
//@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, "deneme", color=color.rgb(0, 187, 212, 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
BullishColor = input.color(color.lime)
BearishColor = input.color(color.red)
barColorBasedOnDEMATrend = close > dfts ? BullishColor : close < dfts ? BearishColor : nz(lastBarColor[1])
lastBarColor := barColorBasedOnDEMATrend
barcolor(color=changebarcol ? barColorBasedOnDEMATrend : na)
b = ta.crossover(close,dfts)
s = ta.crossunder(close,dfts)
if b
strategy.entry("Long",strategy.long)
if s
strategy.close("Long")
-
https://www.tradingview.com/x/8NXGr86w/
PHP Code:
//@version=5
strategy('deneme', overlay=true, max_bars_back=500)
///////////////////////////////////////////////////////////////////////////////////////
//@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
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
BullishColor = input.color(color.lime)
BearishColor = input.color(color.red)
barColorBasedOnDEMATrend = close > lowerFib ? BullishColor : close < lowerFib ? BearishColor : nz(lastBarColor[1])
lastBarColor := barColorBasedOnDEMATrend
barcolor(color=changebarcol ? barColorBasedOnDEMATrend : na)
b = ta.crossover(close,lowerFib)
s = ta.crossunder(close,lowerFib)
if b
strategy.entry("Long",strategy.long)
if s
strategy.close("Long")
-
bu basit strateji örnekleri...
farklı değerlerle denenebilir....
birkaçı ile beraber strateji oluşturulabilir gibi....
verilen örneklerden 3 tanesinin birleşimi ile
oluşturulan...
örnek..... https://www.tradingview.com/x/quOTRBTn/
PHP Code:
// 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
strategy('*', 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, "MA", style=plot.style_line, color=#ffeb3b00)
////////////////////////////////////////
length=(1)
src=close
start1 = input(0.1)
increment1 = input(0.1)
maximum1 = input(1, "Max Value")
out1 = ta.sar(start1, increment1, maximum1)
momo1 = src - src[length]
smdo1 = out1 - momo1
//plot(smdo1, "DD", style=plot.style_line, color=#f0ce0efd)
/////////////////////////////////////////////////////////
// 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, "Trend2", color=color44, style=plot.style_cross, linewidth = 3)
////////////////////////////////////////////////////////////////////////////
///////////////////////////////
// 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()
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
//////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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 > scma and close > ghla and close > smdo1 ? BullishColor : close < scma and close < ghla and close < smdo1 ? BearishColor : nz(lastBarColor[1])
// Change bar color
lastBarColor := barColorBasedOnDEMATrend
barcolor(color=changebarcol ? barColorBasedOnDEMATrend : na)
x = ta.crossover(close,scma) and ta.crossover(close,ghla) and ta.crossover(close,smdo1)
y = ta.crossunder(close,scma) and ta.crossunder(close,ghla) 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")