1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
329 lines of Pine Script v4 from market-cipher.pine, published under Unlicense. Keep the author's credit and licence lines when you reuse it.
market-cipher.pine
//@version=4
// Market Cipher (Not_MCB.txt)
// Overhauled by: Reid Litkauo aka crexalbo
// February 12, 2021
study(title="Not MCB (crexalbo)", shorttitle="Not MCB")
//##############################################################################
// Global Colors
// Zero-Line
color_zero = #888888
// Bull and Bear
color_bull = #00FF00
color_bull2 = #00FF80
color_bear = #FF0000
color_bear2 = #FF0080
// Wave Trend
color_p_wt = #BFE4FF
color_p_wtsma = #673AB7A0
color_p_dif = #FFFF00
//##############################################################################
// Helpful Functions
// Identify if the value TWO INDICES AGO was a bullish or bearish fractal.
bullish_fractal (s) => s[2]<s[4] and s[2]<s[3] and s[2]<s[1] and s[2]<s[0]
bearish_fractal (s) => s[2]>s[4] and s[2]>s[3] and s[2]>s[1] and s[2]>s[0]
//##############################################################################
// Zero Line
// Simple, just a pronounced line at zero
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Plot
zero_plot = plot( 0,
title = "Zero Line",
color = color_zero )
//##############################################################################
// OB-OS
// Over-Bought & Over-Sold
// These are lines/limits we set ourselves
// to indicate if a coin is being bought or sold TOO much.
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Input
// TODO In the future, maybe we could have more "severity degrees/levels"?
// Over-Bought
obos_input_ob1 = input( title = "OB-OS: Over-Bought Level", defval = 60 )
// Over-Sold
obos_input_os1 = input( title = "OB-OS: Over-Sold Level", defval = -60 )
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Plot
// Let's use a dotted line to plot each of these levels
plot( obos_input_ob1,
title = "Over-Bought Level",
color = color_bear,
style = 3 )
plot( obos_input_os1,
title = "Over-Sold Level",
color = color_bull,
style = 3 )
//##############################################################################
// RSI-MFI
// Relative Strength Index / Money Flow Index
// A measure of fiat moving into or out of the market.
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Input
// What moving average function should we use?
mfi_input_mafn = input( title="RSI-MFI: Moving Average Function",
options=["RMA","SMA","EMA","WMA","VWMA"],
defval="SMA" )
// How many data points should this moving average use?
mfi_input_period = input( title = "RSI-MFI: Moving Average Length",
defval = 60 )
// Scale the RSI-MFI graph to fit nicely on top of everything else.
mfi_input_scale = input( title = "RSI-MFI: Scale of Graph",
defval = 190 )
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Calculate
// Candle value (series)
// This formula normalizes candles relative to each other.
// Exact values won't matter, only how erratic / impactful a candle was.
mfi_candle_value = (close - open) / (high - low)
// Apply the MA function requested by the inputs to the candle value
if mfi_input_mafn == "RMA"
mfi_candle_value := rma(mfi_candle_value, mfi_input_period)
if mfi_input_mafn == "SMA"
mfi_candle_value := sma(mfi_candle_value, mfi_input_period)
if mfi_input_mafn == "EMA"
mfi_candle_value := ema(mfi_candle_value, mfi_input_period)
if mfi_input_mafn == "WMA"
mfi_candle_value := wma(mfi_candle_value, mfi_input_period)
if mfi_input_mafn == "VWMA"
mfi_candle_value := vwma(mfi_candle_value, mfi_input_period)
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Plot
// Determine what color the graph should be at any one point
mfi_plot_color = mfi_candle_value > 0 ? color_bull : color_bear
// Plot the RSI-MFI line
// Scale it using the input so it fits nicely
// Color it appropriately and make it slightly transparent
mfi_plot_line = plot( mfi_candle_value * mfi_input_scale,
title = "RSI-MFI",
color = mfi_plot_color,
transp = 35 )
// Fill between the RSI-MFI and the zero line
fill( mfi_plot_line, zero_plot,
mfi_plot_color,
transp = 50 )
//##############################################################################
// Wave Trend Indicator
// Originally written by LazyBear:
// https://www.tradingview.com/script/2KE8wTuF-Indicator-WaveTrend-Oscillator-WT/
// The prefix is "p" because that's what physicists use for momemtum,
// which is what this indicator is frequently referred to.
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Input
// Channel Length
// TODO wtf is this and why is it important
p_input_channel = input( title = "Momentum: Channel Length", defval = 9 )
// Average Length
// TDO wtf is this and why is it important
p_input_average = input( title = "Momentum: Average Length", defval = 12 )
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Calculate
// I found this explanation, not sure if it's useful.
// https://medium.com/@samuel.mcculloch/lets-take-a-look-at-wavetrend-with-crosses-lazybear-s-indicator-2ece1737f72f
// EMA of HLC3, used multiple times
p_hlc3ema = ema(hlc3, p_input_channel)
// Wave Trend formula
p_wt = ema( (hlc3 - p_hlc3ema) / (0.015 * ema(abs(hlc3 - p_hlc3ema), p_input_channel)), p_input_average )
// SMA of Wave Trend, which lags behind the WT
p_wtsma = sma(p_wt, 3)
// Difference between Wave Trend and its lagging SMA
p_wtdif = p_wt - p_wtsma
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Plot
plot( p_wt,
title = "WaveTrend",
color = color_p_wt,
style = 4 )
plot( p_wtsma,
title = "WaveTrend SMA",
color = color_p_wtsma,
style = 4 )
plot( p_wtdif,
title = "WaveTrend Difference",
color = color_p_dif,
style = 4,
transp = 40 )
// Plot crossovers
// Point out where the leading and trailing momentum graphs intersect.
plotshape( crossover(p_wt, p_wtsma) and obos_input_os1 ? p_wtsma : na,
title = "WaveTrend Crossover (Positive)",
color = color_bull,
style = shape.cross,
location = location.absolute,
size = size.tiny,
transp = 20 )
plotshape( crossover(p_wtsma, p_wt) and obos_input_os1 ? p_wt : na,
title = "WaveTrend Crossover (Negative)",
color = color_bear,
style = shape.cross,
location = location.absolute,
size = size.tiny,
transp = 20 )
plotshape( crossover(p_wt, p_wtsma) and p_wtsma <= obos_input_os1 ? p_wtsma : na,
title = "WaveTrend Crossover (Positive)",
color = color_bull,
style = shape.circle,
location = location.bottom,
size = size.tiny,
transp = 20 )
plotshape( crossover(p_wtsma, p_wt) and p_wt >= obos_input_ob1 ? p_wtsma : na,
title = "WaveTrend Crossover (Negative)",
color = color_bear,
style = shape.circle,
location = location.top,
size = size.tiny,
transp = 20 )
//##############################################################################
// Wave Trend Divergence
// I haven't yet been able to locate the source of this script.
// Then again, I haven't yet really tried looking.
// Meh.
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Calculate
// Note when WT is above/below its own SMA
pd_wtabovesma = (p_wt >= p_wtsma)
pd_wtbelowsma = (p_wt <= p_wtsma)
// Ideitify WT bullish and bearish fractals
// Store the value of the WT at that fractal when found
// These will be filled with "na" for all non-fractal candles
pd_wtfracbear = bearish_fractal(p_wt) and p_wt[2] ? p_wt[2] : na
pd_wtfracbull = bullish_fractal(p_wt) and p_wt[2] ? p_wt[2] : na
// Identify WT value & candle value at most recent fractal locations
pd_wthi_prev = valuewhen(pd_wtfracbear, p_wt, 0)[2]
pd_wthi_cndl = valuewhen(pd_wtfracbear, high[2], 0)[2]
pd_wtlo_prev = valuewhen(pd_wtfracbull, p_wt, 0)[2]
pd_wtlo_cndl = valuewhen(pd_wtfracbull, low[2], 0)[2]
// Identify divergences
pd_wtbeardiv = pd_wtfracbear and high[2] > pd_wthi_cndl and p_wt[2] < pd_wthi_prev
pd_wtbulldiv = pd_wtfracbull and low[2] < pd_wtlo_cndl and p_wt[2] > pd_wtlo_prev
// IDENTIFY SIGNALS
sig_bear_pd = pd_wtbeardiv and pd_wtbelowsma
sig_bull_pd = pd_wtbulldiv and pd_wtabovesma
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Plot
// Only plot when the signal is active!
plot( pd_wtfracbull ? p_wt[2] : na,
title = 'WaveTrend Bullish Divergence',
color = sig_bull_pd ? color_bull : na,
linewidth = 5,
transp = 60 )
plot( pd_wtfracbear ? p_wt[2] : na,
title = 'WaveTrend Bearish Divergence',
color = sig_bear_pd ? color_bear : na,
linewidth = 5,
transp = 60 )
//##############################################################################
// Wave Trend SMA Divergence
// Literally the exact same thing as above
// Just did a text replace of pd_ => pda_ for the variable names
// and used p_wtsma instead of p_wt
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Calculate
// Note when WT is above/below its own SMA
pda_wtabovesma = (p_wt >= p_wtsma)
pda_wtbelowsma = (p_wt <= p_wtsma)
// Ideitify WT bullish and bearish fractals
// Store the value of the WT at that fractal when found
// These will be filled with "na" for all non-fractal candles
pda_wtfracbear = bearish_fractal(p_wtsma) and p_wtsma[2] ? p_wtsma[2] : na
pda_wtfracbull = bullish_fractal(p_wtsma) and p_wtsma[2] ? p_wtsma[2] : na
// Identify WT value & candle value at most recent fractal locations
pda_wthi_prev = valuewhen(pda_wtfracbear, p_wtsma, 0)[2]
pda_wthi_cndl = valuewhen(pda_wtfracbear, high[2], 0)[2]
pda_wtlo_prev = valuewhen(pda_wtfracbull, p_wtsma, 0)[2]
pda_wtlo_cndl = valuewhen(pda_wtfracbull, low[2], 0)[2]
// Identify divergences
pda_wtbeardiv = pda_wtfracbear and high[2] > pda_wthi_cndl and p_wtsma[2] < pda_wthi_prev
pda_wtbulldiv = pda_wtfracbull and low[2] < pda_wtlo_cndl and p_wtsma[2] > pda_wtlo_prev
// IDENTIFY SIGNALS
sig_bear_pda = pda_wtbeardiv and pda_wtbelowsma
sig_bull_pda = pda_wtbulldiv and pda_wtabovesma
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Plot
// Only plot when the signal is active!
plot( pda_wtfracbull ? p_wtsma[2] : na,
title = 'WaveTrend Bullish Divergence',
color = sig_bull_pda ? color_bull2 : na,
linewidth = 5,
transp = 60 )
plot( pda_wtfracbear ? p_wtsma[2] : na,
title = 'WaveTrend Bearish Divergence',
color = sig_bear_pda ? color_bear2 : na,
linewidth = 5,
transp = 60 )
Overview
Not MCB (crexalbo) builds an RSI-MFI series from each candle’s close-to-open change divided by its high-to-low range, then smooths that value with a chosen moving average and a scale setting. Default levels are 60 and minus 60. Momentum channel length and average length are also inputs. The code defines bullish and bearish fractal checks two bars back. This indicator places no orders and has no stop loss.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
OB-OS: Over-Bought Level
int
60
obos_input_ob1
OB-OS: Over-Sold Level
int
-60
obos_input_os1
RSI-MFI: Moving Average Function
string
SMA
mfi_input_mafn
RSI-MFI: Moving Average Length
int
60
mfi_input_period
RSI-MFI: Scale of Graph
int
190
mfi_input_scale
Momentum: Channel Length
int
9
p_input_channel
Momentum: Average Length
int
12
p_input_average
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.
Calculates the standard Money Flow Index (MFI) oscillator alongside an exponential moving average signal line in a separate pane. The script visually highlights trend conditions through dynamic ribbon filling, optional difference histogram bars, and overbought
This indicator measures directional momentum by evaluating candlestick body proportions and volume over a user-defined lookback window. It computes the ratio of candle body to total range, weights the cumulative value by volume and absolute body size, and dete
This indicator builds an aggregate oscillator in a separate pane. It scales open, high, low, close, and volume into a 0 to 1 range, then averages scaled readings from MACD, a MACD histogram, RSI, stochastic, CCI, momentum, OBV, a directional index, volume-weig
This indicator calculates the Bill Williams Market Facilitation Index as the high-low range divided by volume, or zero when volume is zero. It compares the index and volume with the previous bar and assigns one of four zones: green for both rising, fade for bo
PPO ATR Bands plots a percentage price oscillator in a separate pane. It compares a Hull average of typical price with a volume-weighted exponential average of Parabolic SAR, then scales three true-range bands around the slow average into matching oscillator l
Calculates the Chaikin Oscillator by taking the difference between a fast exponential moving average and a slow exponential moving average of the Accumulation/Distribution line. It plots the resulting line in a separate pane alongside a dashed zero reference l