MTF Moving Average Slope Histogram

barbaros

Administrator
Staff member
Platform
  1. Thinkorswim
  2. TradingView
This was converted to TradingView from Thinkscript.

CoImKS8.png


Original code in Thinkscript:
Code:
# MTF Moving Average Slope Histogram
# DaysOff

declare lower;

input price = close;
input length = 10;
input agperiod = { "1 min", "2 min", "5 min", default "10 min", "15 min", "30 min", "60 min", "4 hours"};

def avg = ExpAverage(close(period = agperiod), length);
plot height = avg - avg[length];

height.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
height.DefineColor("height >= 0" , Color.GREEN);
height.DefineColor("height < 0", Color.RED);
height.assignValueColor(if height >= 0 then height.color("height >= 0") else height.color("height < 0"));

Converted to Pinescript:
Code:
// MTF Moving Average Slope Histogram
// Converted from
// barbaros - initial version

//@version=5
indicator("MTF Moving Average Slope Histogram")

price = input.source(close, "Price")
length = input.int(10, "Length")
agprerid = input.timeframe("10", "Aggregation Period")

avg = ta.ema(price, length)
price_mtf = request.security(syminfo.tickerid, agprerid, avg)
height = price_mtf - price_mtf[length]

plot(height, "Height", height >= 0 ? color.green : color.red, 2, plot.style_columns)
 
Last edited:
Top