# convert_momenta_smoothes_00
#https://usethinkscript.com/threads/convert-tradingview-double-smoothed-momenta.14299/
#Tradingview Convert Tradingview Double Smoothed Momenta
#https://www.tradingview.com/script/WDGZQHGf-Double-Smoothed-Momenta/
declare lower;
#//@version=4
#// Copyright (c) 2019-present, Franklin Moormann (cheatcountry)
#// Double Smoothed Momenta [CC] script may be freely distributed under the MIT license.
#study("Double Smoothed Momenta [CC]", overlay=false)
#inp = input(title="Source", type=input.source, defval=close)
#res = input(title="Resolution", type=input.resolution, defval="")
#rep = input(title="Allow Repainting?", type=input.bool, defval=false)
#bar = input(title="Allow Bar Color Change?", type=input.bool, defval=true)
#src = security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
#aLength = input(title="ALength", type=input.integer, defval=2, minval=1)
#yLength = input(title="YLength", type=input.integer, defval=5, minval=1)
#zLength = input(title="ZLength", type=input.integer, defval=25, minval=1)
def inp = close;
def res = 0; # 2nd agg
input rep = no;
input bar = yes;
def src = close;
input aLength = 2;
input yLength = 5;
input zLength = 25;
#hc = highest(src, aLength)
#lc = lowest(src, aLength)
#top = ema(ema(src - lc, yLength), zLength)
#bot = ema(ema(hc - lc, yLength), zLength)
#mom = bot != 0 ? 100 * top / bot : 0
#momEma = ema(mom, zLength)
def hc = highest(src, aLength);
def lc = lowest(src, aLength);
def top = ExpAverage(ExpAverage(close - lc, yLength), zLength);
def bot = ExpAverage(ExpAverage(hc - lc, yLength), zLength);
def mom = if bot != 0 then (100 * top / bot) else 0;
def momEma = ExpAverage(mom, zLength);
#sig = mom > momEma ? 1 : mom < momEma ? -1 : 0
#alertcondition(crossover(sig, 0), "Buy Signal", "Bullish Change Detected")
#alertcondition(crossunder(sig, 0), "Sell Signal", "Bearish Change Detected")
#momColor = sig > 0 ? color.green : sig < 0 ? color.red : color.black
#barcolor(bar ? momColor : na)
#plot(mom, color=momColor, linewidth=2)
#plot(momEma, color=color.black, linewidth=1)
def sig = if (mom > momEma) then 1 else if mom < momEma then -1 else 0;
plot z1 = mom;
z1.AssignValueColor( if !bar then color.gray
else if sig > 0 then color.green
else if sig < 0 then color.red
else color.black);
plot z2 = momEma;
z2.SetDefaultColor(Color.cyan);
def alertup = sig crosses above 0;
def alertdwn = sig crosses below 0;
alert(alertup, "Buy Signal", alert.BAR, sound.DING);
alert(alertdwn, "Sell Signal", alert.BAR, sound.bell);
#