DEbug Script

Questions about MultiCharts and user contributed studies.
ronseng
Posts: 1
Joined: 03 Jan 2022

DEbug Script

Postby ronseng » 03 Jan 2022

Hi,

Can anyone help me to debug the below 2 indicators script ?

Thank you.

MACD + ATR SCRIPT

study(title="MACD", shorttitle="MACD", resolution="")
// Getting inputs
fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
src = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
sma_source = input(title="Simple MA (Oscillator)", type=input.bool, defval=false)
sma_signal = input(title="Simple MA (Signal Line)", type=input.bool, defval=false)
// Plot colors
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = #0094ff
col_signal = #ff6a00
// Calculating
fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)
slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal
plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )
//plot(macd, title="MACD", color=col_macd, transp=0)
//plot(signal, title="Signal", color=col_signal, transp=0)

title="Average True Range", shorttitle="ATR", overlay=false, resolution=""
length = input(title="Length", defval=24, minval=1)
smoothing = input(title="Smoothing", defval="SMA")
ma_function(source, length) => sma(source, length)

plot(ma_function(tr(true), length), title = "ATR", color=#991515, transp=0)


3 IN 1 MOVING AVERAGE (MA) SCRIPT

study(title="Triple Moving Averages", shorttitle="3MA", overlay=true)
len1 = input(21, title="Length")
len2 = input(100, title="Length")
len3 = input(100, title="Length")
src1 = input(close, title="Source")
src2 = input(high, title="Source")
src3 = input(low, title="Source")
one = sma(src1, len1)
two = sma(src2, len2)
three = sma(src3, len3)
plot(one, color=color.orange, title="21MA")
plot(two, color=color.green, title="100MA")
plot(three, color=color.green, title="100MA")

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: DEbug Script

Postby TJ » 03 Jan 2022

See post #1 & #2
1. [FAQ] How to Post Codes ... so that people can read.
viewtopic.php?t=11713


Return to “MultiCharts”