Indicator · Pine Script v4 · On the chart

EmaRainbowCandleMark

by fox-buddy· code credited to Liquid1209

EmaRainbowCandleMark is a price-chart overlay that calculates a stack of exponential moving averages with Fibonacci-style lengths and tests candles for hammers, shooting stars, and bullish or bearish engulfing patterns.

View on GitHub

GitHub stars4on the repository
Pine versionv4older, still runs
Lines of code165
Settings11inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago4 Aug 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

165 lines of Pine Script v4 from Tradingview/RainbowTrendfollow.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

RainbowTrendfollow.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Liquid1209

//@version=4
study("EmaRainbowCandleMark", overlay = true)

// *******************************
// ******** User Inputs **********
// *******************************
hammerCandleTolerance = input(title="Hammer Body-Wick Faktor", type=input.float, defval=0.8, minval=0.5, step=0.1)
starCandleTolerance = input(title="Shooting Star Body-Wick Faktor", type=input.float, defval=0.8, minval=0.5, step=0.1)
candleVolumeFilter = input(title="Candle Volumenverhältnis zur vorherigen Candle", type=input.float, defval=0.8, minval=1.0, step=0.1)

emaShortest = input(title="Fastest EMA", type=input.integer, defval=10, minval=1, step=1)
middleFib1 = input(title="EMA 2", type=input.integer, defval=13, minval=1, step=1)
middleFib2 = input(title="EMA 3", type=input.integer, defval=21, minval=1, step=1)
middleFib3 = input(title="EMA 4", type=input.integer, defval=34, minval=1, step=1)
emaMedian = input(title="Median EMA", type=input.integer, defval=55, minval=1, step=1)
emaSlowest = input(title="Slowest EMA", type=input.integer, defval=89, minval=1, step=1)

rsiLongBarrier = input(title="RSI (14) Long Barriere (Maximal erlaubt)", type=input.integer, defval=69, minval=1, step=1)
rsiShortBarrier = input(title="RSI (14) Short Barriere (Minimal erforderlich)", type=input.integer, defval=31, minval=1, step=1)

// *******************************
// ******** Functions *********
// *******************************
isHammerCandle() =>
    candleWickLength = iff(close<open, high-open, high-close)
    candleFuseLength = iff(close<open, close-low, open-low)
    candleBodylength = iff(close<open, open-close, close-open)
    //hammer body size will me multiplied with this value. Reult is the maximum allowd wick lenght
    hammerCandleWickToBodyMaximum = hammerCandleTolerance  
    
    isHammer = (candleWickLength < candleBodylength*hammerCandleWickToBodyMaximum) and (candleFuseLength >= 1.9*candleBodylength)
    isHammer
    
isShootingStarCandle() =>
    candleWickLength = iff(close<open, high-open, high-close)
    candleFuseLength = iff(close<open, close-low, open-low)
    candleBodylength = iff(close<open, open-close, close-open)
    //Shooting Star body size will me multiplied with this value. Reult is the maximum allowd wick lenght
    shootingStarCandleWickToBodyMaximum = starCandleTolerance  
    
    isShootingStar = (candleFuseLength < candleBodylength*shootingStarCandleWickToBodyMaximum) and (candleWickLength >= 1.9*candleBodylength)
    isShootingStar
    
isBullishEngulfingCandle() =>
    lastCandleWasRed = close[1] < open[1]
    lastCandleWasGreen = not lastCandleWasRed
    iAmGreen = close > open
    iAmRed = not iAmGreen
    
    isBullishEngulfing = lastCandleWasRed and iAmGreen and (open<=close[1]) and (close>=open[1])
    isBullishEngulfing

isBearishEngulfingCandle() =>
    lastCandleWasRed = close[1] < open[1]
    lastCandleWasGreen = not lastCandleWasRed
    iAmGreen = close > open
    iAmRed = not iAmGreen
    
    isBearishEngulfing = lastCandleWasGreen and iAmRed and (open>=close[1]) and (close<=open[1])
    isBearishEngulfing

// *******************************
// ******** Calculations *********
// *******************************
//EMA
emaShortestValue = ema(close, emaShortest)
ema13Value = ema(close, middleFib1)
ema21Value = ema(close, middleFib2)
ema34Value = ema(close, middleFib3)
emaMedianValue = ema(close, emaMedian)
ema89Value = ema(close, emaSlowest)

// *******************************
// ******* EMA Crossunders *******
// *******************************
isLongEmaCrossed = false
isLongTradeFlag = false
isShortEmaCrossed = false
isShortTradeFlag = false
emaCrossValue = 0.0

if(crossunder(low, emaShortestValue))
    isLongEmaCrossed := true
    emaCrossValue := emaShortestValue
if(crossunder(low, ema13Value))
    isLongEmaCrossed := true
    emaCrossValue := ema13Value
if(crossunder(low, ema21Value))
    isLongEmaCrossed := true
    emaCrossValue := ema21Value
if(crossunder(low, ema34Value))
    isLongEmaCrossed := true
    emaCrossValue := ema34Value
if(crossunder(low, emaMedianValue))
    isLongEmaCrossed := true
    emaCrossValue := emaMedianValue
if(crossunder(close, emaMedianValue))
    isLongTradeFlag := true
    emaCrossValue := emaMedianValue    
    
if(crossover(high, emaShortestValue))
    isShortEmaCrossed := true
    emaCrossValue := emaShortestValue
if(crossover(high, ema13Value))
    isShortEmaCrossed := true
    emaCrossValue := ema13Value
if(crossover(high, ema21Value))
    isShortEmaCrossed := true
    emaCrossValue := ema21Value
if(crossover(high, ema34Value))
    isShortEmaCrossed := true
    emaCrossValue := ema34Value
if(crossover(high, emaMedianValue))
    isShortEmaCrossed := true
    emaCrossValue := emaMedianValue
if(crossover(close, emaMedianValue))
    isShortTradeFlag := true
    emaCrossValue := emaMedianValue  
// *******************************
// ****** Trade Filtering ********
// *******************************
//Trendphase identification
isUptrendPhase = emaShortestValue >= ema13Value and ema13Value >= ema21Value and ema21Value >= ema34Value and ema34Value >= emaMedianValue and emaMedianValue >= ema89Value
isDownTrendPhase = emaShortestValue <= ema13Value and ema13Value <= ema21Value and ema21Value <= ema34Value and ema34Value <= emaMedianValue and emaMedianValue <= ema89Value
istrendLess = not isUptrendPhase and not isDownTrendPhase

//RSI Filtering
longTradeRsiOkay = rsi(close,14) <= rsiLongBarrier
shortTradeRsiOkay = rsi(close,14) >= rsiShortBarrier

//Volume Filtering
volumeFactor = candleVolumeFilter
isVolumeHigher = volume > volume[1]*volumeFactor


// *******************************
// ********** Plotting ***********
// *******************************
//Plotting EMA Lines
plot(emaShortestValue, color=color.orange)
plot(ema13Value, color=color.green)
plot(ema21Value, color=color.navy)
plot(ema34Value, color=color.aqua)
plot(emaMedianValue, color=color.purple)
plot(ema89Value, color=color.red)

//Plotting EMA Cross
plotshape(isLongEmaCrossed and isUptrendPhase and not isLongTradeFlag ? emaCrossValue : na, color=color.green, style=shape.xcross, location=location.absolute, size=size.small)
plotshape(isLongTradeFlag and isUptrendPhase ? emaCrossValue : na, color=color.red, style=shape.flag, location=location.belowbar, size=size.small)
plotshape(isShortEmaCrossed and isDownTrendPhase and not isShortTradeFlag ? emaCrossValue : na, color=color.red, style=shape.xcross, location=location.absolute, size=size.small)
plotshape(isShortTradeFlag and isDownTrendPhase ? emaCrossValue : na, color=color.green, style=shape.flag, location=location.abovebar, size=size.small)

//Plotting Trend Directions
plotshape(isUptrendPhase and not isUptrendPhase[1], color=color.green, style=shape.triangleup, location=location.abovebar, size=size.small)
plotshape(isDownTrendPhase and not isDownTrendPhase[1], color=color.red, style=shape.triangledown, location=location.abovebar, size=size.small)
plotshape(istrendLess and not istrendLess[1], color=color.black, style=shape.circle, location=location.abovebar, size=size.small)

//Plotting special candles
plotchar(isHammerCandle() and isUptrendPhase and isVolumeHigher and longTradeRsiOkay, char='H', color=color.green, size=size.small)
plotchar(isBullishEngulfingCandle() and isUptrendPhase and isVolumeHigher and longTradeRsiOkay, char='E', color=color.green, size=size.small)
plotchar(isShootingStarCandle() and isDownTrendPhase and isVolumeHigher and shortTradeRsiOkay, char='S', color=color.red, size=size.small)
plotchar(isBearishEngulfingCandle() and isDownTrendPhase and isVolumeHigher and shortTradeRsiOkay, char='E', color=color.red, size=size.small)

Overview

Body-to-wick tolerances set how strict those candle shapes must be, and a volume ratio compares the current candle with the previous one. Separate RSI barriers limit how high or low RSI may be for long and short marks. The visible code does not show completed plot or alert logic.

Details

Published by

fox-buddy on GitHub

Code credit

Liquid1209, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Hammer Body-Wick Faktorfloat0.8hammerCandleTolerance
Shooting Star Body-Wick Faktorfloat0.8starCandleTolerance
Candle Volumenverhältnis zur vorherigen Candlefloat0.8candleVolumeFilter
Fastest EMAint10emaShortest
EMA 2int13middleFib1
EMA 3int21middleFib2
EMA 4int34middleFib3
Median EMAint55emaMedian
Slowest EMAint89emaSlowest
RSI (14) Long Barriere (Maximal erlaubt)int69rsiLongBarrier
RSI (14) Short Barriere (Minimal erforderlich)int31rsiShortBarrier
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.

Similar Pine Scripts

285 stars

Mean Reversion Study is an indicator that identifies trade setups combining exponential moving averages, RSI extremes, and engulfing candlestick patterns. It highlights bullish setups when a bullish engulfing candle forms below the EMA while RSI is oversold, a

Indicator v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Study
55 stars

This indicator overlays on the price chart and provides trend and momentum analysis. It calculates and plots three exponential moving averages with fixed periods of 20, 50, and 200 using yellow, orange, and blue colors respectively. The script also computes th

Indicator v6 TrendOscillators & momentum
Updated 6 months ago · Apache-2.0 GitHub repository of Trend & Momentum Analysis

This overlay indicator combines price-action swing structure with a MACD comparison and a dual moving-average filter. It finds pivot highs and lows, labels higher highs, lower highs, higher lows and lower lows, and builds a trend bias from those swings. It rep

Indicator v5 Candlestick patternsOscillators & momentum Repaints
Updated 5 months ago · None stated GitHub repository of Price Action Candles with MACD Signals

Advanced Scalping EMA & RSI Strategy is an overlay indicator that combines fast and smooth moving averages with RSI levels and candlestick patterns to generate scalping signals. Users can select calculation methods for moving averages, such as SMA, EMA, WMA, o

Indicator v5 TrendOscillators & momentum
Updated 2 years ago · MIT GitHub repository of Advanced Scalping EMA & RSI Strategy
2 stars

Multi-Indicator Trading System plots 50-period and 200-period exponential moving averages alongside buy and sell signals directly on the price chart. Signals trigger when a short-timeframe EMA crossover aligns with higher timeframe trend filters from 1-hour or

Indicator v5 TrendMoving averages Repaints
Updated 1 year ago · MIT GitHub repository of Multi-Indicator Trading System

More Moving averages scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers