Eblicious

 avatar
EBTURK
plain_text
a year ago
6.3 kB
69
Indexable
//@version=5
indicator("Eblicious", shorttitle="MA", overlay=true, precision=3, timeframe = "", timeframe_gaps = true)

// Input Settings 1
src1 = input(high, title="Source 1")
a1 = input.float(0.07, title="Alpha 1", step=0.01)
mul1 = input.float(6.6, title="Multiplier 1", step=0.1)
amaLength1 = input.int(20, title="AMA Length 1")
len1 = input.int(3, title="Length 1")
smo1 = input.int(20, title="Filter RMS 1")
lel1 = input.int(14, title="Lin Reg Length 1")
olr1 = input.int(3, title="Offset Lin Reg 1")

var float ip1 = na
var float p1 = na
var float dp1 = na

s1 = (src1 + 2 * src1[1] + 2 * src1[2] + src1[3]) / 6.0
var float c1 = na
if (bar_index < 7)
    c1 := (src1 - 2 * src1[1] + src1[2]) / 4.0
else
    c1 := ((1 - 0.5 * a1) * (1 - 0.5 * a1) * (s1 - 2 * s1[1] + s1[2]) + 2 * (1 - a1) * c1[1] - (1 - a1) * (1 - a1) * c1[2])
q11 = (0.0962 * c1 + 0.5769 * c1[2] - 0.5769 * c1[4] - 0.0962 * c1[6]) * (0.5 + 0.08 * nz(ip1[1]))
I11 = c1[3]
dp_1 = q11 != 0 and q11[1] != 0 ? (I11 / q11 - I11[1] / q11[1]) / (1 + I11 * I11[1] / (q11 * q11[1])) : 0
dp1 := dp_1 < 0.1 ? 0.1 : dp_1 > 1.1 ? 1.1 : dp_1
med1(x, y, z) => (x + y + z) - math.min(x, math.min(y, z)) - math.max(x, math.max(y, z))
md1 = med1(dp1, dp1[1], med1(dp1[2], dp1[3], dp1[4]))
dc1 = md1 == 0 ? 15 : 6.28318 / md1 + 0.5
ip1 := 0.33 * dc1 + 0.67 * nz(ip1[1])
p1 := 0.15 * ip1 + 0.85 * nz(p1[1])

// Input Settings 2
src2 = input(low, title="Source 2")
a2 = input.float(0.07, title="Alpha 2", step=0.01)
mul2 = input.float(7, title="Multiplier 2", step=0.1)
amaLength2 = input.int(20, title="AMA Length 2")
len2 = input.int(3, title="Length 2")
smo2 = input.int(20, title="Filter RMS 2")
lel2 = input.int(14, title="Lin Reg Length 2")
olr2 = input.int(3, title="Offset Lin Reg 2")

var float ip2 = na
var float p2 = na
var float dp2 = na

s2 = (src2 + 2 * src2[1] + 2 * src2[2] + src2[3]) / 6.0
var float c2 = na
if (bar_index < 7)
    c2 := (src2 - 2 * src2[1] + src2[2]) / 4.0
else
    c2 := ((1 - 0.5 * a2) * (1 - 0.5 * a2) * (s2 - 2 * s2[1] + s2[2]) + 2 * (1 - a2) * c2[1] - (1 - a2) * (1 - a2) * c2[2])
q22 = (0.0962 * c2 + 0.5769 * c2[2] - 0.5769 * c2[4] - 0.0962 * c2[6]) * (0.5 + 0.08 * nz(ip2[1]))
I22 = c1[3]
dp_2 = q22 != 0 and q22[1] != 0 ? (I22 / q22 - I22[1] / q22[1]) / (1 + I22 * I22[1] / (q22 * q22[1])) : 0
dp2 := dp_2 < 0.1 ? 0.1 : dp_2 > 1.1 ? 1.1 : dp_2
med2(x, y, z) => (x + y + z) - math.min(x, math.min(y, z)) - math.max(x, math.max(y, z))
md2 = med2(dp2, dp2[1], med2(dp2[2], dp2[3], dp2[4]))
dc2 = md2 == 0 ? 15 : 6.28318 / md2 + 0.5
ip2 := 0.33 * dc2 + 0.67 * nz(ip2[1])
p2 := 0.15 * ip2 + 0.85 * nz(p2[1])

// Calculations 1
diff1 = math.abs(src1 - src1[1])
signal1 = math.abs(src1 - hlc3)
noise1 = ta.sma(diff1, amaLength1)
efratio1 = noise1 != 0 ? signal1 / noise1 : 1
EF1 = efratio1

TrueRange1 = math.max(math.max(high-low, math.abs(high-nz(close[1]))), math.abs(low-nz(close[1])))
DirectionalMovementPlus1 = high - nz(high[1]) > nz(low[1]) - low ? math.max(high - nz(high[1]), 0) : 0
DirectionalMovementMinus1 = nz(low[1]) - low > high - nz(high[1]) ? math.max(nz(low[1]) - low, 0) : 0

SmoothedTrueRange1 = ta.ema(TrueRange1, len1)
SmoothedDirectionalMovementPlus1 = ta.ema(DirectionalMovementPlus1, len1)
SmoothedDirectionalMovementMinus1 = ta.ema(DirectionalMovementMinus1, len1)

DIPlus1 = SmoothedDirectionalMovementPlus1 / SmoothedTrueRange1 * 100
DIMinus1 = SmoothedDirectionalMovementMinus1 / SmoothedTrueRange1 * 100
DX1 = 1 - (math.abs(DIPlus1 - DIMinus1) / (DIPlus1 + DIMinus1))
ADX1 = ta.sma(DX1, len1)

ER1 = (1 - efratio1) * ADX1
SC1 = (ER1 * (a1 - a2) + a2)
RMSa1 = ta.sma(SC1 * SC1, smo1)
var float out1 = na
RMS1 = math.sqrt(RMSa1 / smo1) * mul1
out1 := nz(out1[1]) + RMS1 * (src1 - nz(out1[1]))
lr1 = ta.linreg(out1, lel1, olr1)

// Calculations 2
diff2 = math.abs(src2 - src2[1])
signal2 = math.abs(src2 - hlc3)
noise2 = ta.sma(diff2, amaLength2)
efratio2 = noise2 != 0 ? signal2 / noise2 : 1
EF2 = efratio2

TrueRange2 = math.max(math.max(high-low, math.abs(high-nz(close[1]))), math.abs(low-nz(close[1])))
DirectionalMovementPlus2 = high - nz(high[1]) > nz(low[1]) - low ? math.max(high - nz(high[1]), 0) : 0
DirectionalMovementMinus2 = nz(low[1]) - low > high - nz(high[1]) ? math.max(nz(low[1]) - low, 0) : 0

SmoothedTrueRange2 = ta.ema(TrueRange2, len2)
SmoothedDirectionalMovementPlus2 = ta.ema(DirectionalMovementPlus2, len2)
SmoothedDirectionalMovementMinus2 = ta.ema(DirectionalMovementMinus2, len2)

DIPlus2 = SmoothedDirectionalMovementPlus2 / SmoothedTrueRange2 * 100
DIMinus2 = SmoothedDirectionalMovementMinus2 / SmoothedTrueRange2 * 100
DX2 = 1 - (math.abs(DIPlus2 - DIMinus2) / (DIPlus2 + DIMinus2))
ADX2 = ta.sma(DX2, len2)

ER2 = (1 - efratio2) * ADX2
SC2 = (ER2 * (a1 - a2) + a2)
RMSa2 = ta.sma(SC2 * SC2, smo2)
var float out2 = na
RMS2 = math.sqrt(RMSa2 / smo2) * mul2
out2 := nz(out2[1]) + RMS2 * (src2 - nz(out2[1]))
lr2 = ta.linreg(out2, lel2, olr2)

// Plots
col1 = out1 > lr1 ? color.lime : color.red
l1 = plot(lr1, color=color.silver, title="Reg Lin 1", linewidth=1)
o1 = plot(out1, color=col1, title="MA 1", linewidth=2)
fill(l1, o1, color=col1, transp=70)

// Plots2
col2 = out2 > lr2 ? color.lime : color.red
l2 = plot(lr2, color=color.silver, title="Reg Lin 2", linewidth=1)
o2 = plot(out2, color=col2, title="MA 2", linewidth=2)
fill(l2, o2, color=col2, transp=70)

// Buy and Sell Conditions
buyCondition1 = ta.crossover(out1, lr1)
sellCondition1 = ta.crossunder(out1, lr1)
//
buyCondition2 = ta.crossover(out2, lr2)
sellCondition2 = ta.crossunder(out2, lr2)
alertcondition(buyCondition1, title="Buy Alert 1", message="BUY 1")
alertcondition(sellCondition1, title="Sell Alert 1", message="SELL 1")
alertcondition(buyCondition2, title="Buy Alert 2", message="BUY 2")
alertcondition(sellCondition2, title="Sell Alert 2", message="SELL 2")

plotshape(buyCondition1, title="Buy Label 1", location=location.belowbar, color=color.lime, style=shape.labelup, text="B1")
plotshape(sellCondition1, title="Sell Label 1", location=location.abovebar, color=color.red, style=shape.labeldown, text="S1")
plotshape(buyCondition2, title="Buy Label 2", location=location.belowbar, color=color.lime, style=shape.labelup, text="B2")
plotshape(sellCondition2, title="Sell Label 2", location=location.abovebar, color=color.red, style=shape.labeldown, text="S2")
Editor is loading...