//@version=4
study("Price vs MA", "", true)
var string GP1 = "Moving averages"
int i_masQty = input(20, "Quantity", minval = 1, maxval = 40, group = GP1, tooltip = "1-40")
int i_masStart = input(20, "Periods begin at", minval = 2, maxval = 200, group = GP1, tooltip = "2-200")
int i_masStep = input(20, "Periods increase by", minval = 1, maxval = 100, group = GP1, tooltip = "1-100")
var string GP2 = "Display"
string i_tableYpos = input("top", "Panel position", inline = "11", options = ["top", "middle", "bottom"], group = GP2)
string i_tableXpos = input("right", "", inline = "11", options = ["left", "center", "right"], group = GP2)
color i_c_bull = input(color.new(color.green, 30), "Bull", inline = "12", group = GP2)
color i_c_bear = input(color.new(color.red, 30), "Bear", inline = "12", group = GP2)
color i_c_neutral = input(color.new(color.gray, 30), "Neutral", inline = "12", group = GP2)
// ————— Produces a string format usable with `tostring()` to restrict precision to ticks.
f_tickFormat() =>
string _s = tostring(syminfo.mintick)
_s := str.replace_all(_s, "25", "00")
_s := str.replace_all(_s, "5", "0")
_s := str.replace_all(_s, "1", "0")
var table panel = table.new(i_tableYpos + "_" + i_tableXpos, 2, i_masQty + 1)
if barstate.islast
// Table header.
table.cell(panel, 0, 0, "MA", bgcolor = i_c_neutral)
table.cell(panel, 1, 0, "Value", bgcolor = i_c_neutral)
int period = i_masStart
for _i = 1 to i_masQty
// ————— Call MAs on each bar.
float _ma = sma(close, period)
// ————— Only execute table code on last bar.
if barstate.islast
// Period in left column.
table.cell(panel, 0, _i, tostring(period), bgcolor = i_c_neutral)
// If MA is between the open and close, use neutral color. If close is lower/higher than MA, use bull/bear color.
_c_bg = close > _ma ? open < _ma ? i_c_neutral : i_c_bull : open > _ma ? i_c_neutral : i_c_bear
// MA value in right column.
table.cell(panel, 1, _i, tostring(_ma, f_tickFormat()), text_color = color.black, bgcolor = _c_bg)
period += i_masStep
Overview
Price vs MA calculates a user-chosen number of SMAs whose periods start at a base length and increase by a fixed step. On the last bar it lists each period and its SMA value, coloring the value bull, bear, or neutral according to whether price is above, below, or straddling the average. Quantity, starting period, step, panel position, and colors are adjustable. It does not plot lines or issue trade signals.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Quantity
int
20
i_masQty
Periods begin at
int
20
i_masStart
Periods increase by
int
20
i_masStep
Panel position
string
top
i_tableYpos
i_tableXpos
string
right
i_tableXpos
Bull
color
color.new(color.green, 30)
i_c_bull
Bear
color
color.new(color.red, 30)
i_c_bear
Neutral
color
color.new(color.gray, 30)
i_c_neutral
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This overlay indicator plots a Supertrend from an ATR length and factor, four exponential moving averages, and a selectable VWAP or TWAP taken from a chosen timeframe on the price chart. It also shows MACD and stochastic with adjustable lengths, smoothing, ver
This indicator plots a 200-period weighted moving average (WMA) on the main chart and monitors price deviations across multiple timeframes. It retrieves daily, 15-minute, 5-minute, and 2-minute price data to track distance from the 200 WMA relative to key sess
TradersPost Trading Checklist is an overlay indicator that evaluates a suite of popular technical conditions for long and short trade setups. It checks session-anchored VWAP, fast and slow EMA alignments and crosses, 200 SMA, RSI overbought or oversold conditi
The 8zz Contrarian Indicator plots reverse sentiment trading signals directly on the price chart based on tracked retail post activity. It generates bullish signals during retail panic and bearish signals during market euphoria. The indicator features adjustab
This indicator plots five moving averages of a chosen source on the price chart, defaulting to EMA lengths 10, 20, 30, 40 and 50. The user can switch the average type to SMA, WMA or HMA and recolor each line. Wide translucent glows sit under the lines, and sof
Calculates exponential moving averages for fast, pivot, and slow lengths along with optional 50, 100, and 200 simple moving average context lines. It visualizes bullish and bearish ribbon fills on the main price chart alongside MACD calculations to generate ea