@MLlalala
@jpmcewen
convert pine study from here
https://www.tradingview.com/script/WkBFJbJD-Natural-Moving-Average-CC/
@jpmcewen
convert pine study from here
https://www.tradingview.com/script/WkBFJbJD-Natural-Moving-Average-CC/
Code:
# Natural_Moving_Average_00
#//@version=4
#// Copyright (c) 2019-present, Franklin Moormann (cheatcountry)
#// Natural Moving Average [CC] script may be freely distributed under the MIT license.
#study("Natural Moving Average [CC]", overlay=true)
#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)
#length = input(title="Length", type=input.integer, defval=40, minval=1)
def bn = barnumber();
def na = double.nan;
input inp = close;
#input res = agg
input rep = no;
input bar = yes;
input length = 40;
#src = security(syminfo.tickerid, res, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
input src = close;
script nz {
input data = 0;
def ret_val = if isNaN(data) then 0 else data;
plot return = ret_val;
}
#ln = log(src) * 1000
def ln = log(src) * 1000;
#num = 0.0
#denom = 0.0
#for i = 0 to length - 1
# oi = abs(nz(ln[i]) - nz(ln[i + 1]))
# num += oi * (sqrt(i + 1) - sqrt(i))
# denom += oi
def num = fold i = 0 to length - 1
with p
while bn > length
do p + (absvalue( (if isNaN(getvalue(ln, i)) then 0 else getvalue(ln, i)) -
(if isNaN(getvalue(ln, i+1)) then 0 else getvalue(ln, i+1)) ))
* (sqrt(i + 1) - sqrt(i));
def denom = fold j = 0 to length - 1
with q
do q + (absvalue( (if isNaN(getvalue(ln, j)) then 0 else getvalue(ln, j)) -
(if isNaN(getvalue(ln, j+1)) then 0 else getvalue(ln, j+1)) ));
#ratio = denom != 0 ? num / denom : 0
def ratio = if denom != 0 then (num / denom) else 0;
#nma = (src * ratio) + (nz(src[1]) * (1 - ratio))
def nma = (src * ratio) + (nz(src[1]) * (1 - ratio));
#slo = src - nma
def slo = src - nma;
#sig = slo > 0 ? slo > nz(slo[1]) ? 2 : 1 : slo < 0 ? slo < nz(slo[1]) ? -2 : -1 : 0
def sig =
if slo > 0 then
if slo > nz(slo[1]) then 2 else 1
else if slo < 0 then
if slo < nz(slo[1]) then -2 else -1
else 0;
#alertcondition(crossover(sig, 1), "Strong Buy Signal", "Strong Bullish Change Detected")
#alertcondition(crossunder(sig, -1), "Strong Sell Signal", "Strong Bearish Change Detected")
#alertcondition(crossover(sig, 0), "Buy Signal", "Bullish Change Detected")
#alertcondition(crossunder(sig, 0), "Sell Signal", "Bearish Change Detected")
#addchartbubble(1, low, sig, color.yellow, no);
def c = if sig == 2 and sig[1] != 2 then 2
else if sig == 1 and sig[1] != 1 then 1
else if sig == -1 and sig[1] != -1 then -1
else if sig == -22 and sig[1] != -2 then -2
else 0;
addlabel(1, " ", color.black);
addlabel(c == 2, "Strong Buy Signal", color.green);
addlabel(c == 1, "Buy Signal", color.light_green);
addlabel(c == -1, "Sell Signal", color.light_red);
addlabel(c == -2, "Strong Sell Signal", color.red);
#nmaColor = sig > 1 ? color.green : sig > 0 ? color.lime : sig < -1 ? color.maroon : sig < 0 ? color.red : color.black
#barcolor(bar ? nmaColor : na)
#plot(nma, color=nmaColor, linewidth=2)
plot z = if bar then nma else na;
z.AssignValueColor(
if sig > 1 then color.green else if sig > 0 then color.lime else if sig < -1 then color.magenta else if sig < 0 then color.red else color.black);
z.setlineweight(2);
z.hidebubble();
#
Last edited: