Trend and Momentum Digi Indicator - TV to ToS conversion

APOT

New member
Platform
  1. Thinkorswim
  2. TradingView
Need help converting this to TOS. Thank you!



Code:
//digiindicator.ir
//@version=5
indicator(title="Trend and Momentum Digi Indicator", shorttitle="TMDI", timeframe="", timeframe_gaps=true)
h1 = hline(2)
h5 = hline(-5)
[_, mac, _] = ta.macd(close, 12, 26, 9)
nrsi= ta.rsi(close,14)
hrsi=ta.highest(nrsi, 10)
lrsi=ta.lowest(nrsi, 10)
mo_g = input.int(title="Buyers", minval=1, maxval=500, defval=21)
mo_r = input.int(title="Sellers", minval=1, maxval=500, defval=34)
h_k = input.int(title="General process", minval=1, maxval=500, defval=144)
ma21 = ta.sma(close,mo_g)
ma34 = ta.sma(close,mo_r)
ma144 = ta.sma(close,h_k)
src = input(title="Source", defval=close)
b3 = ma21>ma34 and src>ma144 and ma144[1]<ma144
b2 = (ma21>ma34 and src>ma144 and ma144[1]>ma144) or (ma21>ma34 and ma144[1]<ma144 and src<ma144)  or (src>ma144 and ma144[1]<ma144 and ma21<ma34)
bsh = (ma21>ma34 and src>ma144) or (ma21>ma34 and ma144[1]<ma144)  or (src>ma144 and ma144[1]<ma144)
s3 = ma21<ma34 and src<ma144 and ma144[1]>ma144
s2 = (ma21<ma34 and src<ma144 and ma144[1]<ma144) or (ma21<ma34 and src>ma144 and ma144[1]>ma144) or (ma21>ma34 and src<ma144 and ma144[1]>ma144)
ssh = (ma21<ma34 and src<ma144) or (ma21<ma34 and ma144[1]>ma144) or ( src<ma144 and ma144[1]>ma144)
tf = if (lrsi<nrsi and nrsi>50) or (hrsi>nrsi and nrsi<50)
    false
else
    true
ft = if (mac>0 and ma21>ma34) or (mac<0 and ma34>ma21)
    false
else
    true
plot(b3?2:na, style=plot.style_columns, color=#2bff00)
plot(b2?1:na, style=plot.style_columns, color=#77dc7f)
plot(s3?-2:na, style=plot.style_columns, color=#ff0000)
plot(s2?-1:na, style=plot.style_columns, color=#eb9c9c)
plot(lrsi<nrsi and nrsi>50?-3:na, style=plot.style_linebr, color=#2bff00)
plot(hrsi>nrsi and nrsi<50?-3:na, style=plot.style_linebr, color=#ff0707)
plot(mac>0 and ma21>ma34?-4:na, style=plot.style_linebr, color=#2bff00)
plot(mac<0 and ma34>ma21?-4:na, style=plot.style_linebr, color=#ff0707)
plot(ft==true?-4:na, style=plot.style_linebr, color=#ffffff)
plot(tf==true?-3:na, style=plot.style_linebr, color=#ffffff)
fill(h1, h5, color= color.new(#8B0000, 90))
 
Last edited by a moderator:

barbaros

Administrator
Staff member
wbzDuAS.png


Code:
# Trend Momentum Digi Inticator
# Converted for https://b4indicators.com/threads/trend-and-momentum-tv-to-tos-conversion-help-needed.278/
# barbaros

declare lower;

plot h1 = 2;
h1.SetDefaultColor(Color.GRAY);
h1.SetPaintingStrategy(PaintingStrategy.DASHES);

plot h5 = -5;
h5.SetDefaultColor(Color.GRAY);
h5.SetPaintingStrategy(PaintingStrategy.DASHES);

def mac = macd(12, 26, 9);
def nrsi = rsi(14);
def hrsi = highest(nrsi, 10);
def lrsi = lowest(nrsi, 10);
def mo_g = 21; # buyers, minval=1, maxval=500, defval=21
def mo_r = 34; # sellers,  minval=1, maxval=500, defval=34
def h_k = 144; # General process, minval=1, maxval=500, defval=144
def ma21 = simpleMovingAvg(close,mo_g);
def ma34 = simpleMovingAvg(close,mo_r);
def ma144 = simpleMovingAvg(close,h_k);
def src = close;
def b3 = ma21>ma34 and src>ma144 and ma144[1]<ma144;
def b2 = (ma21>ma34 and src>ma144 and ma144[1]>ma144) or (ma21>ma34 and ma144[1]<ma144 and src<ma144)  or (src>ma144 and ma144[1]<ma144 and ma21<ma34);
def bsh = (ma21>ma34 and src>ma144) or (ma21>ma34 and ma144[1]<ma144)  or (src>ma144 and ma144[1]<ma144);
def s3 = ma21<ma34 and src<ma144 and ma144[1]>ma144;
def s2 = (ma21<ma34 and src<ma144 and ma144[1]<ma144) or (ma21<ma34 and src>ma144 and ma144[1]>ma144) or (ma21>ma34 and src<ma144 and ma144[1]>ma144);
def ssh = (ma21<ma34 and src<ma144) or (ma21<ma34 and ma144[1]>ma144) or ( src<ma144 and ma144[1]>ma144);
def tf = if (lrsi<nrsi and nrsi>50) or (hrsi>nrsi and nrsi<50) then no else yes;
def ft = if (mac>0 and ma21>ma34) or (mac<0 and ma34>ma21) then no else yes;

plot p_b3 = if b3 then 2 else Double.NaN;
p_b3.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
p_b3.SetDefaultColor(CreateColor(43, 255, 0));
p_b3.SetLineWeight(5);

plot p_b2 = if b2 then 1 else Double.NaN;
p_b2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
p_b2.SetDefaultColor(CreateColor(119, 220, 127));
p_b2.SetLineWeight(5);

plot p_s3 = if s3 then -2 else Double.NaN;
p_s3.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
p_s3.SetDefaultColor(CreateColor(255, 0, 0));
p_s3.SetLineWeight(5);

plot p_s2 = if s2 then -1 else Double.NaN;
p_s2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
p_s2.SetDefaultColor(CreateColor(235, 156, 156));
p_s2.SetLineWeight(5);

plot p_rsi1 = if lrsi<nrsi and nrsi>50 then -3 else Double.NaN;
p_rsi1.SetPaintingStrategy(PaintingStrategy.LINE);
p_rsi1.SetDefaultColor(CreateColor(43, 255, 0));
p_rsi1.SetLineWeight(5);

plot p_rsi2 = if hrsi>nrsi and nrsi<50 then -3 else Double.NaN;
p_rsi2.SetPaintingStrategy(PaintingStrategy.LINE);
p_rsi2.SetDefaultColor(CreateColor(255, 7, 7));
p_rsi2.SetLineWeight(5);

plot p_mac1 = if mac>0 and ma21>ma34 then -4 else Double.NaN;
p_mac1.SetPaintingStrategy(PaintingStrategy.LINE);
p_mac1.SetDefaultColor(CreateColor(43, 255, 0));
p_mac1.SetLineWeight(3);

plot p_mac2 = if mac<0 and ma34>ma21 then -4 else Double.NaN;
p_mac2.SetPaintingStrategy(PaintingStrategy.LINE);
p_mac2.SetDefaultColor(CreateColor(255, 7, 7));
p_mac2.SetLineWeight(3);

plot p_ft1 = if ft == yes then -4 else Double.NaN;
p_ft1.SetPaintingStrategy(PaintingStrategy.LINE);
p_ft1.SetDefaultColor(CreateColor(255, 255, 255));
p_ft1.SetLineWeight(3);

plot p_ft2 = if tf == yes then -3 else Double.NaN;
p_ft2.SetPaintingStrategy(PaintingStrategy.LINE);
p_ft2.SetDefaultColor(CreateColor(255, 255, 255));
p_ft2.SetLineWeight(3);
 
Top