anexas

Oscillator Moving Average (OsMA)

This code for Oscillator of Moving Averages (OsMA) is based on MACD 4C indicator code published by vkno422. Many thanks to vkno422. I have borrowed the concept of 4 colours which I find very useful.

For those who are not familiar with OsMA, it is histogram of difference between MACD (oscillator) and its MA (signal line). The zero line cross over of this indicator is used in many strategies.

This version includes MACD & its signal line together with OsMA histogram. I have programmed flexibility for switching OFF/ON individual indicator components as well as changing the periods for various moving averages.

I am dedicating this indicator to the TV trading community hoping that people will find it useful.
开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?
//Indicator - Oscillator of Moving Averages.
//Histogram of difference between MACD (oscillator) and its MA (signal line)
//Version 2.0 Created on 14 July 2016 by - Shailesh Saxena
//code based on MACD 4C indicator code published by vkno422
study(shorttitle = "OsMA", title = "Oscillator Moving Average")

//User Inputs
fastMA = input(title="Fast MA Period", type = integer, defval = 12, minval = 3)
slowMA = input(title="Slow MA Period", type = integer, defval = 26, minval = 3)
smoothing = input(title="MACD MA Period", type = integer, defval = 9, minval = 3)
sLine = input(title="Show Signal Line", type=bool, defval=true)
MACD_visible = input(title="Show MACD", type = bool, defval = true)
OsMA_histogram = input(title="Show OsMA Histogram", type = bool, defval = true)

//MACD
[MACD,signalLine,_] = macd(close[0], fastMA, slowMA, smoothing)
show_MACD = MACD_visible ? MACD : na

MACDColor = MACD > 0 
    ? MACD > MACD[1] ? lime : green 
    : MACD < MACD[1] ? red : orange
plot(show_MACD, style = line, color = MACDColor, linewidth = 1)
plot(0, title = "Zero line", linewidth = 1, color = gray)

sl = sLine ? signalLine : na
plot(sl, color = yellow, linewidth = 1)

//OsMA
OsMA = OsMA_histogram ? MACD - signalLine : na

OsMAColor = OsMA > 0 
    ? OsMA > OsMA[1] ? aqua : teal 
    : OsMA < OsMA[1] ? fuchsia : purple
plot(OsMA, style = histogram, color = OsMAColor, linewidth = 2)
plot(0, title = "Zero line", linewidth = 1, color = gray)