https://tr.tradingview.com/v/NIuGTgAO/
pivota göre trend çekiyor...rakamlar küçültülebilir....
Printable View
https://tr.tradingview.com/v/NIuGTgAO/
pivota göre trend çekiyor...rakamlar küçültülebilir....
https://tr.tradingview.com/v/m0G2Xv7r/
otomatik mft var....
https://tr.tradingview.com/v/5Q0rRNo6/
çift bolinger...
https://tr.tradingview.com/v/zvy7J87b/ bunu ana trend ve ileri projeksiyon olarak düşünün...
https://tr.tradingview.com/v/ZXIm3q7G/ bunu rsı ccı gibi....hazır strateji olarak düşünün....
https://tr.tradingview.com/v/Bcufg8oX/ bunu dip tepeler için kanal düşünün.....
https://tr.tradingview.com/v/zLGM4F2M/ bunu destek ve direnç olarak düşünün....
bu dördünü bir sistem olarak düşünün...
kodların birleşmiş hali....
istediğiniz değişiklilrei ve ayarlamaları yapın.....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("HyperTrend [LuxAlgo]", "LuxAlgo - HyperTrend", 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.teal, 'Average Color', inline = 'avg', group = 'Style')
bearCss = input.color(color.red, '' , inline = 'avg', group = 'Style')
area = input.string('Gradient', 'Area', options = ['Gradient', 'Solid'], group = 'Style')
upperCss = input.color(color.new(color.red, 70), 'Upper Area', group = 'Style')
lowerCss = input.color(color.new(color.teal, 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, 'Upper', na)
plot_avg = plot(avg, 'Average', os != os[1] ? na : css)
plot_lower = plot(lower, 'Lower', 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(#e91e63, "Premium color")
upcol = input.color(#2962ff, "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 = "Roof")
p3 = plot(downfirst, color = color.new(upcol, 100), editable = false)
p4 = plot(downsecond, color = color.new(upcol, 0), title = "Floor")
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, 25), style = plot.style_linebr, title = "Second Roof")
plot(close < middle ? downavg : na, color = color.new(upcol, 25), style = plot.style_linebr, title = "Second Floor")
///////////////////////////////////////////////////////////
// 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(20)
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.navy, style=line.style_dotted, width=1)
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.navy, style=line.style_dashed, width=1)
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='avg', color=pl_color, linewidth=2, style=plot.style_stepline)
görüntü....
https://i.hizliresim.com/ds9orl8.png
https://www.tradingview.com/x/KV6UoDk1/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)
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)
üzerinde çalışılacak örnek...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)
////////////////////////////////////////////////////
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
https://tr.tradingview.com/v/ed8Sv4PQ/
plotların çoğu kapatılmış görüntü... https://www.tradingview.com/x/ewhTUocn/
not data 5-20 kullanılmıştır....
kodun tasarım hali görüntüsü......https://www.tradingview.com/x/z70FCfiO/
plotlar iptal edilmiş şekilde....
79 kod parçacığının birleşmiş hali......
ham halini kullanmak isteyenler için....
kendilerine göre plot düzenlemeleri ve ortalama ayarlamak isteyenler için....
birleştirilmiş hali....
çalışmıyor demeyin....PHP Code:
//@version=5
indicator('*', max_bars_back=500, overlay=true)
////////////////////Ana Kalıp/////////////////////////
inp = input(title='Source', defval=close)
res = input.timeframe(title='Resolution', defval='')
rep = input(title='Allow Repainting?', defval=false)
///////////////////////Fiyat üzerinde macd hesaplamasıdır///////////////////////////////
src1 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fastLength1 = input.int(title='FastLength', defval=12, minval=1)
slowLength1 = input.int(title='SlowLength', defval=26, minval=1)
signalLength1 = input.int(title='SignalLength', defval=9, minval=1)
macdLevel1 = input.float(title='MacdLevel', defval=0, minval=0)
fastAlpha1 = 2.0 / (1 + fastLength1)
slowAlpha1 = 2.0 / (1 + slowLength1)
fastEma1 = ta.ema(src1, fastLength1)
slowEma1 = ta.ema(src1, slowLength1)
pMacdEq1 = fastAlpha1 - slowAlpha1 != 0 ? ((nz(fastEma1[1]) * fastAlpha1) - (nz(slowEma1[1]) * slowAlpha1)) / (fastAlpha1 - slowAlpha1) : 0
pMacdEqSig1 = ta.ema(pMacdEq1, signalLength1)
pMacdLevel1 = fastAlpha1 - slowAlpha1 != 0 ? (macdLevel1 - (nz(fastEma1[1]) * (1 - fastAlpha1)) + (nz(slowEma1[1]) * (1 - slowAlpha1))) / (fastAlpha1 - slowAlpha1) : 0
slo1 = src1 - pMacdEq1
sig1 = slo1 > 0 ? slo1 > nz(slo1[1]) ? 2 : 1 : slo1 < 0 ? slo1 < nz(slo1[1]) ? -2 : -1 : 0
rmacdColor = sig1 > 1 ? color.rgb(76, 175, 79, 00) : sig1 > 0 ? color.rgb(76, 175, 79, 00) : sig1 < -1 ? color.rgb(255, 82, 82, 00) : sig1 < 0 ? color.rgb(255, 82, 82, 00) : color.rgb(255, 255, 255, 100)
/////////////////////////////////////////////////////////////////////////////////
src2 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length2 = input.int(title='Length', defval=20, minval=1)
gainLimit2 = input.int(title='GainLimit', defval=50, minval=1)
alpha2 = 2 / (length2 + 1)
ema2 = 0.0
ema2 := alpha2 * src2 + (1 - alpha2) * nz(ema2[1])
leastError2 = 1000000.0
ecEma2 = 0.0
error2 = 0.0
bestGain2 = 0.0
for int i = -gainLimit2 to gainLimit2 by 1
gain2 = i / 10
ecEma2 := alpha2 * (ema2 + gain2 * (src2 - nz(ecEma2[1]))) + (1 - alpha2) * nz(ecEma2[1])
error2 := src2 - ecEma2
if math.abs(error2) < leastError2
leastError2 := math.abs(error2)
bestGain2 := gain2
bestGain2
ecEma2 := alpha2 * (ema2+ bestGain2 * (src2 - nz(ecEma2[1]))) + (1 - alpha2) * nz(ecEma2[1])
slo2 = src2 - ecEma2
sig2 = slo2 > 0 ? slo2 > nz(slo2[1]) ? 2 : 1 : slo2 < 0 ? slo2 < nz(slo2[1]) ? -2 : -1 : 0
/////////////////////////////////////////////////////////
src3 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length3 = input.int(title='Length', defval=12, minval=1)
rmsLength3 = input.int(title='RMSLength', defval=50, minval=1)
mom3 = src3 - nz(src3[length3])
hannLength3 = math.ceil(length3 / 1.4)
filt3 = 0.0
coef3 = 0.0
for i = 1 to hannLength3 by 1
cos3 = 1 - math.cos(2 * math.pi * i / (hannLength3 + 1))
filt3 += cos3 * nz(mom3[i - 1])
coef3 += cos3
coef3
hFilt3 = coef3 != 0 ? filt3 / coef3 : 0
filtMa3 = math.sum(math.pow(hFilt3, 2), rmsLength3) / rmsLength3
rms3 = filtMa3 > 0 ? math.sqrt(filtMa3) : 0
scaledFilt3 = rms3 != 0 ? hFilt3 / rms3 : 0
a13 = math.exp(-1.414 * math.pi * math.abs(scaledFilt3) / length3)
b13 = 2 * a13 * math.cos(1.414 * math.pi * math.abs(scaledFilt3) / length3)
c23 = b13
c33 = -a13 * a13
c13 = 1 - c23 - c33
dsss3 = 0.0
dsss3 := c13 * ((src3 + nz(src3[1])) / 2) + c23 * nz(dsss3[1]) + c33 * nz(dsss3[2])
slo3 = src3 - dsss3
sig3 = slo3 > 0 ? slo3 > nz(slo3[1]) ? 2 : 1 : slo3 < 0 ? slo3 < nz(slo3[1]) ? -2 : -1 : 0
///////////////////////////////////////////////////////////
src4 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length4 = input.int(title='Length', defval=27, minval=1)
a14 = math.exp(-1.414 * math.pi / length4)
b14 = 2 * a14 * math.cos(1.414 * math.pi / length4)
c24 = b14
c34 = -a14 * a14
c14 = 1 - c24 - c34
ssf4 = 0.0
ssf4 := bar_index < 3 ? src4 : 0.5 * c14 * (src4 + nz(src4[1])) + c24 * nz(ssf4[1]) + c34 * nz(ssf4[2])
e14 = 0.0
e14 := bar_index < 3 ? 0 : c14 * (src4 - ssf4) + c24 * nz(e14[1]) + c34 * nz(e14[2])
aef4 = ssf4 + e14
slo4 = src4 - nz(aef4[1])
sig4 = slo4 > 0 ? slo4 > nz(slo4[1]) ? 2 : 1 : slo4 < 0 ? slo4 < nz(slo4[1]) ? -2 : -1 : 0
//////////////////////////////////////////////////////////////////////////////////
src5 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
acc5 = input.float(title='Accelerator', defval=1.0, minval=1.0, step=0.01)
minLength5 = input.int(title='MinLength', defval=5, minval=1)
maxLength5 = input.int(title='MaxLength', defval=50, minval=1)
smoothLength5 = input.int(title='SmoothLength', defval=4, minval=1)
mult5 = input.float(title='Multiple', defval=2.0, minval=.01)
mean5 = ta.sma(src5, maxLength5)
stdDev5 = ta.stdev(src5, maxLength5)
a5 = mean5 - 1.75 * stdDev5
b5 = mean5 - 0.25 * stdDev5
c5 = mean5 + 0.25 * stdDev5
d5 = mean5 + 1.75 * stdDev5
length5 = 0.0
length5 := src5 >= b5 and src5 <= c5 ? nz(length5[1], maxLength5) + 1 : src5 < a5 or src5 > d5 ? nz(length5[1], maxLength5) - 1 : nz(length5[1], maxLength5)
length5 := math.max(math.min(length5, maxLength5), minLength5)
len5 = math.round(length5)
mf5 = na(volume) or volume == 0 ? 100.0 - 100.0 / (1.0 + src5 / len5) : ta.mfi(src5, len5)
mfScaled5 = mf5 * 2 - 100
p5 = acc5 + math.abs(mfScaled5) / 25
sum5 = 0.0
weightSum5 = 0.0
for i = 0 to len5 - 1 by 1
weight5 = math.pow(len5 - i, p5)
sum5 += src5[i] * weight5
weightSum5 += weight5
weightSum5
uma5 = ta.wma(sum5 / weightSum5, smoothLength5)
stdev55 = ta.stdev(src5, len5)
upperBand5 = uma5 + stdev55 * mult5
lowerBand5 = uma5 - stdev55 * mult5
slo5 = src5 - uma5
sig5 = src5 > upperBand5 and nz(src5[1]) <= nz(upperBand5[1]) or src5 > lowerBand5 and nz(src5[1]) <= nz(lowerBand5[1]) ? 1 : src5 < lowerBand5 and nz(src5[1]) >= nz(lowerBand5[1]) or src5 < upperBand5 and nz(src5[1]) >= nz(upperBand5[1]) ? -1 : slo5 > 0 ? slo5 > nz(slo5[1]) ? 2 : 1 : slo5< 0 ? slo5 < nz(slo5[1]) ? -2 : -1 : 0
//////////////////////////////////////////////////////////////////////////////////
src6 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
acc6 = input.float(title='Accelerator', defval=1.0, minval=1.0, step=0.01)
minLength6 = input.int(title='MinLength', defval=5, minval=1)
maxLength6 = input.int(title='MaxLength', defval=50, minval=1)
smoothLength6 = input.int(title='SmoothLength', defval=4, minval=1)
mean6 = ta.sma(src6, maxLength6)
stdDev6 = ta.stdev(src6, maxLength6)
a6 = mean6 - 1.75 * stdDev6
b6 = mean6 - 0.25 * stdDev6
c6 = mean6 + 0.25 * stdDev6
d6 = mean6 + 1.75 * stdDev6
length6 = 0.0
length6 := src6 >= b6 and src6 <= c6 ? nz(length6[1], maxLength6) + 1 : src6 < a6 or src6 > d6 ? nz(length6[1], maxLength6) - 1 : nz(length6[1], maxLength6)
length6 := math.max(math.min(length6, maxLength6), minLength6)
len6 = math.round(length6)
mf6 = na(volume) or volume == 0 ? 100.0 - 100.0 / (1.0 + src6 / len6) : ta.mfi(src6, len6)
mfScaled6 = mf6 * 2 - 100
p6 = acc6 + math.abs(mfScaled6) / 25
sum6 = 0.0
weightSum6 = 0.0
for i = 0 to len6 - 1 by 1
weight6 = math.pow(len6 - i, p6)
sum6 += src6[i] * weight6
weightSum6 += weight6
weightSum6
uma6 = ta.wma(sum6 / weightSum6, smoothLength6)
slo6 = src6 - uma6
sig6 = slo6 > 0 ? slo6 > nz(slo6[1]) ? 2 : 1 : slo6 < 0 ? slo6 < nz(slo6[1]) ? -2 : -1 : 0
//////////////////////////////////////////////////////////
src7 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length7 = input.int(title='Length', defval=15, minval=1)
ma7 = ta.sma(src7, length7)
a7 = ta.linreg(src7, length7, 0)
m7 = a7 - nz(a7[1]) + ma7
ie27 = (m7 + a7) / 2
slo7 = src7 - ie27
sig7 = slo7 > 0 ? slo7 > nz(slo7[1]) ? 2 : 1 : slo7 < 0 ? slo7 < nz(slo7[1]) ? -2 : -1 : 0
//////////////////////////////////////////////////////////////////////////////////
src8 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length8 = input(title='Length', defval=14)
sum8 = 0.0
weightSum8 = 0.0
for i = 0 to length8 - 1 by 1
weight8 = math.pow(length8 - i, 3)
sum8 += src8[i] * weight8
weightSum8 += weight8
weightSum8
cwma8 = sum8 / weightSum8
sig8 = src8 > cwma8 ? 1 : src8 < cwma8 ? -1 : 0
////////////////////////////////////////////////////////////
src9 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length9 = input.int(title='Length', defval=15, minval=1)
pi9 = 2 * math.asin(1)
a9 = math.exp(-1.414 * pi9 / length9)
b9 = 2 * a9 * math.cos(1.414 * pi9 / length9)
c29 = b9
c39 = -a9 * a9
c19 = (1 - b9 + math.pow(a9, 2)) / 4
bf9 = 0.0
bf9 := bar_index < 3 ? src9 : c19 * (src9 + 2 * nz(src9[1]) + nz(src9[2])) + c29 * nz(bf9[1]) + c39 * nz(bf9[2])
sig9 = src9 > bf9 ? 1 : src9 < bf9 ? -1 : 0
///////////////////////////////////////////////////////
src10 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length10 = input.int(title='Length', defval=10, minval=1)
pi10 = 2 * math.asin(1)
a10 = math.exp(-1.414 * pi10 / length10)
b10 = 2 * a10 * math.cos(1.414 * 1.25 * pi10 / length10)
c210 = b10
c310 = -a10 * a10
c110 = 1 - c210 - c310
bf10 = 0.0
bf10 := c110 * src10 + c210 * nz(bf10[1]) + c310 * nz(bf10[2])
sig10 = src10 > bf10 ? 1 : src10 < bf10 ? -1 : 0
////////////////////////////////////////////////////////////////////////////////////
src11 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length11 = input.int(title='Length', defval=15, minval=1)
pi11 = 2 * math.asin(1)
a111 = math.exp(-1.414 * pi11 / length11)
b111 = 2 * a111 * math.cos(1.414 * pi11 / length11)
coef211 = b111
coef311 = -a111 * a111
coef111 = 1 - coef211 - coef311
ssf11 = 0.0
ssf11 := bar_index < 3 ? src11 : coef111 * src11 + coef211 * nz(ssf11[1]) + coef311 * nz(ssf11[2])
sig11 = src11 > ssf11 ? 1 : src11 < ssf11 ? -1 : 0
/////////////////////////////////////////////////////
src12 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length12 = input.int(title='Length', defval=10, minval=1)
pi12 = 2 * math.asin(1)
a12 = math.exp(-1.414 * pi12 / length12)
b12 = 2 * a12 * math.cos(1.414 * pi12 / length12)
c212 = b12
c312 = -a12 * a12
c112 = 1 - c212 - c312
ssf12 = 0.0
ssf12 := c112 * ((src12 + nz(src12[1])) / 2) + c212 * nz(ssf12[1]) + c312 * nz(ssf12[2])
sig12 = src12 > ssf12 ? 1 : src12 < ssf12 ? -1 : 0
/////////////////////////////////////////////////////
src13 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length13 = input.int(title='Length', defval=10, minval=1)
pi13 = 2 * math.asin(1)
a130 = math.exp(-pi13 / length13)
b130 = 2 * a130 * math.cos(1.738 * pi13 / length13)
c130 = a130 * a130
d213 = b130 + c130
d313 = -(c130 + b130 * c130)
d413 = c130 * c130
d113 = 1 - d213 - d313 - d413
bf13 = 0.0
bf13 := d113 * src13 + d213 * nz(bf13[1]) + d313 * nz(bf13[2]) + d413 * nz(bf13[3])
sig13 = src13 > bf13 ? 1 : src13 < bf13 ? -1 : 0
////////////////////////////////////////////////////////////////////////////////////
src14 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length14 = input.int(title='Length', defval=15, minval=1)
pi14 = 2 * math.asin(1)
a114 = math.exp(-pi14 / length14)
b114 = 2 * a114 * math.cos(1.738 * pi14 / length14)
c114 = a114 * a114
coef214 = b114 + c114
coef314 = -(c114 + b114 * c114)
coef414 = c114 * c114
coef114 = (1 - b114 + c114) * (1 - c114) / 8
bf14 = 0.0
bf14 := bar_index < 4 ? src14 : coef114 * (src14 + 3 * nz(src14[1]) + 3 * nz(src14[2]) + nz(src14[3])) + coef214 * nz(bf14[1]) + coef314 * nz(bf14[2]) + coef414 * nz(bf14[3])
sig14 = src14 > bf14 ? 1 : src14 < bf14 ? -1 : 0
///////////////////////////////////////
src15 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length15 = input.int(title='Length', defval=15, minval=1)
pi15 = 2 * math.asin(1)
a115 = math.exp(-pi15 / length15)
b115 = 2 * a115 * math.cos(1.738 * pi15 / length15)
c115 = a115 * a115
coef215 = b115 + c115
coef315 = -(c115 + b115 * c115)
coef415 = c115 * c115
coef115 = 1 - coef215 - coef315 - coef415
ssf15 = 0.0
ssf15 := bar_index < 4 ? src15 : coef115 * src15 + coef215 * nz(ssf15[1]) + coef315 * nz(ssf15[2]) + coef415 * nz(ssf15[3])
sig15 = src15 > ssf15 ? 1 : src15 < ssf15 ? -1 : 0
////////////////////////////////////////////
src16 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length16 = input.int(title='Length', defval=20, minval=1)
pi16 = 2 * math.asin(1)
twoPiPrd16 = 2 * pi16 / length16
alpha16 = (math.cos(twoPiPrd16) + math.sin(twoPiPrd16) - 1) / math.cos(twoPiPrd16)
dec16 = 0.0
dec16 := alpha16 / 2 * (src16 + nz(src16[1])) + (1 - alpha16) * nz(dec16[1])
sig16 = src16 > dec16 ? 1 : src16 < dec16 ? -1 : 0
////////////////////////////////////////////////////////////////////////////////////
length17 = input.int(title='Length', defval=15, minval=1)
src17 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
num17 = 0.0
coefSum17 = 0.0
for i = 0 to length17 - 1 by 1
distance17 = 0.0
for lb17 = 1 to length17 - 1 by 1
distance17 += math.pow(nz(src17[i]) - nz(src17[i + lb17]), 2)
distance17
num17 += distance17 * nz(src17[i])
coefSum17 += distance17
coefSum17
filt17 = coefSum17 != 0 ? num17 / coefSum17 : 0
sig17 = src17 > filt17 ? 1 : src17 < filt17 ? -1 : 0
///////////////////////////////
src18 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length18 = input.int(title="Length", defval=14, minval=1)
pedestal18 = input.float(title="Pedestal", defval=3, minval=0.01)
filt18 = 0.0, coef18 = 0.0
for i = 0 to length18 - 1
sine18 = math.sin(pedestal18 + (((math.pi - (2 * pedestal18)) * i) / (length18 - 1)))
filt18 := filt18 + (sine18 * nz(src18[i]))
coef18 := coef18 + sine18
filt18 := coef18 != 0 ? filt18 / coef18 : 0
slo18 = src18 - filt18
sig18 = slo18 > 0 ? slo18 > nz(slo18[1]) ? 2 : 1 : slo18 < 0 ? slo18 < nz(slo18[1]) ? -2 : -1 : 0
//////////////////////////////
src19 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length19 = input.int(title="Length", defval=14, minval=1)
filt19 = 0.0, coef19 = 0.0
for i = 1 to length19 by 1
cosine19 = 1 - math.cos(2 * math.pi * i / (length19 + 1))
filt19 += cosine19 * nz(src19[i - 1])
coef19 += cosine19
filt19 := coef19 != 0 ? filt19 / coef19 : 0
slo19 = src19 - filt19
sig19 = slo19 > 0 ? slo19 > nz(slo19[1]) ? 2 : 1 : slo19 < 0 ? slo19 < nz(slo19[1]) ? -2 : -1 : 0
/////////////////////////////////////
src20 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
pi20 = 2 * math.asin(1)
period20 = 0.0
smooth20 = (4 * src20 + 3 * nz(src20[1]) + 2 * nz(src20[2]) + nz(src20[3])) / 10
detrender20 = (0.0962 * smooth20 + 0.5769 * nz(smooth20[2]) - 0.5769 * nz(smooth20[4]) - 0.0962 * nz(smooth20[6])) * (0.075 * nz(period20[1]) + 0.54)
q120 = (0.0962 * detrender20 + 0.5769 * nz(detrender20[2]) - 0.5769 * nz(detrender20[4]) - 0.0962 * nz(detrender20[6])) * (0.075 * nz(period20[1]) + 0.54)
i120 = nz(detrender20[3])
jI20 = (0.0962 * i120 + 0.5769 * nz(i120[2]) - 0.5769 * nz(i120[4]) - 0.0962 * nz(i120[6])) * (0.075 * nz(period20[1]) + 0.54)
jQ20 = (0.0962 * q120 + 0.5769 * nz(q120[2]) - 0.5769 * nz(q120[4]) - 0.0962 * nz(q120[6])) * (0.075 * nz(period20[1]) + 0.54)
i220 = i120 - jQ20
i220 := 0.2 * i220 + 0.8 * nz(i220[1])
q220 = q120 + jI20
q220 := 0.2 * q220 + 0.8 * nz(q220[1])
re20 = i220 * nz(i220[1]) + q220 * nz(q220[1])
re20 := 0.2 * re20 + 0.8 * nz(re20[1])
im20= i220 * nz(q220[1]) - q220 * nz(i220[1])
im20 := 0.2 * im20 + 0.8 * nz(im20[1])
period20 := im20 != 0 and re20 != 0 ? 2 * pi20 / math.atan(im20 / re20) : 0
period20 := math.min(math.max(period20, 0.67 * nz(period20[1])), 1.5 * nz(period20[1]))
period20 := math.min(math.max(period20, 6), 50)
period20 := 0.2 * period20 + 0.8 * nz(period20[1])
smoothPeriod20 = 0.0
smoothPeriod20 := 0.33 * period20 + 0.67 * nz(smoothPeriod20[1])
dcPeriod20 = math.ceil(smoothPeriod20 + 0.5)
iTrend20 = 0.0
for i = 0 to dcPeriod20 - 1 by 1
iTrend20 += nz(src20[i])
iTrend20
iTrend20 := dcPeriod20 > 0 ? iTrend20 / dcPeriod20 : iTrend20
trendline20 = (4 * iTrend20 + 3 * nz(iTrend20[1]) + 2 * nz(iTrend20[2]) + nz(iTrend20[3])) / 10
sig20 = smooth20 > trendline20 ? 1 : smooth20 < trendline20 ? -1 : 0
///////////////////////////////////
src21 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
alpha21 = input.float(title='Alpha', defval=0.07, minval=0.01, step=0.01)
itrend21 = 0.0
itrend21 := bar_index < 7 ? (src21 + 2 * nz(src21[1]) + nz(src21[2])) / 4 : (alpha21 - math.pow(alpha21, 2) / 4) * src21 + 0.5 * math.pow(alpha21, 2) * nz(src21[1]) - (alpha21 - 0.75 * math.pow(alpha21, 2)) * nz(src21[2]) + 2 * (1 - alpha21) * nz(itrend21[1]) - math.pow(1 - alpha21, 2) * nz(itrend21[2])
trigger21 = 2 * itrend21 - nz(itrend21[2])
sig21 = trigger21 > itrend21 ? 1 : trigger21 < itrend21 ? -1 : 0
//////////////////////
src22 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length22 = input.int(title='Length', defval=20, minval=1)
deltaSum22 = 0.0
for int i = 0 to length22 - 1 by 1
deltaSum22 += math.abs(nz(src22[i]) - nz(src22[i + 1]))
ef22 = deltaSum22 != 0 ? math.min(math.abs(src22 - nz(src22[length22 - 1])) / deltaSum22, 1) : 0
s22 = math.pow((0.6667 * ef22) + 0.0645, 2)
kama22 = 0.0
kama22 := (s22 * src22) + ((1 - s22) * nz(kama22[1]))
slo22 = src22 - kama22
sig22 = slo22 > 0 ? slo22 > nz(slo22[1]) ? 2 : 1 : slo22 < 0 ? slo22 < nz(slo22[1]) ? -2 : -1 : 0
////////////////////////
src23 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
gamma23 = input.float(title='Gamma', defval=0.8, minval=0.01, step=0.01)
l023 = 0.0
l023 := (1 - gamma23) * src23 + gamma23 * nz(l023[1])
l123 = 0.0
l123 := -gamma23 * l023 + nz(l023[1]) + gamma23 * nz(l123[1])
l223 = 0.0
l223 := -gamma23 * l123 + nz(l123[1]) + gamma23 * nz(l223[1])
l323 = 0.0
l323 := -gamma23 * l223 + nz(l223[1]) + gamma23 * nz(l323[1])
filt23 = (l023 + 2 * l123 + 2 * l223 + l323) / 6
fir23 = (src23 + 2 * nz(src23[1]) + 2 * nz(src23[2]) + nz(src23[3])) / 6
sig23 = fir23 > filt23 ? 1 : fir23 < filt23 ? -1 : 0
/////////////////////////////////
src24 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
threshold24 = input.float(title='Threshold', defval=0.002, minval=0.0001, step=0.001)
length24 = input.int(title='Length', defval=39, minval=1)
smth24 = (src24 + (2 * nz(src24[1])) + (2 * nz(src24[2])) + nz(src24[3])) / 6
len24 = length24
v324 = 0.2, v224 = 0.0, alpha24 = 0.0
while (v324 > threshold24 and len24 > 0)
alpha24 := 2.0 / (len24 + 1)
v124 = ta.median(smth24, len24)
v224 := (alpha24 * smth24) + ((1 - alpha24) * nz(v224[1]))
v324 := v124 != 0 ? math.abs(v124 - v224) / v124 : v324
len24 -= 2
len24 := len24 < 3 ? 3 : len24
alpha24 := 2.0 / (len24 + 1)
filter24 = 0.0
filter24 := (alpha24 * smth24) + ((1 - alpha24) * nz(filter24[1]))
slo24 = src24 - filter24
sig24 = slo24 > 0 ? slo24 > nz(slo24[1]) ? 2 : 1 : slo24 < 0 ? slo24 < nz(slo24[1]) ? -2 : -1 : 0
///////////////////////////////
src25 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fastLimit25 = input.float(title='FastLimit', defval=0.5, minval=0.01, step=0.01)
slowLimit25 = input.float(title='SlowLimit', defval=0.05, minval=0.01, step=0.01)
pi25 = 2 * math.asin(1)
period25 = 0.0
smooth25 = (4 * src25 + 3 * nz(src25[1]) + 2 * nz(src25[2]) + nz(src25[3])) / 10
detrender25 = (0.0962 * smooth25 + 0.5769 * nz(smooth25[2]) - 0.5769 * nz(smooth25[4]) - 0.0962 * nz(smooth25[6])) * (0.075 * nz(period25[1]) + 0.54)
q125 = (0.0962 * detrender25 + 0.5769 * nz(detrender25[2]) - 0.5769 * nz(detrender25[4]) - 0.0962 * nz(detrender25[6])) * (0.075 * nz(period25[1]) + 0.54)
i125 = nz(detrender25[3])
jI25 = (0.0962 * i125 + 0.5769 * nz(i125[2]) - 0.5769 * nz(i125[4]) - 0.0962 * nz(i125[6])) * (0.075 * nz(period25[1]) + 0.54)
jQ25 = (0.0962 * q125 + 0.5769 * nz(q125[2]) - 0.5769 * nz(q125[4]) - 0.0962 * nz(q125[6])) * (0.075 * nz(period25[1]) + 0.54)
i225 = i125 - jQ25
i225 := 0.2 * i225 + 0.8 * nz(i225[1])
q225 = q125 + jI25
q225 := 0.2 * q225 + 0.8 * nz(q225[1])
re25 = i225 * nz(i225[1]) + q225 * nz(q225[1])
re25 := 0.2 * re25 + 0.8 * nz(re25[1])
im25 = i225 * nz(q225[1]) - q225 * nz(i225[1])
im25 := 0.2 * im25 + 0.8 * nz(im25[1])
period25 := im25 != 0 and re25 != 0 ? 2 * pi25 / math.atan(im25 / re25) : 0
period25 := math.min(math.max(period25, 0.67 * nz(period25[1])), 1.5 * nz(period25[1]))
period25 := math.min(math.max(period25, 6), 50)
period25 := 0.2 * period25 + 0.8 * nz(period25[1])
smoothPeriod25 = 0.0
smoothPeriod25 := 0.33 * period25 + 0.67 * nz(smoothPeriod25[1])
phase25 = i125 != 0 ? math.atan(q125 / i125) * 180 / pi25 : 0
deltaPhase25 = nz(phase25[1]) - phase25
deltaPhase25 := deltaPhase25 < 1 ? 1 : deltaPhase25
alpha25 = fastLimit25 / deltaPhase25
alpha25 := alpha25 < slowLimit25 ? slowLimit25 : alpha25
mama25 = 0.0
mama25 := alpha25 * src25 + (1 - alpha25) * nz(mama25[1])
fama25 = 0.0
fama25 := 0.5 * alpha25 * mama25 + (1 - 0.5 * alpha25) * nz(fama25[1])
sig25 = mama25 > fama25 ? 1 : mama25 < fama25 ? -1 : 0
//////////////////////////////////////
length26 = input.int(title='Length', defval=15, minval=1)
momLength26 = input.int(title='MomentumLength', defval=5, minval=1)
src26 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
num26 = 0.0
coefSum26 = 0.0
for i = 0 to length26 - 1 by 1
coef26 = math.abs(nz(src26[i]) - nz(src26[i + momLength26]))
num26 += coef26 * nz(src26[i])
coefSum26 += coef26
coefSum26
filt26 = coefSum26 != 0 ? num26 / coefSum26 : 0
sig26 = src26 > filt26 ? 1 : src26 < filt26 ? -1 : 0
//////////////////////////////////
src27 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
wma127 = (7 * src27 + 6 * nz(src27[1]) + 5 * nz(src27[2]) + 4 * nz(src27[3]) + 3 * nz(src27[4]) + 2 * nz(src27[5]) + nz(src27[6])) / 28
wma227 = (7 * wma127 + 6 * nz(wma127[1]) + 5 * nz(wma127[2]) + 4 * nz(wma127[3]) + 3 * nz(wma127[4]) + 2 * nz(wma127[5]) + nz(wma127[6])) / 28
predict27 = 2 * wma127 - wma227
trigger27 = (4 * predict27 + 3 * nz(predict27[1]) + 2 * nz(predict27[2]) + nz(predict27[3])) / 10
sig27 = predict27 > trigger27 ? 1 : predict27 < trigger27 ? -1 : 0
/////////////////////////////////////
src28 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length28 = input.int(title="Length", defval=14, minval=1)
filt28 = 0.0, coef28 = 0.0, l228 = length28 / 2.0
for i = 1 to length28
c28 = i < l228 ? i : i > l228 ? length28 + 1 - i : l228
filt28 := filt28 + (c28 * nz(src28[i - 1]))
coef28 := coef28 + c28
filt28 := coef28 != 0 ? filt28 / coef28 : 0
slo28 = src28 - filt28
sig28 = slo28 > 0 ? slo28 > nz(slo28[1]) ? 2 : 1 : slo28 < 0 ? slo28 < nz(slo28[1]) ? -2 : -1 : 0
//////////////////////////////////
src29 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
shortLength29 = input.int(title='ShortLength', defval=9, minval=1)
longLength29 = input.int(title='LongLength', defval=30, minval=1)
shortAvg29 = ta.wma(src29, shortLength29)
shortMa29 = math.sum(math.pow(src29 - shortAvg29, 2), shortLength29) / shortLength29
shortRms29 = shortMa29 > 0 ? math.sqrt(shortMa29) : 0
longAvg29 = ta.wma(src29, longLength29)
longMa29 = math.sum(math.pow(src29 - longAvg29, 2), longLength29) / longLength29
longRms29 = longMa29 > 0 ? math.sqrt(longMa29) : 0
kk29 = longRms29 != 0 ? 0.2 * shortRms29 / longRms29 : 0
vidya29 = 0.0
vidya29 := kk29 * src29 + (1 - kk29) * nz(vidya29[1])
slo29 = src29 - vidya29
sig29 = slo29 > 0 ? slo29 > nz(slo29[1]) ? 2 : 1 : slo29 < 0 ? slo29 < nz(slo29[1]) ? -2 : -1 : 0
////////////////////////////////////////
src31 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length31 = input(title='Length', defval=11)
offset31 = input(title='Offset', defval=4)
sum31 = 0.0
weightSum31 = 0.0
for i = 0 to length31 - 1 by 1
weight31 = length31 - i - offset31
sum31 += src31[i] * weight31
weightSum31 += weight31
weightSum31
epma31 = 1 / weightSum31 * sum31
sig31 = src31 > epma31 ? 1 : src31 < epma31 ? -1 : 0
//////////////////////////////////////////
src32 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length32 = input.int(title='Length', defval=14, minval=1)
jsa32 = (src32 + src32[length32]) / 2
sig32 = src32 > jsa32 ? 1 : src32 < jsa32 ? -1 : 0
/////////////////////////////
src33 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fastLength33 = input.int(title = "FastLength", defval = 14, minval = 1)
slowLength33 = input.int(title = "SlowLength", defval = 30, minval = 1)
leavittProjection(src33, length33) =>
result33 = ta.linreg(src33, length33, -1)
fastLp33 = leavittProjection(src33, fastLength33)
slowLp33 = leavittProjection(src33, slowLength33)
slo33 = fastLp33 - slowLp33
sig33 = slo33 > 0 ? slo33 > nz(slo33[1]) ? 2 : 1 : slo33 < 0 ? slo33 < nz(slo33[1]) ? -2 : -1 : 0
//////////////////////////////////
src34 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length34 = input(title='Length', defval=5)
k34 = input.float(title='K Constant', step=0.1, defval=0.6)
mdi34 = 0.0
mdi34 := na(mdi34[1]) ? src34 : nz(mdi34[1]) + (src34 - nz(mdi34[1])) / math.max(k34 * length34 * math.pow(src34 / nz(mdi34[1]), 4), 1)
sig34 = src34 > mdi34 ? 1 : src34 < mdi34 ? -1 : 0
////////////////////////////////////////////
src35 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length35 = input.int(title='Length', defval=10, minval=1)
fastLength35 = input.int(title='FastLength', defval=2, minval=1)
slowLength35 = input.int(title='SlowLength', defval=30, minval=1)
// first half uses the same formula as the kaufman adaptive moving average
diff35 = math.abs(src35 - nz(src35[1]))
signal35 = math.abs(src35 - nz(src35[length35]))
noise35 = math.sum(diff35, length35)
ratio35 = noise35 != 0 ? signal35 / noise35 : 0
// this is where it differs from the kaufman adaptive moving average
fastSc35 = 2 / (fastLength35 + 1)
slowSc35 = 2 / (slowLength35 + 1)
temp35 = ratio35 * fastSc35 + slowSc35
maaq35 = 0.0
prevMaaq35 = nz(maaq35[1], src35)
maaq35 := prevMaaq35 + math.pow(temp35, 2) * (src35 - prevMaaq35)
sig35 = src35 > maaq35 ? 1 : src35 < maaq35 ? -1 : 0
///////////////////////////////
src36 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fac36 = input.float(title='Factor', defval=0.2, minval=0.01)
val236 = 2 / fac36 - 1
factor36 = 2 / (val236 + 1)
mwdx36 = 0.0
mwdx36 := factor36 * src36 + (1 - factor36) * nz(mwdx36[1], src36)
sig36 = src36 > mwdx36 ? 1 : src36 < mwdx36 ? -1 : 0
////////////////////////
src37 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
fastLength37 = input.int(title='FastLength', defval=10, minval=1)
slowLength37 = input.int(title='SlowLength', defval=50, minval=1)
mult37 = input.int(title='Multiple', defval=1, minval=1)
fastEma37 = ta.ema(src37, fastLength37)
slowEma37 = ta.ema(src37, slowLength37)
sqAvg37 = math.sum(math.pow(slowEma37 - fastEma37, 2), fastLength37) / fastLength37
dev37 = math.sqrt(sqAvg37) * mult37
upperBand37 = slowEma37 + dev37
lowerBand37 = slowEma37 - dev37
middleBand37 = fastEma37
sig37 = src37 > upperBand37 and nz(src37[1]) <= nz(upperBand37[1]) or src37 > lowerBand37 and nz(src37[1]) <= nz(lowerBand37[1]) ? 1 : src37 < lowerBand37 and nz(src37[1]) >= nz(lowerBand37[1]) or src37 < upperBand37 and nz(src37[1]) >= nz(upperBand37[1]) ? -1 : src37 > middleBand37 ? 1 : src37 < middleBand37 ? -1 : 0
//////////////////////////////////
src38 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length38 = input(title='Length', defval=14)
sum38 = 0.0
weightSum38 = 0.0
owma38 = 0.0
for i = 0 to length38 - 1 by 1
corr38 = ta.correlation(src38, owma38, length38)
weight38 = math.pow(length38 - i, corr38)
sum38 += src38[i] * weight38
weightSum38 += weight38
weightSum38
owma38 := sum38/ weightSum38
sig38 = src38 > owma38 ? 1 : src38 < owma38 ? -1 : 0
/////////////////////////////////
src39 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
minLength39 = input.int(title='MinLength', defval=5, minval=1)
maxLength39 = input.int(title='MaxLength', defval=50, minval=1)
mean39 = ta.sma(src39, maxLength39)
stdDev39 = ta.stdev(src39, maxLength39)
a39 = mean39 - 1.75 * stdDev39
b39 = mean39 - 0.25 * stdDev39
c390 = mean39 + 0.25 * stdDev39
d39 = mean39 + 1.75 * stdDev39
length39 = 0.0
length39 := src39 >= b39 and src39 <= c390 ? nz(length39[1], maxLength39) + 1 : src39 < a39 or src39 > d39 ? nz(length39[1], maxLength39) - 1 : nz(length39[1], maxLength39)
length39 := math.max(math.min(length39, maxLength39), minLength39)
sc39 = 2 / (length39 + 1)
vlma39 = 0.0
vlma39 := src39 * sc39 + (1 - sc39) * nz(vlma39[1], src39)
sig39 = src39 > vlma39 ? 1 : src39 < vlma39 ? -1 : 0
//////////////////////////////
src41 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length41 = input(title='Length', defval=14)
p41 = input.float(title='Power', minval=0, defval=1.0)
sum41 = 0.0
weightSum41 = 0.0
for i = 0 to length41 - 1 by 1
weight41 = math.pow(length41 - i, p41)
sum41 += src41[i] * weight41
weightSum41 += weight41
weightSum41
vpwma41 = sum41 / weightSum41
sig41 = src41 > vpwma41 ? 1 : src41 < vpwma41 ? -1 : 0
/////////////////////////////
src42 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length42 = input(title='Length', defval=14)
sum42 = 0.0
weightSum42 = 0.0
for i = 0 to length42 - 1 by 1
weight42 = math.pow(length42 - i, 2)
sum42 += src42[i] * weight42
weightSum42 += weight42
weightSum42
swma42 = sum42 / weightSum42
sig42 = src42 > swma42 ? 1 : src42 < swma42 ? -1 : 0
//////////////////////////
src43 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length43 = input(title='Length', defval=14)
sum43 = 0.0
weightSum43 = 0.0
for i = 0 to length43 - 1 by 1
weight43 = math.pow(length43 - i, 0.5)
sum43 += src43[i] * weight43
weightSum43 += weight43
weightSum43
srwma43 = sum43 / weightSum43
sig43 = src43 > srwma43 ? 1 : src43 < srwma43 ? -1 : 0
////////////////////////
src44 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length44 = input.int(title='Length', defval=20, minval=1)
middleBandLength44 = input.int(title='MiddleBandLength', defval=21, minval=1)
bandsDeviation44 = input.float(title='BandsDeviation', defval=2.4, minval=0.1)
lowBandAdjust44 = input.float(title='LowBandAdjust', defval=0.9, minval=0.1)
atrPeriod44 = length44 * 2 - 1
atrBuf44 = ta.atr(atrPeriod44) * bandsDeviation44
ma44 = ta.ema(src44, length44)
upperBand44 = ma44 + ma44 * atrBuf44 / src44
middleBand44 = ta.ema(src44, middleBandLength44)
lowerBand44 = ma44- ma44 * atrBuf44 * lowBandAdjust44 / src44
sig44 = src44 > upperBand44 and nz(src44[1]) <= nz(upperBand44[1]) or src44 > lowerBand44 and nz(src44[1]) <= nz(lowerBand44[1]) or src44 > middleBand44 ? 1 : src44 < lowerBand44 and nz(src44[1]) >= nz(lowerBand44[1]) or src44 < upperBand44 and nz(src44[1]) >= nz(upperBand44[1]) or src44 < middleBand44 ? -1 : 0
//////////////////////
src45 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length45 = input.int(title='Length', defval=50, minval=2)
mult45 = input.float(title='Mult', defval=10.0, minval=0.01)
alpha45 = 2.0 / (length45 + 1)
mom45 = src45 - nz(src45[1])
up45 = mom45 > 0 ? mom45 : 0
dn45 = mom45 < 0 ? math.abs(mom45) : 0
upMa45 = ta.ema(up45, length45)
dnMa45 = ta.ema(dn45, length45)
rs45 = upMa45 + dnMa45 != 0 ? math.abs(upMa45 - dnMa45) / (upMa45 + dnMa45) : 0
rsEma45 = 0.0
rsEma45 := nz(rsEma45[1]) + (alpha45 * (1 + (rs45 * mult45)) * (src45 - nz(rsEma45[1])))
slo45 = src45 - rsEma45
sig45 = slo45 > 0 ? slo45 > nz(slo45[1]) ? 2 : 1 : slo45 < 0 ? slo45 < nz(slo45[1]) ? -2 : -1 : 0
//////////////////////
volSym46 = input.symbol(title='Volatility Symbol', defval='VIX')
src46 = request.security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
volSrc46 = request.security(volSym46, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
length46 = input.int(title='Length', defval=10, minval=1)
maLength46 = input.int(title='MaLength', defval=10, minval=1)
mult46 = input.float(title='Mult', defval=10.0, minval=.01)
alpha46 = 2.0 / (length46 + 1)
mom46 = src46 - nz(src46[1])
pv46 = mom46> 0 ? volSrc46 : 0
nv46 = mom46 < 0 ? volSrc46 : 0
pvMa46 = ta.ema(pv46, maLength46)
nvMa46 = ta.ema(nv46, maLength46)
rs46 = pvMa46 + nvMa46 != 0 ? math.abs(pvMa46 - nvMa46) / (pvMa46 + nvMa46) : 0
rsvaEma46 = 0.0
rsvaEma46 := nz(rsvaEma46[1]) + (alpha46 * (1 + (rs46 * mult46)) * (src46 - nz(rsvaEma46[1])))
slo46 = src46 - rsvaEma46
sig46 = slo46 > 0 ? slo46 > nz(slo46[1]) ? 2 : 1 : slo46 < 0 ? slo46 < nz(slo46[1]) ? -2 : -1 : 0
/////////////////////////////////
float inp55 = input(title = 'Source', defval = close)
string res55 = input.timeframe(title = 'Resolution', defval = '')
bool rep55 = input(title = 'Allow Repainting?', defval = false)
float src47 = request.security(syminfo.tickerid, res55, inp55[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
int length47 = input.int(title = 'Length', defval = 40, minval = 2)
float mult47 = input.float(title = 'Mult', defval = 10.0, minval = 0.01)
float alpha47 = 2.0 / (length47 + 1)
float trL47 = ta.lowest(ta.tr, length47)
float trH47 = ta.highest(ta.tr, length47)
float trAdj47 = trH47 - trL47 != 0 ? (ta.tr - trL47) / (trH47 - trL47) : 0
float trAdjEma47 = 0.0
trAdjEma47 := nz(trAdjEma47[1]) + (alpha47 * (1 + (trAdj47 * mult47)) * (src47 - nz(trAdjEma47[1])))
float slo47 = src47 - trAdjEma47
int sig47 = slo47 > 0 ? slo47 > nz(slo47[1]) ? 2 : 1 : slo47 < 0 ? slo47 < nz(slo47[1]) ? -2 : -1 : 0
/////////////////////////////////
float src49 = request.security(syminfo.tickerid, res55, inp55[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
float tr49 = request.security(syminfo.tickerid, res55, ta.tr[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
int length49 = input.int(title = 'Length', defval = 30, minval = 2)
float hhC49 = ta.highest(src49, length49)
float llC49 = ta.lowest(src49, length49)
float result49 = hhC49 - llC49
float effort49 = math.sum(tr49, length49)
float alpha49 = effort49 != 0 ? result49 / effort49 : 0
float nama49 = 0.0
nama49 := (alpha49 * src49) + ((1 - alpha49) * nz(nama49[1]))
float slo49 = src49 - nama49
int sig49 = slo49 > 0 ? slo49 > nz(slo49[1]) ? 2 : 1 : slo49 < 0 ? slo49 < nz(slo49[1]) ? -2 : -1 : 0
//////////////////////////////////////
float src50 = request.security(syminfo.tickerid, res55, inp55[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
float tr50 = request.security(syminfo.tickerid, res55, ta.tr[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
int length50 = input.int(title = 'Length', defval = 30, minval = 2)
float result50 = math.abs(src50 - nz(src50[length50]))
float effort50 = math.sum(tr50, length50)
float alpha50 = effort50 != 0 ? result50 / effort50 : 0
float anama50 = 0.0
anama50 := (alpha50 * src50) + ((1 - alpha50) * nz(anama50[1]))
float slo50 = src50 - anama50
int sig50 = slo50 > 0 ? slo50 > nz(slo50[1]) ? 2 : 1 : slo50 < 0 ? slo50 < nz(slo50[1]) ? -2 : -1 : 0
/////////////////////////////////////////////////////////
float src51 = request.security(syminfo.ticker, res55, inp55[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
int fastLength51 = input.int(title = 'FastLength', defval = 6, minval = 1)
int slowLength51 = input.int(title = 'SlowLength', defval = 12, minval = 1)
int sampleLength51 = input.int(title = 'SampleLength', defval = 5, minval = 1)
hannFilter51(float sampleSrc51, int length51) =>
filt51 = 0.0, coef51 = 0.0
for i = 1 to length51
cosine51 = 1 - math.cos(2 * math.pi * i / (length51 + 1))
filt51 := filt51 + (cosine51 * nz(sampleSrc51[i - 1]))
coef51 := coef51 + cosine51
filt51 := coef51 != 0 ? filt51 / coef51 : 0
float sample51 = 0.0
sample51 := bar_index % sampleLength51 == 0 ? src51 : nz(sample51[1])
float fastAvg51 = hannFilter51(sample51, fastLength51)
float slowAvg51 = hannFilter51(sample51, slowLength51)
float slo51 = fastAvg51 - slowAvg51
int sig51 = slo51 > 0 ? slo51 > nz(slo51[1]) ? 2 : 1 : slo51 < 0 ? slo51 < nz(slo51[1]) ? -2 : -1 : 0
//////////////////////////////////
float src52 = request.security(syminfo.tickerid, res55, inp55[rep55 ? 0 : barstate.isrealtime ? 1 : 0])[rep55 ? 0 : barstate.isrealtime ? 0 : 1]
fastLength52 = input.int(title = "FastLength", defval = 14, minval = 1)
slowLength52 = input.int(title = "SlowLength", defval = 30, minval = 1)
leavittProjection52(float src52, int length52) =>
float result52 = ta.linreg(src52, length52, -1)
leavittConvolution52(float src52, int length52) =>
int sqrtLength52 = math.floor(nz(math.sqrt(length52)))
float result52 = ta.linreg(leavittProjection52(src52, length52), sqrtLength52, -1)
float fastConv52 = leavittConvolution52(src52, fastLength52)
float slowConv52 = leavittConvolution52(src52, slowLength52)
float slo52 = fastConv52 - slowConv52
int sig52 = slo52 > 0 ? slo52 > nz(slo52[1]) ? 2 : 1 : slo52 < 0 ? slo52 < nz(slo52[1]) ? -2 : -1 : 0
/////////////////////////////////////////////////////////////////////////
f_security(_symbol66, _res66, _src66, _repaint66) =>
request.security(_symbol66, _res66, _src66[_repaint66 ? 0 : barstate.isrealtime ? 1 : 0])[_repaint66 ? 0 : barstate.isrealtime ? 0 : 1]
res66 = input.timeframe(title='Resolution', defval='')
rep66 = input(title='Allow Repainting?', defval=false)
length53 = input.int(title='Length', defval=14, minval=1)
factor53 = input.int(title='Factor', defval=2, minval=1)
p53 = f_security(syminfo.tickerid, res66, hl2, rep66)
h53 = f_security(syminfo.tickerid, res66, high, rep66)
l53 = f_security(syminfo.tickerid, res66, low, rep66)
t53 = f_security(syminfo.tickerid, res66, ta.tr, rep66)
mpEma53 = ta.ema(p53, length53)
trEma53 = ta.ema(t53, length53)
stdDev53 = ta.stdev(trEma53, length53)
ad53 = p53 > nz(p53[1]) ? mpEma53 + trEma53 / 2 : p53 < nz(p53[1]) ? mpEma53 - trEma53 / 2 : mpEma53
adm53 = ta.ema(ad53, length53)
trndDn53 = 0.0
trndDn53 := ta.crossunder(adm53, mpEma53) ? h53[2] : p53 < nz(p53[1]) ? p53 + stdDev53 * factor53 : nz(trndDn53[1], h53[2])
trndUp53 = 0.0
trndUp53 := ta.crossover(adm53, mpEma53) ? l53[2] : p53 > nz(p53[1]) ? p53 - stdDev53 * factor53 : nz(trndUp53[1], l53[2])
trndr53 = 0.0
trndr53 := adm53 < mpEma53 ? trndDn53 : adm53 > mpEma53 ? trndUp53 : nz(trndr53[1], 0)
sig53 = p53 > trndr53 ? 1 : p53 < trndr53 ? -1 : 0
/////////////////////////////////////////
c54 = f_security(syminfo.tickerid, res66, close, rep66)
v54 = f_security(syminfo.tickerid, res66, volume, rep66)
length54 = input.int(title='Length', defval=50, minval=2)
mult54 = input.float(title='Mult', defval=10.0, minval=0.01)
alpha54 = 2.0 / (length54 + 1)
mom54 = c54 - nz(c54[1])
pv54 = mom54 > 0 ? v54 : 0
nv54 = mom54 < 0 ? v54 : 0
pvMa54 = ta.ema(pv54, length54)
nvMa54 = ta.ema(nv54, length54)
vs54 = pvMa54 + nvMa54 != 0 ? math.abs(pvMa54 - nvMa54) / (pvMa54 + nvMa54) : 0
rsvaEma54 = 0.0
rsvaEma54 := nz(rsvaEma54[1]) + (alpha54 * (1 + (vs54 * mult54)) * (c54 - nz(rsvaEma54[1])))
slo54 = c54 - rsvaEma54
sig54 = slo54 > 0 ? slo54 > nz(slo54[1]) ? 2 : 1 : slo54 < 0 ? slo54 < nz(slo54[1]) ? -2 : -1 : 0
////////////////////////////////////
length56 = input.int(title='Length', defval=25, minval=1)
h56 = f_security(syminfo.tickerid, res66, high, rep66)
l56 = f_security(syminfo.tickerid, res66, low, rep66)
c56 = f_security(syminfo.tickerid, res66, close, rep66)
hh56 = ta.highest(h56, length56)
ll56 = ta.lowest(l56, length56)
atr56 = ta.atr(length56)
mult56 = math.sqrt(length56)
dSup56 = hh56 - atr56 * mult56
dRes56 = ll56 + atr56 * mult56
dMid56 = (dSup56 + dRes56) / 2
sig56 = c56 > dMid56 ? 1 : c56 < dMid56 ? -1 : 0
///////////////////////////////
length57 = input.int(title='Length', defval=3, minval=1)
h57 = f_security(syminfo.tickerid, res66, high, rep66)
l57 = f_security(syminfo.tickerid, res66, low, rep66)
c57 = f_security(syminfo.tickerid, res66, close, rep66)
highMa57 = ta.sma(h57, length57)
lowMa57 = ta.sma(l57, length57)
ghla57 = 0.0
ghla57 := c57 > nz(highMa57[1]) ? lowMa57 : c57 < nz(lowMa57[1]) ? highMa57 : nz(ghla57[1])
sig57 = c57 > ghla57 ? 1 : c57 < ghla57 ? -1 : 0
//////////////////////////////////
lbLength58 = input.int(title='LookBackLength', defval=21, minval=1)
p58 = f_security(syminfo.tickerid, res66, close, rep66)
h58 = f_security(syminfo.tickerid, res66, high, rep66)
l58 = f_security(syminfo.tickerid, res66, low, rep66)
ll58 = ta.lowest(lbLength58)
hh58 = ta.highest(lbLength58)
hCount58 = 0
lCount58 = 0
cbl58 = p58
for i = 0 to lbLength58 by 1
if l58[i] == ll58
for j58 = i + 1 to i + lbLength58 by 1
lCount58 += (h58[j58] > h58[i] ? 1 : 0)
if lCount58 == 2
cbl58 := h58[j58]
break
if h58[i] == hh58
for j58 = i + 1 to i + lbLength58 by 1
hCount58 += (l58[j58] < l58[i] ? 1 : 0)
if hCount58 == 2
cbl58 := l58[j58]
break
sig58 = p58 > cbl58 ? 1 : p58 < cbl58 ? -1 : 0
//////////////////////////////
inp59 = input(title='Source', defval=close)
h59 = f_security(syminfo.tickerid, res66, high, rep66)
l59 = f_security(syminfo.tickerid, res66, low, rep66)
c59 = f_security(syminfo.tickerid, res66, inp59, rep66)
length59 = input.int(title='Length', defval=14, minval=1)
mHigh59 = ta.linreg(h59, length59, 0) - ta.linreg(h59, length59, 1)
mLow59 = ta.linreg(l59, length59, 0) - ta.linreg(l59, length59, 1)
upperBand59 = h59, lowerBand59 = l59
for i = 0 to length59 - 1
currH59 = nz(h59[i])
prevH59 = nz(h59[i - 1])
currL59 = nz(l59[i])
prevL59 = nz(l59[i - 1])
vHigh59 = currH59 + (nz(mHigh59[i]) * i)
vLow59 = currL59 + (nz(mLow59[i]) * i)
upperBand59 := math.max(vHigh59, upperBand59)
lowerBand59 := math.min(vLow59, lowerBand59)
middleBand59 = (upperBand59 + 59) / 2
slo59 = c59 - middleBand59
sig59 = (c59 > upperBand59 and nz(c59[1]) <= nz(upperBand59[1])) or (c59 > lowerBand59 and nz(c59[1]) <= nz(lowerBand59[1]))
? 1 : (c59 < lowerBand59 and nz(c59[1]) >= nz(lowerBand59[1])) or (c59 < upperBand59 and nz(c59[1]) >= nz(upperBand59[1]))
? -1 : slo59 > 0 ? slo59 > nz(slo59[1]) ? 2 : 1 : slo59 < 0 ? slo59 < nz(slo59[1]) ? -2 : -1 : 0
///////////////////////////////////
length61 = input.int(title='Length', defval=25, minval=1)
h61 = f_security(syminfo.tickerid, res66, high, rep66)
l61 = f_security(syminfo.tickerid, res66, low, rep66)
c61 = f_security(syminfo.tickerid, res66, close, rep66)
hh61 = ta.highest(h61, length61)
ll61 = ta.lowest(l61, length61)
range_161 = hh61 - ll61
sup161 = ll61 - 0.25 * range_161
sup261 = ll61 - 0.5 * range_161
res161 = hh61 + 0.25 * range_161
res261 = hh61 + 0.5 * range_161
mid61 = (sup161 + sup261 + res161 + res261) / 4
sig61 = c61 > mid61 ? 1 : c61 < mid61 ? -1 : 0
her turuncu slashların arası.....kod hesaplamaları içerir....
istediğinizi plotlar.....ortalama alırsınız....
ham yayınlama sebebi şu an test aşamassında....
https://www.tradingview.com/x/elg0IBRp/
https://www.tradingview.com/x/dtCqxguO/
https://www.tradingview.com/x/nvba5IUR/
https://www.tradingview.com/x/7FLSOPWx/
testler bitince...tradingwiev de... paylaşılacak.....
zaman analizi trendi....
1-3-5-15-30-45-60 lık periyotları okur....
saatlik periyodun kapanışını esas alarak...
zamanlara iki ortalama alır....
biri 1-3-5-15 hesaplar zaman 0 olan
diğeri 1-3-5-15-30-45-60 hesaplar... zaman1 olan
sonuç görüntü...
https://www.tradingview.com/x/q7RWQxIa/
https://www.tradingview.com/x/HBOWp3KI/
https://www.tradingview.com/x/oHB7GKFF/
https://www.tradingview.com/x/JXBqMtK6/
vurkaç için tasarlanacaksa...
tek çizgi...
1-3 dak periyodu oku....15 lik kapanışa kıyasla....
çizgiyi çekinçe.....
https://www.tradingview.com/x/yvxp7UTq/
https://www.tradingview.com/x/Apddmsoa/
https://www.tradingview.com/x/HwEMCcZd/
15lik kıyaslanan periyot....https://www.tradingview.com/x/x43m9V00/
yandaki rakamlar ise periyotlar oluyor....
böylece hangi periyodun....destek ve direncini görmüş oluyoruz.....
gann kodu....
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ThiagoSchmitz
//@version=5
indicator("Gann Square of 144", overlay=true, max_lines_count=50, max_labels_count=50)
// *****************************************************************************
// ********************************* Constants *********************************
// *****************************************************************************
string groupInlineXYLabels = "X-Axis and Y-Axis Labels"
string groupInlineExtraLines = "Extra Lines"
string groupInlineColors = "colors"
string groupInlineSquare = "squarecolors"
int squares = 144
int barIndex = bar_index
float barHigh = high
float barLow = low
string lineDashed = line.style_dashed
string lineDotted = line.style_dotted
string lineSolid = line.style_solid
string lineNone = label.style_none
bool barstateIsNew = barstate.isnew
bool barstateIsLast = barstate.islast
color colorRed = color.red
color colorWhite = color.white
// *****************************************************************************
// ********************************* Inputs ************************************
// *****************************************************************************
var int startDate = input.time(timestamp("2022-11-01"), "Starting Date")
var float maxPrice = input.float(69198.0, "Manual Max Price")
var float minPrice = input.float(17595.0, "Manual Min Price")
var bool autoPricesAndBar = input.bool(true, "Set Upper/Lower Prices and Start Bar Automatically")
var bool updateNewBar = input.bool(true, "Update at new bar")
var int candlesPerDivision = input.int(1, "Candles per division", minval=1)
var bool showTopXAxis = input.bool(false, "Top X-Axis", inline=groupInlineXYLabels, group=groupInlineXYLabels)
var bool showBottomXAxis = input.bool(false, "Bottom X-Axis", inline=groupInlineXYLabels, group=groupInlineXYLabels)
var bool showLeftYAxis = input.bool(false, "Left Y-Axis", inline=groupInlineXYLabels, group=groupInlineXYLabels)
var bool showRightYAxis = input.bool(false, "Right Y-Axis", inline=groupInlineXYLabels, group=groupInlineXYLabels)
var bool showPrices = input.bool(false, "Show Prices on the Right Y-Axis", inline=groupInlineXYLabels, group=groupInlineXYLabels)
var bool showDivisions = input.bool(false, "Show Vertical Divisions", inline=groupInlineExtraLines, group=groupInlineExtraLines)
var bool showExtraLines = input.bool(false, "Show Extra Lines", inline=groupInlineExtraLines, group=groupInlineExtraLines)
var bool showGrid = input.bool(false, "Show Grid", inline=groupInlineExtraLines, group=groupInlineExtraLines)
var bool showBackground = input.bool(true, "Show Background", inline=groupInlineExtraLines, group=groupInlineExtraLines)
var string patterns = input.string("Arrow", "Line Patterns", options=["None", "Arrow", "Star", "36, 72, and 108", "Arrow Cross", "Corners and Cross", "Master"], group="patterns")
var color labelColor = input.color(color.green, "Numbers Color", inline=groupInlineColors, group=groupInlineColors)
var color divisionsColor = input.color(color.blue, "Vertical Lines Color", inline=groupInlineColors, group=groupInlineColors)
var color gridColor = input.color(color.gray, "Grid Color", inline=groupInlineColors, group=groupInlineColors)
var color TLSColor = input.color(color.new(color.green, 80), "Top Left Square Color", inline=groupInlineSquare, group=groupInlineSquare)
var color TMSColor = input.color(color.new(color.red, 80), "Top Middle Square Color", inline=groupInlineSquare, group=groupInlineSquare)
var color TRSColor = input.color(color.new(color.green, 80), "Top Right Square Color", inline=groupInlineSquare, group=groupInlineSquare)
var color CLSColor = input.color(color.new(color.green, 80), "Center Left Square Color", inline=groupInlineSquare, group=groupInlineSquare)
var color CMSColor = input.color(color.new(color.red, 80), "Center Middle Square Color", inline=groupInlineSquare, group=groupInlineSquare)
var color CRSColor = input.color(color.new(color.green, 80), "Center Right Square Color", inline=groupInlineSquare, group=groupInlineSquare)
var color BLSColor = input.color(color.new(color.green, 80), "Bottom Left Square Color", inline=groupInlineSquare, group=groupInlineSquare)
var color BMSColor = input.color(color.new(color.red, 80), "Bottom Middle Square Color", inline=groupInlineSquare, group=groupInlineSquare)
var color BRSColor = input.color(color.new(color.green, 80), "Bottom Right Square Color", inline=groupInlineSquare, group=groupInlineSquare)
var int dateBarIndex = 0
if time == startDate
dateBarIndex := barIndex
// *****************************************************************************
// ******************************** Variables **********************************
// *****************************************************************************
int startBarIndex = autoPricesAndBar ? barIndex - math.floor(squares * candlesPerDivision / 2) : dateBarIndex
int endBarIndex = startBarIndex + squares * candlesPerDivision
int middleBarIndex = startBarIndex + squares * candlesPerDivision / 2
int onethirdPriceBar = (endBarIndex - startBarIndex) / 3
int barDiff = squares - math.abs(endBarIndex - barIndex)
int barIndexDiff = barDiff <= 0 ? 1 : barDiff
float atr = ta.atr(5)
float highest = ta.highest(math.floor(squares * candlesPerDivision / 2) + 1)
float lowest = ta.lowest(math.floor(squares * candlesPerDivision/ 2) + 1)
float lowerPrice = autoPricesAndBar ? lowest : minPrice
float upperPrice = autoPricesAndBar ? highest : maxPrice
float middlePrice = lowerPrice + (upperPrice - lowerPrice) / 2
float onethirdPrice = (upperPrice - lowerPrice) / 3
// *****************************************************************************
// *************************** One-Time Variables ******************************
// *****************************************************************************
var box squareLines = box.new(barIndex, barHigh, barIndex, barLow, color.new(colorWhite, 50), 2, bgcolor=na)
var bool buildSquareDone = false
var bool buildInputsDone = false
var bool[] dashedLineStyles = array.new_bool()
var bool[] extendLines = array.new_bool()
var bool[] showGroup = array.new_bool()
var color[] lineColors = array.new_color()
var label[] bottomXAxisArray = array.new_label()
var label[] leftYAxisArray = array.new_label()
var label[] rightYAxisArray = array.new_label()
var label[] topXAxisArray = array.new_label()
var line[] BLRArray = array.new_line()
var line[] BLTArray = array.new_line()
var line[] BRLArray = array.new_line()
var line[] BRTArray = array.new_line()
var line[] TLBArray = array.new_line()
var line[] TLRArray = array.new_line()
var line[] TRBArray = array.new_line()
var line[] TRLArray = array.new_line()
var line[] divisionsArray = array.new_line()
var line[] extraArray = array.new_line()
var line[] gridArray = array.new_line()
var box back1Square = box.new(barIndex, barHigh, barIndex, barLow, na, 0, bgcolor=TLSColor)
var box back2Square = box.new(barIndex, barHigh, barIndex, barLow, na, 0, bgcolor=TMSColor)
var box back3Square = box.new(barIndex, barHigh, barIndex, barLow, na, 0, bgcolor=TRSColor)
var box back4Square = box.new(barIndex, barHigh, barIndex, barLow, na, 0, bgcolor=CLSColor)
var box back5Square = box.new(barIndex, barHigh, barIndex, barLow, na, 0, bgcolor=CMSColor)
var box back6Square = box.new(barIndex, barHigh, barIndex, barLow, na, 0, bgcolor=CRSColor)
var box back7Square = box.new(barIndex, barHigh, barIndex, barLow, na, 0, bgcolor=BLSColor)
var box back8Square = box.new(barIndex, barHigh, barIndex, barLow, na, 0, bgcolor=BMSColor)
var box back9Square = box.new(barIndex, barHigh, barIndex, barLow, na, 0, bgcolor=BRSColor)
// *****************************************************************************
// ******************************** Fucntions **********************************
// *****************************************************************************
// =============================================================================
// * This function will update the box that goes on the edge of the Gann's
// * square
// =============================================================================
updateBox() =>
box.set_left(squareLines, startBarIndex)
box.set_top(squareLines, upperPrice)
box.set_right(squareLines, endBarIndex)
box.set_bottom(squareLines, lowerPrice)
// =============================================================================
// * This function will update the background of the Gann's square
// =============================================================================
updateBackgrounds() =>
s1 = startBarIndex
s2 = startBarIndex + ((squares / 3) * candlesPerDivision)
s3 = startBarIndex + ((squares / 3) * 2 * candlesPerDivision)
s4 = endBarIndex
t1 = upperPrice
t2 = upperPrice - ((upperPrice - lowerPrice) / 3)
t3 = upperPrice - ((upperPrice - lowerPrice) / 3) * 2
t4 = lowerPrice
box.set_left(back1Square, s1)
box.set_right(back1Square, s2)
box.set_top(back1Square, t1)
box.set_bottom(back1Square, t2)
box.set_left(back2Square, s2)
box.set_right(back2Square, s3)
box.set_top(back2Square, t1)
box.set_bottom(back2Square, t2)
box.set_left(back3Square, s3)
box.set_right(back3Square, s4)
box.set_top(back3Square, t1)
box.set_bottom(back3Square, t2)
box.set_left(back4Square, s1)
box.set_right(back4Square, s2)
box.set_top(back4Square, t2)
box.set_bottom(back4Square, t3)
box.set_left(back5Square, s2)
box.set_right(back5Square, s3)
box.set_top(back5Square, t2)
box.set_bottom(back5Square, t3)
box.set_left(back6Square, s3)
box.set_right(back6Square, s4)
box.set_top(back6Square, t2)
box.set_bottom(back6Square, t3)
box.set_left(back7Square, s1)
box.set_right(back7Square, s2)
box.set_top(back7Square, t3)
box.set_bottom(back7Square, t4)
box.set_left(back8Square, s2)
box.set_right(back8Square, s3)
box.set_top(back8Square, t3)
box.set_bottom(back8Square, t4)
box.set_left(back9Square, s3)
box.set_right(back9Square, s4)
box.set_top(back9Square, t3)
box.set_bottom(back9Square, t4)
// =============================================================================
// * Build both X-Axis and y-Axis labels
// * It will use the topXAxisArray, bottomXAxisArray, rightYAxisArray, and
// * leftYAxisArray arrays to store each label, if they are enabled to be shown
// =============================================================================
buildAxis() =>
for int j = 0 to squares by 6
if showTopXAxis
array.push(topXAxisArray, label.new(startBarIndex + j * candlesPerDivision, upperPrice + atr / 4, str.tostring(j), style=lineNone, textcolor=labelColor))
if showBottomXAxis
array.push(bottomXAxisArray, label.new(startBarIndex + j * candlesPerDivision, lowerPrice - atr / 2, str.tostring(j), style=lineNone, textcolor=labelColor))
if showRightYAxis
price = upperPrice - (upperPrice - lowerPrice) / squares * j
t = str.tostring(j) + (showPrices ? " (" + str.tostring(math.round_to_mintick(price)) + ")" : "")
array.push(rightYAxisArray, label.new(endBarIndex + 8 * candlesPerDivision, price, t, style=lineNone, textcolor=labelColor))
if showLeftYAxis
array.push(leftYAxisArray, label.new(startBarIndex - 3, upperPrice - (upperPrice - lowerPrice) / squares * j, str.tostring(j), style=lineNone, textcolor=labelColor))
// =============================================================================
// * Update both X-Axis and y-Axis labels
// =============================================================================
updateAxis() =>
for int j = 0 to squares - 1 by 6
if showTopXAxis
label.set_x(array.get(topXAxisArray, j / 6), startBarIndex + j * candlesPerDivision)
label.set_y(array.get(topXAxisArray, j / 6), upperPrice + atr / 4)
if showBottomXAxis
label.set_x(array.get(bottomXAxisArray, j / 6), startBarIndex + j * candlesPerDivision)
label.set_y(array.get(bottomXAxisArray, j / 6), lowerPrice - atr / 2)
if showRightYAxis
label.set_x(array.get(rightYAxisArray, j / 6), endBarIndex + 8 * candlesPerDivision)
label.set_y(array.get(rightYAxisArray, j / 6), upperPrice - (upperPrice - lowerPrice) / squares * j)
if showLeftYAxis
label.set_x(array.get(rightYAxisArray, j / 6), startBarIndex - 3)
label.set_y(array.get(rightYAxisArray, j / 6), upperPrice - (upperPrice - lowerPrice) / squares * j)
// =============================================================================
// * Build the vertical divisions to divide the square in 9 smaller squares
// =============================================================================
buildDivisions() =>
array.push(divisionsArray, line.new(startBarIndex, lowerPrice + onethirdPrice, endBarIndex, lowerPrice + onethirdPrice, color=divisionsColor, style=lineDashed))
array.push(divisionsArray, line.new(startBarIndex, lowerPrice + onethirdPrice * 2, endBarIndex, lowerPrice + onethirdPrice * 2, color=divisionsColor, style=lineDashed))
array.push(divisionsArray, line.new(startBarIndex + onethirdPriceBar, upperPrice, startBarIndex + onethirdPriceBar, lowerPrice, color=divisionsColor, style=lineDashed))
array.push(divisionsArray, line.new(startBarIndex + onethirdPriceBar * 2, upperPrice, startBarIndex + onethirdPriceBar * 2, lowerPrice, color=divisionsColor, style=lineDashed))
// =============================================================================
// * Update the vertical divisions
// =============================================================================
updateDivisions() =>
line.set_xy1(array.get(divisionsArray, 0), startBarIndex, lowerPrice + onethirdPrice)
line.set_xy2(array.get(divisionsArray, 0), endBarIndex, lowerPrice + onethirdPrice)
line.set_xy1(array.get(divisionsArray, 1), startBarIndex, lowerPrice + onethirdPrice * 2)
line.set_xy2(array.get(divisionsArray, 1), endBarIndex, lowerPrice + onethirdPrice * 2)
line.set_xy1(array.get(divisionsArray, 2), startBarIndex + onethirdPriceBar, upperPrice)
line.set_xy2(array.get(divisionsArray, 2), startBarIndex + onethirdPriceBar, lowerPrice)
line.set_xy1(array.get(divisionsArray, 3), startBarIndex + onethirdPriceBar * 2, upperPrice)
line.set_xy2(array.get(divisionsArray, 3), startBarIndex + onethirdPriceBar * 2, lowerPrice)
// =============================================================================
// * Build the Gann's square. It will create lines based on the inputs and store
// * them in some arrays. It will use the showGroup array to check if the line
// * needs to be created or not. If showExtraLines is enabled, it will create
// * specific lines to provide the original Gann's Square format
// =============================================================================
buildSquare() =>
for int i = 0 to (squares / 6) - 1
int endIndex = startBarIndex + 6 * (i + 1) * candlesPerDivision
float endPrice = upperPrice - ((upperPrice - lowerPrice) / squares) * 6 * (i + 1)
string style = array.get(dashedLineStyles, i) ? lineDashed : lineSolid
string extend = array.get(extendLines, i) ? extend.both : extend.none
if array.get(showGroup, i * 8)
// Top Left Bottom
array.push(TLBArray, line.new(startBarIndex, upperPrice, endIndex, lowerPrice, color=array.get(lineColors, i), style=style, extend=extend))
if array.get(showGroup, i * 8 + 1)
// Top Left Right
array.push(TLRArray, line.new(startBarIndex, upperPrice, endBarIndex, endPrice, color=array.get(lineColors, i), style=style, extend=extend))
if array.get(showGroup, i * 8 + 2)
// Bottom Left Top
array.push(BLTArray, line.new(startBarIndex, lowerPrice, endIndex, upperPrice, color=array.get(lineColors, i), style=style, extend=extend))
if array.get(showGroup, i * 8 + 3)
// Bottom Left Right
array.push(BLRArray, line.new(startBarIndex, lowerPrice, endBarIndex, endPrice, color=array.get(lineColors, i), style=style, extend=extend))
if array.get(showGroup, i * 8 + 4)
// Top Right Bottom
array.push(TRBArray, line.new(endBarIndex, upperPrice, endIndex, lowerPrice, color=array.get(lineColors, i), style=style, extend=extend))
if array.get(showGroup, i * 8 + 5)
// Top Right Left
array.push(TRLArray, line.new(endBarIndex, upperPrice, startBarIndex, endPrice, color=array.get(lineColors, i), style=style, extend=extend))
if array.get(showGroup, i * 8 + 6)
// Bottom Right Top
array.push(BRTArray, line.new(endBarIndex, lowerPrice, endIndex, upperPrice, color=array.get(lineColors, i), style=style, extend=extend))
if array.get(showGroup, i * 8 + 7)
// Bottom Right Left
array.push(BRLArray, line.new(endBarIndex, lowerPrice, startBarIndex, endPrice, color=array.get(lineColors, i), style=style, extend=extend))
if showExtraLines
array.push(extraArray, line.new(middleBarIndex, upperPrice, startBarIndex, upperPrice - ((upperPrice - lowerPrice) / squares) * 36, color=colorRed, style=lineDashed))
array.push(extraArray, line.new(middleBarIndex, upperPrice, endBarIndex, upperPrice - ((upperPrice - lowerPrice) / squares) * 36, color=colorRed, style=lineDashed))
array.push(extraArray, line.new(middleBarIndex, lowerPrice, startBarIndex, upperPrice - ((upperPrice - lowerPrice) / squares) * 108, color=colorRed, style=lineDashed))
array.push(extraArray, line.new(middleBarIndex, lowerPrice, endBarIndex, upperPrice - ((upperPrice - lowerPrice) / squares) * 108, color=colorRed, style=lineDashed))
// =============================================================================
// * Update each line created for the Gann's square
// =============================================================================
updateSquare() =>
if array.size(TLBArray) == (squares / 6) - 1 and
array.size(TLRArray) == (squares / 6) - 1 and
array.size(BLTArray) == (squares / 6) - 1
for int i = 0 to (squares / 6) - 1
int endIndex = startBarIndex + 6 * i * candlesPerDivision
float endPrice = upperPrice - ((upperPrice - lowerPrice) / squares) * 6 * i
if array.get(showGroup, i * 8)
// Top Left Bottom
line.set_xy1(array.get(TLBArray, i), startBarIndex, upperPrice)
line.set_xy2(array.get(TLBArray, i), endIndex, lowerPrice)
if array.get(showGroup, i * 8 + 1)
// Top Left Right
line.set_xy1(array.get(TLRArray, i), startBarIndex, upperPrice)
line.set_xy2(array.get(TLRArray, i), endBarIndex, endPrice)
if array.get(showGroup, i * 8 + 2)
// Bottom Left Top
line.set_xy1(array.get(BLTArray, i), startBarIndex, lowerPrice)
line.set_xy2(array.get(BLTArray, i), endIndex, upperPrice)
if array.get(showGroup, i * 8 + 3)
// Bottom Left Right
line.set_xy1(array.get(BLRArray, i), startBarIndex, lowerPrice)
line.set_xy2(array.get(BLRArray, i), endBarIndex, endPrice)
if array.get(showGroup, i * 8 + 4)
// Top Right Bottom
line.set_xy1(array.get(TRBArray, i), endBarIndex, upperPrice)
line.set_xy2(array.get(TRBArray, i), endIndex, lowerPrice)
if array.get(showGroup, i * 8 + 5)
// Top Right Left
line.set_xy1(array.get(TRLArray, i), endBarIndex, upperPrice)
line.set_xy2(array.get(TRLArray, i), startBarIndex, endPrice)
if array.get(showGroup, i * 8 + 6)
// Bottom Right Top
line.set_xy1(array.get(BRTArray, i), endBarIndex, lowerPrice)
line.set_xy2(array.get(BRTArray, i), endIndex, upperPrice)
if array.get(showGroup, i * 8 + 7)
// Bottom Right Left
line.set_xy1(array.get(BRLArray, i), endBarIndex, lowerPrice)
line.set_xy2(array.get(BRLArray, i), startBarIndex, endPrice)
// =============================================================================
// * Create the grid lines for reference
// =============================================================================
buildGrid() =>
for int i = 0 to 23
index = startBarIndex + 6 * (i + 1) * candlesPerDivision
price = upperPrice - ((upperPrice - lowerPrice) / squares) * 6 * (i + 1)
array.push(gridArray, line.new(index, upperPrice, index, lowerPrice, color=gridColor, style=lineDotted))
array.push(gridArray, line.new(startBarIndex, price, endBarIndex, price, color=gridColor, style=lineDotted))
// =============================================================================
// * Update the grid lines
// =============================================================================
updateGrid() =>
for int i = 0 to 23
index = startBarIndex + 6 * (i + 1) * candlesPerDivision
price = upperPrice - ((upperPrice - lowerPrice) / squares) * 6 * (i + 1)
line.set_xy1(array.get(gridArray, i * 2), index, upperPrice)
line.set_xy2(array.get(gridArray, i * 2), index, lowerPrice)
line.set_xy1(array.get(gridArray, i * 2 + 1), startBarIndex, price)
line.set_xy2(array.get(gridArray, i * 2 + 1), endBarIndex, price)
// =============================================================================
// * Set lines pattern to override the parameters input of each division. When an
// * option besides None is selected, it will ignore the selections of each line
// =============================================================================
setPattern() =>
if patterns != "None"
for int i = 0 to array.size(showGroup) - 1
array.set(showGroup, i, false)
if patterns == "Arrow"
array.set(showGroup, 88, true) // Top Left to Bottom 72
array.set(showGroup, 89, true) // Top Left to Right 72
array.set(showGroup, 90, true) // Bottom Left to Top 72
array.set(showGroup, 91, true) // Bottom Left to Right 72
else if patterns == "Star"
array.set(showGroup, 88, true) // Top Left to Bottom 72
array.set(showGroup, 89, true) // Top Left to Right 72
array.set(showGroup, 90, true) // Bottom Left to Top 72
array.set(showGroup, 91, true) // Bottom Left to Right 72
array.set(showGroup, 92, true) // Top Right to Bottom 72
array.set(showGroup, 93, true) // Top Right to Left 72
array.set(showGroup, 94, true) // Bottom Right to Top 72
array.set(showGroup, 95, true) // Bottom Right to Left 72
else if patterns == "36, 72, and 108"
array.set(showGroup, 40, true) // Top Left to Bottom 36
array.set(showGroup, 41, true) // Top Left to Right 36
array.set(showGroup, 42, true) // Bottom Left to Top 36
array.set(showGroup, 45, true) // Top Right to Left 36
array.set(showGroup, 88, true) // Top Left to Bottom 72
array.set(showGroup, 89, true) // Top Left to Right 72
array.set(showGroup, 90, true) // Bottom Left to Top 72
array.set(showGroup, 91, true) // Bottom Left to Right 72
array.set(showGroup, 92, true) // Top Right to Bottom 72
array.set(showGroup, 93, true) // Top Right to Left 72
array.set(showGroup, 94, true) // Bottom Right to Top 72
array.set(showGroup, 95, true) // Bottom Right to Left 72
array.set(showGroup, 139, true) // Bottom Left to Right 108
array.set(showGroup, 140, true) // Top Right to Bottom 108
array.set(showGroup, 142, true) // Bottom Right to Top 108
array.set(showGroup, 143, true) // Bottom Right to Left 108
array.set(showGroup, 184, true) // Top Left to Corner 144
array.set(showGroup, 186, true) // Top Right to Corner 144
else if patterns == "Arrow Cross"
array.set(showGroup, 88, true) // Top Left to Bottom 72
array.set(showGroup, 89, true) // Top Left to Right 72
array.set(showGroup, 90, true) // Bottom Left to Top 72
array.set(showGroup, 91, true) // Bottom Left to Right 72
array.set(showGroup, 184, true) // Top Left to Corner 144
array.set(showGroup, 186, true) // Top Right to Corner 144
else if patterns == "Corners and Cross"
array.set(showGroup, 88, true) // Top Left to Bottom 72
array.set(showGroup, 89, true) // Top Left to Right 72
array.set(showGroup, 90, true) // Bottom Left to Top 72
array.set(showGroup, 91, true) // Bottom Left to Right 72
array.set(showGroup, 92, true) // Top Right to Bottom 72
array.set(showGroup, 93, true) // Top Right to Left 72
array.set(showGroup, 94, true) // Bottom Right to Top 72
array.set(showGroup, 95, true) // Bottom Right to Left 72
array.set(showGroup, 184, true) // Top Left to Corner 144
array.set(showGroup, 186, true) // Top Right to Corner 144
else if patterns == "Master"
array.set(showGroup, 42, true) // Bottom Left to Top 36
array.set(showGroup, 43, true) // Bottom Left to Right 36
array.set(showGroup, 88, true) // Top Left to Bottom 72
array.set(showGroup, 89, true) // Top Left to Right 72
array.set(showGroup, 90, true) // Bottom Left to Top 72
array.set(showGroup, 91, true) // Bottom Left to Right 72
array.set(showGroup, 138, true) // Bottom Left to Top 108
array.set(showGroup, 139, true) // Bottom Left to Right 108
array.set(showGroup, 184, true) // Top Left to Corner 144
array.set(showGroup, 186, true) // Top Right to Corner 144
// *****************************************************************************
// ************************** Run On Every Tick ********************************
// *****************************************************************************
if updateNewBar and buildSquareDone and barstateIsNew and autoPricesAndBar
updateSquare()
updateAxis()
updateBox()
if showDivisions
updateDivisions()
if showGrid
updateGrid()
// if showBackground
// updateBackgrounds()
// *****************************************************************************
// ****************************** Run Once *************************************
// *****************************************************************************
if buildInputsDone
if time == startDate
startBarIndex := barIndex
if barstateIsLast and not buildSquareDone
setPattern()
updateBox()
buildSquare()
buildAxis()
if showDivisions
buildDivisions()
if showGrid
buildGrid()
if showBackground
updateBackgrounds()
buildSquareDone := true
// =============================================================================
// * Create all the lines inputs, together with the color of each one, line style and
// * extend type. The default values are those originally found in W.D. Gann's book.
// * The order of each line matters for the comparison inside the functions
// =============================================================================
if not buildInputsDone
buildInputsDone := true
lineColors := array.concat(lineColors, array.from(
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 6"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 12"),
input.color(color.red, "Line Color", inline="line", group="Connections from corners to 18"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 24"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 30"),
input.color(color.red, "Line Color", inline="line", group="Connections from corners to 36"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 42"),
input.color(color.red, "Line Color", inline="line", group="Connections from corners to 48"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 54"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 60"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 66"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 72"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 78"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 84"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 90"),
input.color(color.red, "Line Color", inline="line", group="Connections from corners to 96"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 102"),
input.color(color.red, "Line Color", inline="line", group="Connections from corners to 108"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 114"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 120"),
input.color(color.red, "Line Color", inline="line", group="Connections from corners to 126"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 132"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 138"),
input.color(color.green, "Line Color", inline="line", group="Connections from corners to 144")))
extendLines := array.concat(extendLines, array.from(
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 6"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 12"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 18"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 24"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 30"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 36"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 42"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 48"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 54"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 60"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 66"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 72"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 78"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 84"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 90"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 96"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 102"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 108"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 114"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 120"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 126"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 132"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 138"),
input.bool(false, "Extend Line", inline="line", group="Connections from corners to 144")))
dashedLineStyles := array.concat(dashedLineStyles, array.from(
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 6"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 12"),
input.bool(true, "Dashed Line", inline="line", group="Connections from corners to 18"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 24"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 30"),
input.bool(true, "Dashed Line", inline="line", group="Connections from corners to 36"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 42"),
input.bool(true, "Dashed Line", inline="line", group="Connections from corners to 48"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 54"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 60"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 66"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 72"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 78"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 84"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 90"),
input.bool(true, "Dashed Line", inline="line", group="Connections from corners to 96"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 102"),
input.bool(true, "Dashed Line", inline="line", group="Connections from corners to 108"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 114"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 120"),
input.bool(true, "Dashed Line", inline="line", group="Connections from corners to 126"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 132"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 138"),
input.bool(false, "Dashed Line", inline="line", group="Connections from corners to 144")))
showGroup := array.concat(showGroup, array.from(
input.bool(false, "┏ ↓", inline="6", group="Connections from corners to 6"),
input.bool(false, "┏ →", inline="6", group="Connections from corners to 6"),
input.bool(false, "┗ ↑", inline="6", group="Connections from corners to 6"),
input.bool(false, "┗ →", inline="6", group="Connections from corners to 6"),
input.bool(false, "┓ ←", inline="6", group="Connections from corners to 6"),
input.bool(false, "┓ ↓", inline="6", group="Connections from corners to 6"),
input.bool(false, "┛ ←", inline="6", group="Connections from corners to 6"),
input.bool(false, "┛ ↑", inline="6", group="Connections from corners to 6"),
input.bool(false, "┏ ↓", inline="12", group="Connections from corners to 12"),
input.bool(false, "┏ →", inline="12", group="Connections from corners to 12"),
input.bool(false, "┗ ↑", inline="12", group="Connections from corners to 12"),
input.bool(false, "┗ →", inline="12", group="Connections from corners to 12"),
input.bool(false, "┓ ←", inline="12", group="Connections from corners to 12"),
input.bool(false, "┓ ↓", inline="12", group="Connections from corners to 12"),
input.bool(false, "┛ ←", inline="12", group="Connections from corners to 12"),
input.bool(false, "┛ ↑", inline="12", group="Connections from corners to 12"),
input.bool(true, "┏ ↓", inline="18", group="Connections from corners to 18"),
input.bool(true, "┏ →", inline="18", group="Connections from corners to 18"),
input.bool(true, "┗ ↑", inline="18", group="Connections from corners to 18"),
input.bool(false, "┗ →", inline="18", group="Connections from corners to 18"),
input.bool(false, "┓ ←", inline="18", group="Connections from corners to 18"),
input.bool(false, "┓ ↓", inline="18", group="Connections from corners to 18"),
input.bool(false, "┛ ←", inline="18", group="Connections from corners to 18"),
input.bool(false, "┛ ↑", inline="18", group="Connections from corners to 18"),
input.bool(false, "┏ ↓", inline="24", group="Connections from corners to 24"),
input.bool(false, "┏ →", inline="24", group="Connections from corners to 24"),
input.bool(false, "┗ ↑", inline="24", group="Connections from corners to 24"),
input.bool(false, "┗ →", inline="24", group="Connections from corners to 24"),
input.bool(false, "┓ ←", inline="24", group="Connections from corners to 24"),
input.bool(false, "┓ ↓", inline="24", group="Connections from corners to 24"),
input.bool(false, "┛ ←", inline="24", group="Connections from corners to 24"),
input.bool(false, "┛ ↑", inline="24", group="Connections from corners to 24"),
input.bool(false, "┏ ↓", inline="30", group="Connections from corners to 30"),
input.bool(false, "┏ →", inline="30", group="Connections from corners to 30"),
input.bool(false, "┗ ↑", inline="30", group="Connections from corners to 30"),
input.bool(false, "┗ →", inline="30", group="Connections from corners to 30"),
input.bool(false, "┓ ←", inline="30", group="Connections from corners to 30"),
input.bool(false, "┓ ↓", inline="30", group="Connections from corners to 30"),
input.bool(false, "┛ ←", inline="30", group="Connections from corners to 30"),
input.bool(false, "┛ ↑", inline="30", group="Connections from corners to 30"),
input.bool(true, "┏ ↓", inline="36", group="Connections from corners to 36"),
input.bool(true, "┏ →", inline="36", group="Connections from corners to 36"),
input.bool(true, "┗ ↑", inline="36", group="Connections from corners to 36"),
input.bool(false, "┗ →", inline="36", group="Connections from corners to 36"),
input.bool(false, "┓ ←", inline="36", group="Connections from corners to 36"),
input.bool(false, "┓ ↓", inline="36", group="Connections from corners to 36"),
input.bool(false, "┛ ←", inline="36", group="Connections from corners to 36"),
input.bool(false, "┛ ↑", inline="36", group="Connections from corners to 36"),
input.bool(false, "┏ ↓", inline="42", group="Connections from corners to 42"),
input.bool(false, "┏ →", inline="42", group="Connections from corners to 42"),
input.bool(false, "┗ ↑", inline="42", group="Connections from corners to 42"),
input.bool(false, "┗ →", inline="42", group="Connections from corners to 42"),
input.bool(false, "┓ ←", inline="42", group="Connections from corners to 42"),
input.bool(false, "┓ ↓", inline="42", group="Connections from corners to 42"),
input.bool(false, "┛ ←", inline="42", group="Connections from corners to 42"),
input.bool(false, "┛ ↑", inline="42", group="Connections from corners to 42"),
input.bool(true, "┏ ↓", inline="48", group="Connections from corners to 48"),
input.bool(true, "┏ →", inline="48", group="Connections from corners to 48"),
input.bool(true, "┗ ↑", inline="48", group="Connections from corners to 48"),
input.bool(false, "┗ →", inline="48", group="Connections from corners to 48"),
input.bool(false, "┓ ←", inline="48", group="Connections from corners to 48"),
input.bool(false, "┓ ↓", inline="48", group="Connections from corners to 48"),
input.bool(false, "┛ ←", inline="48", group="Connections from corners to 48"),
input.bool(false, "┛ ↑", inline="48", group="Connections from corners to 48"),
input.bool(false, "┏ ↓", inline="54", group="Connections from corners to 54"),
input.bool(false, "┏ →", inline="54", group="Connections from corners to 54"),
input.bool(false, "┗ ↑", inline="54", group="Connections from corners to 54"),
input.bool(false, "┗ →", inline="54", group="Connections from corners to 54"),
input.bool(false, "┓ ←", inline="54", group="Connections from corners to 54"),
input.bool(false, "┓ ↓", inline="54", group="Connections from corners to 54"),
input.bool(false, "┛ ←", inline="54", group="Connections from corners to 54"),
input.bool(false, "┛ ↑", inline="54", group="Connections from corners to 54"),
input.bool(false, "┏ ↓", inline="60", group="Connections from corners to 60"),
input.bool(false, "┏ →", inline="60", group="Connections from corners to 60"),
input.bool(false, "┗ ↑", inline="60", group="Connections from corners to 60"),
input.bool(false, "┗ →", inline="60", group="Connections from corners to 60"),
input.bool(false, "┓ ←", inline="60", group="Connections from corners to 60"),
input.bool(false, "┓ ↓", inline="60", group="Connections from corners to 60"),
input.bool(false, "┛ ←", inline="60", group="Connections from corners to 60"),
input.bool(false, "┛ ↑", inline="60", group="Connections from corners to 60"),
input.bool(false, "┏ ↓", inline="66", group="Connections from corners to 66"),
input.bool(false, "┏ →", inline="66", group="Connections from corners to 66"),
input.bool(false, "┗ ↑", inline="66", group="Connections from corners to 66"),
input.bool(false, "┗ →", inline="66", group="Connections from corners to 66"),
input.bool(false, "┓ ←", inline="66", group="Connections from corners to 66"),
input.bool(false, "┓ ↓", inline="66", group="Connections from corners to 66"),
input.bool(false, "┛ ←", inline="66", group="Connections from corners to 66"),
input.bool(false, "┛ ↑", inline="66", group="Connections from corners to 66"),
input.bool(true, "┏ ↓", inline="72", group="Connections from corners to 72"),
input.bool(true, "┏ →", inline="72", group="Connections from corners to 72"),
input.bool(true, "┗ ↑", inline="72", group="Connections from corners to 72"),
input.bool(true, "┗ →", inline="72", group="Connections from corners to 72"),
input.bool(true, "┓ ←", inline="72", group="Connections from corners to 72"),
input.bool(true, "┓ ↓", inline="72", group="Connections from corners to 72"),
input.bool(true, "┛ ←", inline="72", group="Connections from corners to 72"),
input.bool(true, "┛ ↑", inline="72", group="Connections from corners to 72"),
input.bool(false, "┏ ↓", inline="78", group="Connections from corners to 78"),
input.bool(false, "┏ →", inline="78", group="Connections from corners to 78"),
input.bool(false, "┗ ↑", inline="78", group="Connections from corners to 78"),
input.bool(false, "┗ →", inline="78", group="Connections from corners to 78"),
input.bool(false, "┓ ←", inline="78", group="Connections from corners to 78"),
input.bool(false, "┓ ↓", inline="78", group="Connections from corners to 78"),
input.bool(false, "┛ ←", inline="78", group="Connections from corners to 78"),
input.bool(false, "┛ ↑", inline="78", group="Connections from corners to 78"),
input.bool(false, "┏ ↓", inline="84", group="Connections from corners to 84"),
input.bool(false, "┏ →", inline="84", group="Connections from corners to 84"),
input.bool(false, "┗ ↑", inline="84", group="Connections from corners to 84"),
input.bool(false, "┗ →", inline="84", group="Connections from corners to 84"),
input.bool(false, "┓ ←", inline="84", group="Connections from corners to 84"),
input.bool(false, "┓ ↓", inline="84", group="Connections from corners to 84"),
input.bool(false, "┛ ←", inline="84", group="Connections from corners to 84"),
input.bool(false, "┛ ↑", inline="84", group="Connections from corners to 84"),
input.bool(false, "┏ ↓", inline="90", group="Connections from corners to 90"),
input.bool(false, "┏ →", inline="90", group="Connections from corners to 90"),
input.bool(false, "┗ ↑", inline="90", group="Connections from corners to 90"),
input.bool(false, "┗ →", inline="90", group="Connections from corners to 90"),
input.bool(false, "┓ ←", inline="90", group="Connections from corners to 90"),
input.bool(false, "┓ ↓", inline="90", group="Connections from corners to 90"),
input.bool(false, "┛ ←", inline="90", group="Connections from corners to 90"),
input.bool(false, "┛ ↑", inline="90", group="Connections from corners to 90"),
input.bool(false, "┏ ↓", inline="96", group="Connections from corners to 96"),
input.bool(false, "┏ →", inline="96", group="Connections from corners to 96"),
input.bool(false, "┗ ↑", inline="96", group="Connections from corners to 96"),
input.bool(true, "┗ →", inline="96", group="Connections from corners to 96"),
input.bool(false, "┓ ←", inline="96", group="Connections from corners to 96"),
input.bool(false, "┓ ↓", inline="96", group="Connections from corners to 96"),
input.bool(false, "┛ ←", inline="96", group="Connections from corners to 96"),
input.bool(false, "┛ ↑", inline="96", group="Connections from corners to 96"),
input.bool(false, "┏ ↓", inline="102", group="Connections from corners to 102"),
input.bool(false, "┏ →", inline="102", group="Connections from corners to 102"),
input.bool(false, "┗ ↑", inline="102", group="Connections from corners to 102"),
input.bool(false, "┗ →", inline="102", group="Connections from corners to 102"),
input.bool(false, "┓ ←", inline="102", group="Connections from corners to 102"),
input.bool(false, "┓ ↓", inline="102", group="Connections from corners to 102"),
input.bool(false, "┛ ←", inline="102", group="Connections from corners to 102"),
input.bool(false, "┛ ↑", inline="102", group="Connections from corners to 102"),
input.bool(false, "┏ ↓", inline="108", group="Connections from corners to 108"),
input.bool(false, "┏ →", inline="108", group="Connections from corners to 108"),
input.bool(false, "┗ ↑", inline="108", group="Connections from corners to 108"),
input.bool(true, "┗ →", inline="108", group="Connections from corners to 108"),
input.bool(false, "┓ ←", inline="108", group="Connections from corners to 108"),
input.bool(false, "┓ ↓", inline="108", group="Connections from corners to 108"),
input.bool(false, "┛ ←", inline="108", group="Connections from corners to 108"),
input.bool(false, "┛ ↑", inline="108", group="Connections from corners to 108"),
input.bool(false, "┏ ↓", inline="114", group="Connections from corners to 114"),
input.bool(false, "┏ →", inline="114", group="Connections from corners to 114"),
input.bool(false, "┗ ↑", inline="114", group="Connections from corners to 114"),
input.bool(false, "┗ →", inline="114", group="Connections from corners to 114"),
input.bool(false, "┓ ←", inline="114", group="Connections from corners to 114"),
input.bool(false, "┓ ↓", inline="114", group="Connections from corners to 114"),
input.bool(false, "┛ ←", inline="114", group="Connections from corners to 114"),
input.bool(false, "┛ ↑", inline="114", group="Connections from corners to 114"),
input.bool(false, "┏ ↓", inline="120", group="Connections from corners to 120"),
input.bool(false, "┏ →", inline="120", group="Connections from corners to 120"),
input.bool(false, "┗ ↑", inline="120", group="Connections from corners to 120"),
input.bool(false, "┗ →", inline="120", group="Connections from corners to 120"),
input.bool(false, "┓ ←", inline="120", group="Connections from corners to 120"),
input.bool(false, "┓ ↓", inline="120", group="Connections from corners to 120"),
input.bool(false, "┛ ←", inline="120", group="Connections from corners to 120"),
input.bool(false, "┛ ↑", inline="120", group="Connections from corners to 120"),
input.bool(false, "┏ ↓", inline="126", group="Connections from corners to 126"),
input.bool(false, "┏ →", inline="126", group="Connections from corners to 126"),
input.bool(false, "┗ ↑", inline="126", group="Connections from corners to 126"),
input.bool(true, "┗ →", inline="126", group="Connections from corners to 126"),
input.bool(false, "┓ ←", inline="126", group="Connections from corners to 126"),
input.bool(false, "┓ ↓", inline="126", group="Connections from corners to 126"),
input.bool(false, "┛ ←", inline="126", group="Connections from corners to 126"),
input.bool(false, "┛ ↑", inline="126", group="Connections from corners to 126"),
input.bool(false, "┏ ↓", inline="132", group="Connections from corners to 132"),
input.bool(false, "┏ →", inline="132", group="Connections from corners to 132"),
input.bool(false, "┗ ↑", inline="132", group="Connections from corners to 132"),
input.bool(false, "┗ →", inline="132", group="Connections from corners to 132"),
input.bool(false, "┓ ←", inline="132", group="Connections from corners to 132"),
input.bool(false, "┓ ↓", inline="132", group="Connections from corners to 132"),
input.bool(false, "┛ ←", inline="132", group="Connections from corners to 132"),
input.bool(false, "┛ ↑", inline="132", group="Connections from corners to 132"),
input.bool(false, "┏ ↓", inline="138", group="Connections from corners to 138"),
input.bool(false, "┏ →", inline="138", group="Connections from corners to 138"),
input.bool(false, "┗ ↑", inline="138", group="Connections from corners to 138"),
input.bool(false, "┗ →", inline="138", group="Connections from corners to 138"),
input.bool(false, "┓ ←", inline="138", group="Connections from corners to 138"),
input.bool(false, "┓ ↓", inline="138", group="Connections from corners to 138"),
input.bool(false, "┛ ←", inline="138", group="Connections from corners to 138"),
input.bool(false, "┛ ↑", inline="138", group="Connections from corners to 138"),
input.bool(true, "┏ ↓", inline="144", group="Connections from corners to 144"),
input.bool(true, "┏ →", inline="144", group="Connections from corners to 144"),
input.bool(true, "┗ ↑", inline="144", group="Connections from corners to 144"),
input.bool(true, "┗ →", inline="144", group="Connections from corners to 144"),
input.bool(false, "┓ ←", inline="144", group="Connections from corners to 144"),
input.bool(false, "┓ ↓", inline="144", group="Connections from corners to 144"),
input.bool(false, "┛ ←", inline="144", group="Connections from corners to 144"),
input.bool(false, "┛ ↑", inline="144", group="Connections from corners to 144")))
trend bar renkli...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.yellow, 0), style=plot.style_line, 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=true)
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
// 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
src33 = input(defval=close, title='لا تلعب بيها')
len33 = input.int(defval=20, title='الشمعات', minval=10)
devlen = input.float(defval=2., title='الانحراف', minval=0.1, step=0.1)
extendit = input(defval=false, 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(src33, len33) =>
mid = math.sum(src33, len33) / len33
slope = ta.linreg(src33, len33, 0) - ta.linreg(src33, len33, 1)
intercept = mid - slope * math.floor(len33 / 2) + (1 - len33 % 2) / 2 * slope
endy = intercept + slope * (len33 - 1)
dev = 0.0
for x = 0 to len33 - 1 by 1
dev += math.pow(src33[x] - (slope * (len33 - x) + intercept), 2)
dev
dev := math.sqrt(dev / len33)
[intercept, endy, dev, slope]
[y1_, y2_, dev, slope] = get_channel(src33, len33)
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 - (len33 - 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 - (len33 - 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 - (len33 - 1), y=y1_, text='S', size=size.normal)
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 - (len33 - 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)
// direction
trendisup = math.sign(slope) != math.sign(slope[1]) and slope > 0
trendisdown = math.sign(slope) != math.sign(slope[1]) and slope < 0
pi döngüsünün ...yarısı kullanılarak....
görüntüler......
https://www.tradingview.com/x/H3fxiZKL/
https://www.tradingview.com/x/7HwEdOwU/
https://www.tradingview.com/x/qX24pk0a/
https://www.tradingview.com/x/bZF7yn6J/
kodu....
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Furo010
// [2023-08]
//@version=5
indicator(title="Pi Cycle Top Indicator", shorttitle="Pi Cycle", overlay=true)
// Input to control whether the Pi Cycle Top Indicator should be displayed
Show_PiCicleTopIndicator = input.bool(title='Pi Cycle Top Indicator', defval=true, tooltip='Use only with daily candles')
// Calculate the 111-period and 350-period simple moving averages (SMAs) of the closing prices
sma111 = ta.sma(close, 55)
sma350 = ta.sma(close, 175)
// Plot the SMAs on the chart based on the input condition and daily timeframe
plot(Show_PiCicleTopIndicator and timeframe.isminutes ? sma111 : na, title="MA 111", linewidth=2, color=color.new(color.orange, 0))
plot(Show_PiCicleTopIndicator and timeframe.isminutes ? sma350 : na, title="MA 350 * 2", linewidth=2, color=color.new(color.green, 0))
https://tr.tradingview.com/script/u4YafpVP/
birleştirilmiş kod yazmış....pivot hesaplaması var....
34 uzunlukla trend hesaplaması....rsi stock var....
kodun uzun olmasının sebebi ise.....
mum formasyonlarını birleştirmiş olması....
labelların anlamı...kısaltılmış mum formasyonları....
https://www.tradingview.com/x/xC9jTgim/
log kanallar...PHP Code:
//@version=5
indicator("Acceleration Bands", overlay=true)
ma(sourcexz, lengthxz, type) =>
switch type
"SMA" => ta.sma(sourcexz, lengthxz)
"EMA" => ta.ema(sourcexz, lengthxz)
"SMMA (RMA)" => ta.rma(sourcexz, lengthxz)
"WMA" => ta.wma(sourcexz, lengthxz)
"VWMA" => ta.vwma(sourcexz, lengthxz)
factorxz= input(0.004)
lengthxz = input(20)
maTypeInput = input.string("EMA", title="MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
logHigh = math.log10(high)
logLow = math.log10(low)
logAvg = math.log10((high + low) / 2)
logUpperband = ma(logHigh * (1 + 2 * (((logHigh - logLow) / (logAvg)) * 1000) * factorxz), lengthxz, maTypeInput)
logLowerband = ma(logLow * (1 - 2 * (((logHigh - logLow) / (logAvg)) * 1000) * factorxz), lengthxz, maTypeInput)
logCentral = (logUpperband + logLowerband) / 2
Upperbandxz = math.pow(10, logUpperband)
Centralxz = math.pow(10, logCentral)
Lowerbandxz = math.pow(10, logLowerband)
plot(Upperbandxz, title="Olası-Tepe", color=color.rgb(255, 82, 82, 100))
plot(Centralxz,title="Olası-Ort", color=color.rgb(255, 153, 0, 100))
plot(Lowerbandxz,title="Olası-Dip", color=color.rgb(76, 175, 79, 100))
draw_prediction = input.bool(true, title="Draw Prediction Lines")
slope_length = input(20, title = "Slope Length")
customLogarithmicRegression(_data, _color) =>
logData = math.log10(_data)
linreg = ta.linreg(logData, slope_length, 0)
linreg_p = ta.linreg(logData, slope_length, 0 + 1)
x = bar_index
slope = linreg - linreg_p
intercept = linreg - x * slope
deviationSum = 0.0
for i = 0 to slope_length - 1 by 1
deviationSum += math.pow(logData[i] - (slope * (x - i) + intercept), 2)
deviation = math.sqrt(deviationSum / slope_length)
x1 = x - slope_length
x2 = x
y1 = slope * (x - slope_length) + intercept
y2 = linreg
var line b = na
updating = timestamp("20 Jul 2050 00:00 +0300") >= time
displacement = false
if draw_prediction
if updating
b := line.new(x1, math.pow(10, y1), x2, math.pow(10, y2), xloc.bar_index, extend.right, _color, style=line.style_dotted, width=2)
if not displacement
line.delete(b[1])
customLogarithmicRegression(Upperbandxz, color.red)
customLogarithmicRegression(Centralxz, color.orange)
customLogarithmicRegression(Lowerbandxz, color.green)
PHP Code:
//@version=2
study("SAR", overlay = true)
startds = input(0)
incds = input(0.01)
maxids = input(0.1)
Pds = 1
EPds = max(high, high[1])
SARds = min(low, low[1])
AFds = startds
EPnewds = 0
AFnewds = startds
if nz(Pds[1]) == 0
Pds := 1
else
if (Pds[1] == 1)
EPnewds := max(high, EPds[1])
else
EPnewds := min(low, EPds[1])
if EPnewds != EPds[1]
AFnewds := min(maxids, AFds[1] + incds)
else
AFnewds := AFds[1]
if nz(Pds[1]) == 0
Pds := 1
else
if Pds[1] == 1 and SARds[1] + AFds[1] * (EPnewds - SARds[1]) <= low
Pds := 1
SARds := SARds[1] + AFnewds * (EPnewds - SARds[1])
EPds := EPnewds
AFds := AFnewds
else
if Pds[1] == 1 and SARds[1] + AFds[1] * (EPnewds - SARds[1]) > low
if low >= SARds[1]
Pds := 1
SARds := low
EPds := EPnewds
AFds := AFnewds
else
Pds := -1
SARds := max(high, EPds[1])
EPds := min(low, low[1])
AFds := startds
else
if Pds[1] == -1 and SARds[1] - AFds[1] * (SARds[1] - EPnewds) >= high
Pds := -1
SARds := SARds[1] - AFnewds * (SARds[1] - EPnewds)
EPds := EPnewds
AFds := AFnewds
else
if Pds[1] == -1 and SARds[1] - AFds[1] * (SARds[1] - EPnewds) < high
if high <= SARds[1]
Pds := -1
SARds := high
EPds := EPnewds
AFds := AFnewds
else
Pds := 1
SARds := min(low, EPds[1])
EPds := max(high, high[1])
AFds := startds
//plot(SARds, color = white, style = cross, linewidth = 2)
/////////////////////////////
y3 = sar(0,0.01,0.1)
y2 = sar(0,0.02,0.1)
y1 = sar(0,0.03,0.1)
y33 = sar(0.01,0.02,0.2)
y22 = sar(0.01,0.04,0.4)
y11 = sar(0.01,0.06,0.6)
acx32fX = input(true, title="Adaptive Coloring", type=bool)
plot(y1, title="A", style=circles, color=acx32fX?(y1>close?red:lime) : silver, transp=100, linewidth=1)
plot(y11, title="AA", style=circles, color=acx32fX?(y11>close?red:lime) : silver, transp=00, linewidth=1)
plot(y2, title="B", style=circles, color=acx32fX?(y2>close?red:lime) : silver, transp=100, linewidth=1)
plot(y22, title="BB", style=circles, color=acx32fX?(y22>close?red:lime) : silver, transp=00, linewidth=1)
plot(y3, title="C", style=circles, color=acx32fX?(y3>close?red:lime) : silver, transp=100, linewidth=1)
plot(y33, title="CC", style=circles, color=acx32fX?(y33>close?red:lime) : silver, transp=00, linewidth=1)
plot(SARds, title="ABC", style=line, color=acx32fX?(SARds>close?red:lime) : silver, transp=00, linewidth=2)
///////////////////
PHP Code:
//@version=5
indicator(title="Vsar", overlay = true)
// ------------------- INPUTS
ATRPeriod = input(10, "ATR Period")
ATRMultiplicator = input.float(10.2, "ARC constant muliplicator", minval=0, step=0.1)
source1 = input(high, "Source 1")
source2 = input(low, "Source 2")
source3 = input(hl2, "Source 3")
// ------------------- FIRST INIT
SIC1 = source1
SAR1 = 0.0
SIC2 = source2
SAR2 = 0.0
SIC3 = source3
SAR3 = 0.0
// -------------------
// Display SAR (calculated from the previous candle)
plot1 = plot(SAR1[1], color = source1 < SAR1[1] ? color.rgb(255, 82, 82, 100) : color.rgb(76, 175, 79, 100), style = plot.style_circles)
plot2 = plot(SAR2[1], color = source2 < SAR2[1] ? color.rgb(255, 82, 82, 100) : color.rgb(76, 175, 79, 100), style = plot.style_circles)
plot(SAR3[1], color = source3 < SAR3[1] ? color.rgb(255, 82, 82, 100) : color.rgb(76, 175, 79, 100), style = plot.style_circles)
//fill(plot1, plot2, title='SAR fill', color=#FFFFFF40)
// Calculate ARC (ATR x multiplicator)
ARC = ATRMultiplicator * ta.atr(ATRPeriod)
// Calculate the new SIC
if(source1 > SAR1[1])
// Long trade in progress, the new SIC is the max between the current price and the previous SIC
SIC1 := math.max(source1, SIC1[1])
// Calculate SAR for the next candle
SAR1 := SIC1 - ARC
if(source1 < SAR1[1])
// Short trade in progress, the new SIC is the min between the current price and the previous SIC
SIC1 := math.min(source1, SIC1[1])
// Calculate SAR for the next candle
SAR1 := SIC1 + ARC
if(source2 > SAR2[1])
// Long trade in progress, the new SIC is the max between the current price and the previous SIC
SIC2 := math.max(source2, SIC2[1])
// Calculate SAR for the next candle
SAR2 := SIC2 - ARC
if(source2 < SAR2[1])
// Short trade in progress, the new SIC is the min between the current price and the previous SIC
SIC2 := math.min(source2, SIC2[1])
// Calculate SAR for the next candle
SAR2 := SIC2 + ARC
if(source3 > SAR3[1])
// Long trade in progress, the new SIC is the max between the current price and the previous SIC
SIC3 := math.max(source3, SIC3[1])
// Calculate SAR for the next candle
SAR3 := SIC3 - ARC
if(source3 < SAR3[1])
// Short trade in progress, the new SIC is the min between the current price and the previous SIC
SIC3 := math.min(source3, SIC3[1])
// Calculate SAR for the next candle
SAR3 := SIC3 + ARC
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RafaelZioni
//@version=5
indicator(title='SAR', overlay=true)
lenxc = input(5)
lenxc20 = input(20)
lenxc50 = input(50)
z(close, lenxc) =>
hxc = 0.0
dxc = 0.0
for i = 0 to lenxc - 1 by 1
kxc = (lenxc - i) * lenxc
hxc += kxc
dxc += close[i] * kxc
dxc
dxc / hxc
cxc = z(close, math.floor(math.sqrt(lenxc)))
//
z20(close, lenxc20) =>
hcx20 = 0.0
dxc20 = 0.0
for i = 0 to lenxc20 - 1 by 1
kxc20 = (lenxc20 - i) * lenxc20
hcx20 += kxc20
dxc20 += close[i] * kxc20
dxc20
dxc20 / hcx20
cxc20 = z(close, math.floor(math.sqrt(lenxc20)))
//
z50(close, lenxc50) =>
hxc50 = 0.0
dxc50 = 0.0
for i = 0 to lenxc50 - 1 by 1
kxc50 = (lenxc50 - i) * lenxc50
hxc50 += kxc50
dxc50 += close[i] * kxc50
dxc50
dxc50 / hxc50
cxc50 = z(close, math.floor(math.sqrt(lenxc50)))
//
//
startsx = 0
incrementsx = 0.01
maximumsx = 0.1
ssx = ta.sar(startsx, incrementsx, maximumsx)
s1sx = z(ssx, lenxc)
pcsx = close < s1sx ? color.red : color.green
plot(s1sx, title="5",style=plot.style_cross, color=pcsx, linewidth=1)
startsx20 = 0
incrementsx20 = 0.01
maximumsx20 = 0.1
ssx20 = ta.sar(startsx20, incrementsx20, maximumsx20)
s1sx20 = z(ssx20, lenxc20)
pcsx20 = close < s1sx20 ? color.red : color.green
plot(s1sx20, title="20",style=plot.style_cross, color=pcsx20, linewidth=1)
startsx50 = 0
incrementsx50 = 0.01
maximumsx50 = 0.1
ssx50 = ta.sar(startsx50, incrementsx50, maximumsx50)
s1sx50 = z50(ssx50, lenxc50)
pcsx50 = close < s1sx50 ? color.red : color.green
plot(s1sx50, title="50",style=plot.style_cross, color=pcsx50, linewidth=1)
PHP Code:
//@version=5
indicator('SAR', overlay=true)
// INPUTS //
//
startq = input(0)
incrementq = input(0.01)
maximumq = input(0.1)
s1q = ta.sar(startq, incrementq, maximumq)
pcq = close < s1q ? color.red : color.green
//plot(s1q, style=plot.style_line, color=pcq)
//
lookBackq = input(20)
//
multiq = input.float(2, title='Multiplier', minval=0.001, maxval=2)
meanq = ta.ema(s1q, lookBackq)
stddevq = multiq * ta.stdev(s1q, lookBackq)
bq = meanq + stddevq
s2q = meanq - stddevq
low1q = ta.crossover(s1q, s2q)
high1q = ta.crossunder(s1q, bq)
//meanp = plot(meanq, title='Mean', color=color.new(color.gray, 0))
bsign = plot(bq, title='TEPE', color=color.new(#4caf4f, 100), linewidth=2)
ssign = plot(s2q, title='DİP', color=color.new(#ff5252, 100), linewidth=2)
plotshape(low1q, title='low', text='DİP', color=color.new(color.green, 0), style=shape.labelup, location=location.belowbar, size=size.tiny, textcolor=color.new(color.white, 0)) //plot for buy icon
plotshape(high1q, title='high', text='TEPE', color=color.new(color.red, 0), style=shape.labeldown, location=location.abovebar, size=size.tiny, textcolor=color.new(color.white, 0)) //plot for sell icon
//////////////////
lenxc = input(5)
lenxc20 = input(20)
lenxc50 = input(50)
z(close, lenxc) =>
hxc = 0.0
dxc = 0.0
for i = 0 to lenxc - 1 by 1
kxc = (lenxc - i) * lenxc
hxc += kxc
dxc += close[i] * kxc
dxc
dxc / hxc
cxc = z(close, math.floor(math.sqrt(lenxc)))
//
z20(close, lenxc20) =>
hcx20 = 0.0
dxc20 = 0.0
for i = 0 to lenxc20 - 1 by 1
kxc20 = (lenxc20 - i) * lenxc20
hcx20 += kxc20
dxc20 += close[i] * kxc20
dxc20
dxc20 / hcx20
cxc20 = z(close, math.floor(math.sqrt(lenxc20)))
//
z50(close, lenxc50) =>
hxc50 = 0.0
dxc50 = 0.0
for i = 0 to lenxc50 - 1 by 1
kxc50 = (lenxc50 - i) * lenxc50
hxc50 += kxc50
dxc50 += close[i] * kxc50
dxc50
dxc50 / hxc50
cxc50 = z(close, math.floor(math.sqrt(lenxc50)))
//
//
startsx = 0
incrementsx = 0.01
maximumsx = 0.1
ssx = ta.sar(startsx, incrementsx, maximumsx)
s1sx = z(ssx, lenxc)
pcsx = close < s1sx ? color.red : color.green
plot(s1sx, title="5",style=plot.style_cross, color=pcsx, linewidth=1)
startsx20 = 0
incrementsx20 = 0.01
maximumsx20 = 0.1
ssx20 = ta.sar(startsx20, incrementsx20, maximumsx20)
s1sx20 = z(ssx20, lenxc20)
pcsx20 = close < s1sx20 ? color.red : color.green
plot(s1sx20, title="20",style=plot.style_cross, color=pcsx20, linewidth=1)
startsx50 = 0
incrementsx50 = 0.01
maximumsx50 = 0.1
ssx50 = ta.sar(startsx50, incrementsx50, maximumsx50)
s1sx50 = z50(ssx50, lenxc50)
pcsx50 = close < s1sx50 ? color.red : color.green
plot(s1sx50, title="50",style=plot.style_cross, color=pcsx50, linewidth=1)
//////////////////////////
// ------------------- INPUTS
ATRPeriod = input(10, "ATR Period")
ATRMultiplicator = input.float(10.2, "ARC constant muliplicator", minval=0, step=0.1)
source1 = input(high, "Source 1")
source2 = input(low, "Source 2")
source3 = input(hl2, "Source 3")
// ------------------- FIRST INIT
SIC1 = source1
SAR1 = 0.0
SIC2 = source2
SAR2 = 0.0
SIC3 = source3
SAR3 = 0.0
// -------------------
// Display SAR (calculated from the previous candle)
plot1 = plot(SAR1[1], color = source1 < SAR1[1] ? color.rgb(255, 82, 82, 100) : color.rgb(76, 175, 79, 100), style = plot.style_circles)
plot2 = plot(SAR2[1], color = source2 < SAR2[1] ? color.rgb(255, 82, 82, 100) : color.rgb(76, 175, 79, 100), style = plot.style_circles)
plot(SAR3[1], color = source3 < SAR3[1] ? color.rgb(255, 82, 82, 100) : color.rgb(76, 175, 79, 100), style = plot.style_circles)
//fill(plot1, plot2, title='SAR fill', color=#FFFFFF40)
// Calculate ARC (ATR x multiplicator)
ARC = ATRMultiplicator * ta.atr(ATRPeriod)
// Calculate the new SIC
if(source1 > SAR1[1])
// Long trade in progress, the new SIC is the max between the current price and the previous SIC
SIC1 := math.max(source1, SIC1[1])
// Calculate SAR for the next candle
SAR1 := SIC1 - ARC
if(source1 < SAR1[1])
// Short trade in progress, the new SIC is the min between the current price and the previous SIC
SIC1 := math.min(source1, SIC1[1])
// Calculate SAR for the next candle
SAR1 := SIC1 + ARC
if(source2 > SAR2[1])
// Long trade in progress, the new SIC is the max between the current price and the previous SIC
SIC2 := math.max(source2, SIC2[1])
// Calculate SAR for the next candle
SAR2 := SIC2 - ARC
if(source2 < SAR2[1])
// Short trade in progress, the new SIC is the min between the current price and the previous SIC
SIC2 := math.min(source2, SIC2[1])
// Calculate SAR for the next candle
SAR2 := SIC2 + ARC
if(source3 > SAR3[1])
// Long trade in progress, the new SIC is the max between the current price and the previous SIC
SIC3 := math.max(source3, SIC3[1])
// Calculate SAR for the next candle
SAR3 := SIC3 - ARC
if(source3 < SAR3[1])
// Short trade in progress, the new SIC is the min between the current price and the previous SIC
SIC3 := math.min(source3, SIC3[1])
// Calculate SAR for the next candle
SAR3 := SIC3 + ARC
//////////////////////////////////////////////////
PHP Code:
//@version=5
indicator("*", overlay = true, max_boxes_count=100,max_lines_count = 100, max_labels_count = 100, format=format.price)
//////////////////////Parabolic Sar ile Trend Takip Sistemidir.//////////////////////////////////////////////////////////////////////////////////////////////////////////////
psar(start1, inc1, maximum1) =>
out1 = float(na)
isUpTrend1 = bool(na)
maxMin1 = float(na)
acc1 = float(na)
prev1 = float(na)
if bar_index >= 1
prev1 := out1[1]
if bar_index == 1
if close > close[1]
isUpTrend1 := true
maxMin1 := math.max(high, high[1])
prev1 := math.min(low, low[1])
prev1
else
isUpTrend1 := false
maxMin1 := math.min(low, low[1])
prev1 := math.max(high, high[1])
prev1
acc1 := start1
acc1
else
isUpTrend1 := isUpTrend1[1]
acc1 := acc1[1]
maxMin1 := maxMin1[1]
maxMin1
if isUpTrend1
if high > maxMin1
maxMin1 := high
acc1 := math.min(acc1 + inc1, maximum1)
acc1
else
if low < maxMin1
maxMin1 := low
acc1 := math.min(acc1 + inc1, maximum1)
acc1
if na(out1)
out1 := prev1 + acc1 * (maxMin1 - prev1)
out1
if isUpTrend1
if low <= out1
isUpTrend1 := false
out1 := maxMin1
maxMin1 := low
acc1 := start1
acc1
else
if high >= out1
isUpTrend1 := true
out1 := maxMin1
maxMin1 := high
acc1 := start1
acc1
if na(out1)
if isUpTrend1
out1 := math.min(out1, bar_index == 1 ? low[1] : math.min(low[1], low[2]))
out1
else
out1 := math.max(out1, bar_index == 1 ? high[1] : math.max(high[1], high[2]))
out1
[out1, acc1, maxMin1, isUpTrend1]
start1 = input(0)
increment1 = input(0.01)
maximum1 = input(0.1)
[p1, AF1, EP1, isUpTrend1] = psar(start1, increment1, maximum1)
newEP1 = EP1 != EP1[1]
epNew1 = newEP1 ? EP1 : na
plot(p1, 'Trend-1', style=plot.style_cross, color=isUpTrend1 ? color.rgb(76, 175, 79, 100) : color.rgb(255, 82, 82, 100), linewidth=2)
//plot(EP1, 'ONAY', style=plot.style_circles, color=isUpTrend1 ? color.green : color.red, linewidth=2)
plot(epNew1, 'Trend-2', style=plot.style_linebr, color=isUpTrend1 ? color.rgb(76, 175, 79, 100) : color.rgb(255, 82, 82, 100), linewidth=2)
///////////////Parabolic Sar ortalamaları ile onaylama sistemidir...///////////////////////////////////////////
//////////////////////////////////////////////Alarmlı Kısa-orta ve uzun reverse sistemidir............///////////////
requestSecurity(string _symbol, string _res, bool _repaints) =>
repIndex = _repaints ? 0 : barstate.isrealtime ? 1 : 0
resIndex = _repaints ? 0 : barstate.isrealtime ? 0 : 1
[h, l, t] = request.security(_symbol, _res, [high[repIndex], low[repIndex], time[repIndex]])
[h[resIndex], l[resIndex], t[resIndex]]
var GRP1 = "General Settings"
string res = input.timeframe(title = "Resolution", defval = "", group = GRP1)
bool ignoreInsideBars = input.bool(title = "Ignore Inside Bars?", defval = true, group = GRP1)
bool rep = input.bool(title = "Allow Repainting?", defval = false, group = GRP1)
var string GRP2 = "Short Term Settings"
bool showSTHighs = input.bool(title = "Show Short Term Highs?", defval = true, group = GRP2)
color stHighsColor = input.color(color.yellow, "Short Term Highs Color", group = GRP2)
bool showSTLows = input.bool(title = "Show Short Term Lows?", defval = true, group = GRP2)
color stLowsColor = input.color(color.yellow, "Short Term Lows Color", group = GRP2)
var string GRP3 = "Mid Term Settings"
bool showMTHighs = input.bool(title = "Show Mid Term Highs?", defval = true, group = GRP3)
color mtHighsColor = input.color(color.aqua, "Mid Term Highs Color", group = GRP3)
bool showMTLows = input.bool(title = "Show Mid Term Lows?", defval = true, group = GRP3)
color mtLowsColor = input.color(color.aqua, "Mid Term Lows Color", group = GRP3)
var string GRP4 = "Long Term Settings"
bool showLTHighs = input.bool(title = "Show Long Term Highs?", defval = true, group = GRP4)
color ltHighsColor = input.color(color.white, "Long Term Highs Color", group = GRP4)
bool showLTLows = input.bool(title = "Show Long Term Lows?", defval = true, group = GRP4)
color ltLowsColor = input.color(color.white, "Long Term Lows Color", group = GRP4)
[h, l, t] = requestSecurity(syminfo.ticker, res, rep)
type ReversalPoint
int bar_time
float price
var lowShortRevPoints = array.new<ReversalPoint>()
var highShortRevPoints = array.new<ReversalPoint>()
var lowMediumRevPoints = array.new<ReversalPoint>()
var highMediumRevPoints = array.new<ReversalPoint>()
isReversalPoint(bool isLow, float firstSrc, float midSrc, float lastSrc, bool isInsideBar) =>
bool isReversalPoint = false
if not (isInsideBar and ignoreInsideBars)
if isLow
isReversalPoint := lastSrc > midSrc and midSrc < firstSrc
else
isReversalPoint := lastSrc < midSrc and midSrc > firstSrc
isReversalPoint
plotReversalPoint(bool isLow, ReversalPoint revPoint, color revPointColor, string labelSize, bool createLabel) =>
if createLabel
label.new(revPoint.bar_time, revPoint.price, isLow ? '▲' : '▼',
xloc = xloc.bar_time, yloc = isLow ? yloc.belowbar : yloc.abovebar, size = labelSize, color = color(na),
textcolor = revPointColor, style = label.style_text_outline)
getReversalPoints(bool isLow, ReversalPoint[] sourceArray, color plotColor, ReversalPoint newRp, string labelSize,
bool createLabel, bool isInsideBar) =>
ReversalPoint result = na
sourceArray.push(newRp)
plotReversalPoint(isLow, newRp, plotColor, labelSize, createLabel)
int arraySize = sourceArray.size()
float midArrayValue = arraySize >= 2 ? sourceArray.get(arraySize - 2).price : na
float firstArrayValue = arraySize >= 3 ? sourceArray.get(arraySize - 3).price : na
if not na(firstArrayValue) and not na(midArrayValue) and isReversalPoint(isLow, firstArrayValue, midArrayValue, newRp.price, isInsideBar)
result := sourceArray.get(arraySize - 2)
result
bool isInsideBar = h < nz(h[1]) and l > nz(l[1])
ReversalPoint shortTermLow = isReversalPoint(true, nz(l[2]), nz(l[1]), l, isInsideBar) ? ReversalPoint.new(nz(t[1]), nz(l[1])) : na
ReversalPoint midTermLow = na
ReversalPoint longTermLow = na
if not na(shortTermLow)
midTermLow := getReversalPoints(true, lowShortRevPoints, stLowsColor, shortTermLow, size.tiny, showSTLows, isInsideBar)
if not na(midTermLow)
longTermLow := getReversalPoints(true, lowMediumRevPoints, mtLowsColor, midTermLow, size.small, showMTLows, isInsideBar)
if not na(longTermLow)
plotReversalPoint(true, longTermLow, ltLowsColor, size.normal, showLTLows)
ReversalPoint shortTermHigh = isReversalPoint(false, nz(h[2]), nz(h[1]), h, isInsideBar) ? ReversalPoint.new(nz(t[1]), nz(h[1])) : na
ReversalPoint midTermHigh = na
ReversalPoint longTermHigh = na
if not na(shortTermHigh)
midTermHigh := getReversalPoints(false, highShortRevPoints, stHighsColor, shortTermHigh, size.tiny, showSTHighs, isInsideBar)
if not na(midTermHigh)
longTermHigh := getReversalPoints(false, highMediumRevPoints, mtHighsColor, midTermHigh, size.small, showMTHighs, isInsideBar)
if not na(longTermHigh)
plotReversalPoint(false, longTermHigh, ltHighsColor, size.normal, showLTHighs)
alertcondition(not na(midTermLow) or not na(longTermLow), "Strong Buy Signal", "Strong Bullish Change Detected")
alertcondition(not na(midTermHigh) or not na(longTermHigh), "Strong Sell Signal", "Strong Bearish Change Detected")
alertcondition(not na(shortTermLow), "Buy Signal", "Bullish Change Detected")
alertcondition(not na(shortTermHigh), "Sell Signal", "Bearish Change Detected")
alertcondition(not na(shortTermLow) or not na(midTermLow) or not na(longTermLow), "All Buy Signals", "Any Bullish Change Detected")
alertcondition(not na(shortTermHigh) or not na(midTermHigh) or not na(longTermHigh), "All Sell Signals", "Any Bearish Change Detected")
///////////////////////////////////Kırılım çizgileri.....////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ma(sourcexz, lengthxz, type) =>
switch type
"SMA" => ta.sma(sourcexz, lengthxz)
"EMA" => ta.ema(sourcexz, lengthxz)
"SMMA (RMA)" => ta.rma(sourcexz, lengthxz)
"WMA" => ta.wma(sourcexz, lengthxz)
"VWMA" => ta.vwma(sourcexz, lengthxz)
factorxz= input(0.004)
lengthxz = input(20)
maTypeInput = input.string("EMA", title="MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
logHigh = math.log10(high)
logLow = math.log10(low)
logAvg = math.log10((high + low) / 2)
logUpperband = ma(logHigh * (1 + 2 * (((logHigh - logLow) / (logAvg)) * 1000) * factorxz), lengthxz, maTypeInput)
logLowerband = ma(logLow * (1 - 2 * (((logHigh - logLow) / (logAvg)) * 1000) * factorxz), lengthxz, maTypeInput)
logCentral = (logUpperband + logLowerband) / 2
Upperbandxz = math.pow(10, logUpperband)
Centralxz = math.pow(10, logCentral)
Lowerbandxz = math.pow(10, logLowerband)
//plot(Upperbandxz, title="Olası-Tepe", color=color.rgb(255, 82, 82, 100))
//plot(Centralxz,title="Olası-Ort", color=color.rgb(255, 153, 0, 100))
//plot(Lowerbandxz,title="Olası-Dip", color=color.rgb(76, 175, 79, 100))
draw_prediction = input.bool(true, title="Draw Prediction Lines")
slope_length = input(20, title = "Slope Length")
customLogarithmicRegression(_data, _color) =>
logData = math.log10(_data)
linreg = ta.linreg(logData, slope_length, 0)
linreg_p = ta.linreg(logData, slope_length, 0 + 1)
xxz = bar_index
slope = linreg - linreg_p
intercept = linreg - xxz * slope
deviationSum = 0.0
for i = 0 to slope_length - 1 by 1
deviationSum += math.pow(logData[i] - (slope * (xxz - i) + intercept), 2)
deviation = math.sqrt(deviationSum / slope_length)
x1 = xxz - slope_length
x2 = xxz
y1 = slope * (xxz - slope_length) + intercept
y2 = linreg
var line b = na
updating = timestamp("20 Jul 2050 00:00 +0300") >= time
displacement = false
if draw_prediction
if updating
b := line.new(x1, math.pow(10, y1), x2, math.pow(10, y2), xloc.bar_index, extend.right, _color, style=line.style_dotted, width=2)
if not displacement
line.delete(b[1])
customLogarithmicRegression(Upperbandxz, color.red)
customLogarithmicRegression(Centralxz, color.orange)
customLogarithmicRegression(Lowerbandxz, color.green)
/////////////////////////////////////////////////////////////
// INPUTS //
//
startq = input(0)
incrementq = input(0.01)
maximumq = input(0.1)
s1q = ta.sar(startq, incrementq, maximumq)
pcq = close < s1q ? color.red : color.green
//plot(s1q, style=plot.style_line, color=pcq)
//
lookBackq = input(20)
//
multiq = input.float(2, title='Multiplier', minval=0.001, maxval=2)
meanq = ta.ema(s1q, lookBackq)
stddevq = multiq * ta.stdev(s1q, lookBackq)
bq = meanq + stddevq
s2q = meanq - stddevq
low1q = ta.crossover(s1q, s2q)
high1q = ta.crossunder(s1q, bq)
plotshape(low1q, title='low', text='DİP', color=color.new(color.green, 0), style=shape.labelup, location=location.belowbar, size=size.tiny, textcolor=color.new(color.white, 0)) //plot for buy icon
plotshape(high1q, title='high', text='TEPE', color=color.new(color.red, 0), style=shape.labeldown, location=location.abovebar, size=size.tiny, textcolor=color.new(color.white, 0)) //plot for sell icon
//////////////////
lenxc = input(5)
lenxc20 = input(20)
lenxc50 = input(50)
z(close, lenxc) =>
hxc = 0.0
dxc = 0.0
for i = 0 to lenxc - 1 by 1
kxc = (lenxc - i) * lenxc
hxc += kxc
dxc += close[i] * kxc
dxc
dxc / hxc
cxc = z(close, math.floor(math.sqrt(lenxc)))
//
z20(close, lenxc20) =>
hcx20 = 0.0
dxc20 = 0.0
for i = 0 to lenxc20 - 1 by 1
kxc20 = (lenxc20 - i) * lenxc20
hcx20 += kxc20
dxc20 += close[i] * kxc20
dxc20
dxc20 / hcx20
cxc20 = z20(close, math.floor(math.sqrt(lenxc20)))
//
z50(close, lenxc50) =>
hxc50 = 0.0
dxc50 = 0.0
for i = 0 to lenxc50 - 1 by 1
kxc50 = (lenxc50 - i) * lenxc50
hxc50 += kxc50
dxc50 += close[i] * kxc50
dxc50
dxc50 / hxc50
cxc50 = z50(close, math.floor(math.sqrt(lenxc50)))
//
//
startsx = 0
incrementsx = 0.01
maximumsx = 0.1
ssx = ta.sar(startsx, incrementsx, maximumsx)
s1sx = z(ssx, lenxc)
pcsx = close < s1sx ? color.red : color.green
plot(s1sx, title="5",style=plot.style_cross, color=pcsx, linewidth=1)
startsx20 = 0
incrementsx20 = 0.01
maximumsx20 = 0.1
ssx20 = ta.sar(startsx20, incrementsx20, maximumsx20)
s1sx20 = z20(ssx20, lenxc20)
pcsx20 = close < s1sx20 ? color.red : color.green
plot(s1sx20, title="20",style=plot.style_cross, color=pcsx20, linewidth=1)
startsx50 = 0
incrementsx50 = 0.01
maximumsx50 = 0.1
ssx50 = ta.sar(startsx50, incrementsx50, maximumsx50)
s1sx50 = z50(ssx50, lenxc50)
pcsx50 = close < s1sx50 ? color.red : color.green
plot(s1sx50, title="50",style=plot.style_cross, color=pcsx50, linewidth=1)
//////////////////////////