ortaya karışık bir kombine kod çalışması....
emalar saatliktir...
örnek görüntü....PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carefulCode53358
//@version=5
indicator(".", overlay = true)
//Trend Sar
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, 'SAR', style=plot.style_stepline, color=isUpTrend1 ? color.rgb(76, 175, 79, 100) : color.rgb(255, 82, 82, 100), linewidth=1)
//plot(EP1, 'ONAY', style=plot.style_circles, color=isUpTrend1 ? color.green : color.red, linewidth=2)
plot(epNew1, 'Trend-Continue', style=plot.style_line, color=isUpTrend1 ? color.rgb(76, 175, 79, 00) : color.rgb(255, 82, 82, 00), linewidth=1)
//Signal
xyz=ta.crossunder(epNew1,p1)
plotshape(xyz? epNew1:na, style=shape.circle, location=location.abovebar, color=isUpTrend1 ? color.rgb(34, 247, 6) : color.rgb(247, 3, 3), size=size.small)
xyz1=ta.crossover(epNew1,p1)
plotshape(xyz1? epNew1:na, style=shape.circle, location=location.belowbar, color=isUpTrend1 ? color.rgb(34, 247, 6) : color.rgb(247, 3, 3), size=size.small)
//END
//Function
inp = input(title='Source', defval=close)
res = input.timeframe(title='Resolution', defval='')
rep = input(title='Allow Repainting?', defval=false)
//////////////////////////////////////////////////////
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.lime : sig1 > 0 ? color.lime : sig1 < -1 ? color.red : sig1 < 0 ? color.red : color.white
plot(pMacdEq1, title='Trend',style=plot.style_cross, color=rmacdColor, linewidth=2)
plot(pMacdEqSig1, title='Stop', color=color.rgb(255, 255, 255, 100), linewidth=1)
//plot(pMacdLevel1, title='MacdLevel', color=color.blue, linewidth=2)
xyzx=(pMacdEq1+pMacdEqSig1+pMacdLevel1)/3
//plot(xyzx, title='Avarage', color=color.rgb(241, 225, 8, 100), linewidth=2)
////////////////////////////////////////////////////////////////////////////
// FINAL CALCULATION
reverseUP = ta.crossunder(epNew1,xyzx)
reverseDOWN =ta.crossover(epNew1,xyzx)
plotshape(reverseUP , 'reverse UP',shape.triangledown , location.abovebar , color.red,size = size.normal)
plotshape(reverseDOWN , 'reverse DOWN',shape.triangleup , location.belowbar , color.lime,size = size.normal)
//////////Emalar günlük
price = request.security(syminfo.tickerid, "60", close)
EMA_5 = ta.ema(price, 5)
EMA_13 = ta.ema(price, 13)
EMA_26 = ta.ema(price, 26)
EMA_50 = ta.ema(price, 50)
EMA_100 = ta.ema(price, 100)
EMA_200 = ta.ema(price, 200)
plot(EMA_5,"5 EMA",color.rgb(243, 141, 7, 100), 1)
//plot(EMA_13,"13 EMA",color.rgb(243, 7, 243, 100), 1)
//plot(EMA_26,"26 EMA",color.rgb(243, 7, 243, 100), 1)
//plot(EMA_50,"50 EMA",color.rgb(243, 7, 243, 100), 1)
//plot(EMA_100,"100 EMA",color.rgb(243, 7, 243, 100), 1)
plot(EMA_200,"200 EMA", color.rgb(243, 141, 7, 100), 1)
///////////////
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
factor= input(0.001382)
length = input(100)
mult = input.float(0.382, title="Mult")
show_middle_bands = input.bool(true, title="Show Middle Bands")
show_upper_bands = input.bool(true, title="Show Upper Bands")
maTypeInput = input.string("EMA", title="Band MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
middleTypeInput = input.string("EMA", title="Middle MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
logHigh = math.log10(high)
logLow = math.log10(low)
logClose = math.log10(close)
logAvg = math.log10((high + low) / 2)
logUppestband = ma(logHigh * (1 + 2 * (((logHigh - logLow) / (logAvg)) * 1000) * factor * (1+mult)), length, maTypeInput)
logUpperband = ma(logHigh * (1 + 2 * (((logHigh - logLow) / (logAvg)) * 1000) * factor), length, maTypeInput)
logLowerband = ma(logLow * (1 - 2 * (((logHigh - logLow) / (logAvg)) * 1000) * factor), length, maTypeInput)
logLowestband = ma(logLow * (1 - 2 * (((logHigh - logLow) / (logAvg)) * 1000) * factor / (1-mult)), length, maTypeInput)
logCentral = ma(logClose, length, middleTypeInput)
Uppestband = math.pow(10, logUppestband)
Upperband = math.pow(10, logUpperband)
Central = math.pow(10, logCentral)
Lowerband = math.pow(10, logLowerband)
Lowestband = math.pow(10, logLowestband)
//plot(Uppestband, color=color.red, linewidth=2, display=show_upper_bands ? display.all : display.none)
//plot(Upperband, color=color.red, linewidth=1, display=show_middle_bands ? display.all : display.none)
//plot(Central, color=color.orange, linewidth=1, display=show_middle_bands ? display.all : display.none)
//plot(Lowerband, color=color.green, linewidth=1, display=show_middle_bands ? display.all : display.none)
//plot(Lowestband, color=color.green, linewidth=2, display=show_upper_bands ? display.all : display.none)
draw_prediction = input.bool(true, title="Draw Prediction Lines")
slope_length_type = input.bool(true, title="Use Fixed Slope Length?")
fixed_slope_length = input(55, title = "Slope Length") // Useful for Prediction Upto Next (80% * Slope Length) Candles
slope_length = slope_length_type ? fixed_slope_length : last_bar_index - length
customLogarithmicRegression(_data, _color, _width) =>
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=_width)
if not displacement
line.delete(b[1])
if show_upper_bands
customLogarithmicRegression(Uppestband, color.rgb(1, 219, 248), 2)
customLogarithmicRegression(Lowestband, color.rgb(2, 219, 248), 2)
if show_middle_bands
//customLogarithmicRegression(Upperband, color.red, 1)
customLogarithmicRegression(Central, color.rgb(2, 221, 250), 1)
//customLogarithmicRegression(Lowerband, color.green, 1)
///////
//@version=5
lengthx = input.int(55, title="Length", minval = 1, maxval = 5000)
src = input.source(close, title="Source")
// ----------------------------------------------------------------------
upper_1_bool_input = input.bool(false, title="Upper +1", inline="abc", group = "channel")
upper_1_float_input = input.float(1.0, title="", inline="abc", group = "channel")
upper_2_bool_input = input.bool(false, title="Upper +2", inline="cde", group = "channel")
upper_2_float_input = input.float(2.0, title="", inline="cde", group = "channel")
upper_3_bool_input = input.bool(false, title="Upper +3", inline="ghi", group = "channel")
upper_3_float_input = input.float(3.0, title="", inline="ghi", group = "channel")
lower_1_bool_input = input.bool(false, title="Lower -1", inline="bcd", group = "channel")
lower_1_float_input = input.float(1.0, title="", inline="bcd", group = "channel")
lower_2_bool_input = input.bool(false, title="Lower -2", inline="def", group = "channel")
lower_2_float_input = input.float(2.0, title="", inline="def", group = "channel")
lower_3_bool_input = input.bool(false, title="Lower +3", inline="hij", group = "channel")
lower_3_float_input = input.float(3.0, title="", inline="hij", group = "channel")
// ----------------------------------------------------------------------
color_upper_1 = input.color(color.new(#535455, 90), "", inline = "colors", group = "colors")
color_upper_2 = input.color(color.new(#4caf4f, 100), "", inline = "colors", group = "colors")
color_upper_3 = input.color(color.new(#ff5252, 100), "", inline = "colors", group = "colors")
color_lower_1 = input.color(color.new(#535455, 90), "", inline = "colors", group = "colors")
color_lower_2 = input.color(color.new(#4caf4f, 100), "", inline = "colors", group = "colors")
color_lower_3 = input.color(color.new(#ff5252, 100), "", inline = "colors", group = "colors")
// ----------------------------------------------------------------------
visual_settings_group = "Visual Settings"
prinp = input.bool(false, "Show Pearson's R", group = visual_settings_group)
exl = input.bool(false, "Extend Lines Left", group = visual_settings_group)
exr = input.bool(true, "Extend Lines Right", group = visual_settings_group)
exs = switch
exl and exr => extend.both
exl => extend.left
exr => extend.right
=> extend.none
// ----------------------------------------------------------------------
slpclc(source, lengthx) =>
max_bars_back(source, 5000)
if not barstate.islast or lengthx <= 1
[float(na), float(na), float(na)]
else
sumX = 0.0
sumY = 0.0
sumXSqr = 0.0
sumXY = 0.0
for i = 0 to lengthx - 1 by 1
val = source[i]
per = i + 1.0
sumX += per
sumY += val
sumXSqr += per * per
sumXY += val * per
slope = (lengthx * sumXY - sumX * sumY) / (lengthx * sumXSqr - sumX * sumX)
average = sumY / lengthx
intercept = average - slope * sumX / lengthx + slope
[slope, average, intercept]
// ----------------------------------------------------------------------
[s, a, i] = slpclc(src, lengthx)
st_price = i + s * (lengthx - 1)
end_price = i
base_line = line.new(bar_index - lengthx + 1, st_price, bar_index, end_price, width=1, extend=exs, style=line.style_dashed, color=color.new(color.orange, 0))
// ----------------------------------------------------------------------
devcalc(source, lengthx, slope, average, intercept) =>
upDev = 0.0
dnDev = 0.0
stdDevAcc = 0.0
dsxx = 0.0
dsyy = 0.0
dsxy = 0.0
periods = lengthx - 1
daY = intercept + slope * periods / 2
val = intercept
for j = 0 to periods by 1
price = high[j] - val
if price > upDev
upDev := price
price := val - low[j]
if price > dnDev
dnDev := price
price := source[j]
dxt = price - average
dyt = val - daY
price -= val
stdDevAcc += price * price
dsxx += dxt * dxt
dsyy += dyt * dyt
dsxy += dxt * dyt
val += slope
stdDev = math.sqrt(stdDevAcc / (periods == 0 ? 1 : periods))
pearsonR = dsxx == 0 or dsyy == 0 ? 0 : dsxy / math.sqrt(dsxx * dsyy)
[stdDev, pearsonR, upDev, dnDev]
// ----------------------------------------------------------------------
[stdDev, pearsonR, upDev, dnDev] = devcalc(src, lengthx, s, a, i)
// ----------------------------------------------------------------------
create_line(bool_input, float_input, color, dev) =>
line_start_price = st_price + (bool_input ? float_input * stdDev : dev)
line_end_price = end_price + (bool_input ? float_input * stdDev : dev)
line.new(bar_index - lengthx + 1, line_start_price, bar_index, line_end_price, width=1, style=line.style_dashed, extend=exs, color=color.new(color, 0))
// ----------------------------------------------------------------------
upper_1_line = create_line(upper_1_bool_input, upper_1_float_input, color_upper_1, upDev)
//upper_2_line = create_line(upper_2_bool_input, upper_2_float_input, color_upper_2, upDev)
//upper_3_line = create_line(upper_3_bool_input, upper_3_float_input, color_upper_3, upDev)
lower_1_line = create_line(lower_1_bool_input, -lower_1_float_input, color_lower_1, -dnDev)
//lower_2_line = create_line(lower_2_bool_input, -lower_2_float_input, color_lower_2, -dnDev)
//lower_3_line = create_line(lower_3_bool_input, -lower_3_float_input, color_upper_3, -dnDev)
// ----------------------------------------------------------------------
linefill.new(upper_1_line, base_line, color = color_upper_1)
linefill.new(lower_1_line, base_line, color = color_lower_1)
// ----------------------------------------------------------------------
https://i.hizliresim.com/rxjglfq.png