Creator Message:
This script is the combination of RSI and Engulfing Pattern
How it works
1. when RSI > 70 and form the bullish engulfing pattern . it gives sell signal - Configurable.
2. when RSI < 30 and form the bearish engulfing pattern . it gives buy signal - Configurable
settings:
basic setting for RSI has been enabled in the script to set the levels accordingly to your trades. Added multiaple engulfing candle calculation methods.
CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © ahmedirshad419
# https://www.tradingview.com/v/58m8mjwG/
#study("EngulfingCandle", overlay=true )
# converted and mod by Sam4Cok@Samer800 - 03/2023
#// RSI integration
input rsiSource = close; # "rsiSource"
input SignalStyle = {Default Bubble, Wedges};
input CalculationMEthod = {"Open/Close EngulfingCandle", "Wick EngulfingCandle", Default "3 Candle Engulfing"};
input rsiLenghth = 14; # "rsi length"
input rsiOverBought = 70; # "rsi overbought level"
input rsiOverSold = 30; # "rsi over sold level"
input SmoothedRsi = no;
input SmoothingPeriod = 5;
input SmoothingType = AverageType.HULL;
def na = Double.NaN;
def bubble = SignalStyle==SignalStyle.Bubble;
def calc = CalculationMEthod==CalculationMEthod."Open/Close EngulfingCandle";
def calcA = CalculationMEthod==CalculationMEthod."Wick EngulfingCandle";
#def calcT = CalculationMEthod==CalculationMEthod."3 Candle Engulfing";
#bullEngulf(float maxRejectWick = 0.0, bool mustEngulfWick = false) =>
script bullEngulf {
input maxRejectWick = 0.0;
input mustEngulfWick = no;
def topWickSize = AbsValue(Max(close, open) - high);
def bodySize = AbsValue( close - open);
def rejectionRule = maxRejectWick == 0.0 or (topWickSize / bodySize) < (maxRejectWick / 100);
plot result = close[1] <= open[1] and close >= open[1] and open <= close[1] and rejectionRule and (!mustEngulfWick or close >= high[1]) and bodySize > 0;
}
#bearEngulf(float maxRejectWick = 0.0, bool mustEngulfWick = false) =>
script bearEngulf {
input maxRejectWick = 0.0;
input mustEngulfWick = no;
def bottomWickSize = AbsValue(Min( close, open) - low);
def bodySize = AbsValue( close - open);
def rejectionRule = maxRejectWick == 0.0 or (bottomWickSize / bodySize) < (maxRejectWick / 100);
plot result = close[1] >= open[1] and close <= open[1] and open >= close[1] and rejectionRule and (!mustEngulfWick or close <= low[1]) and bodySize > 0;
}
#// Logic
def bewA = bullEngulf(0 , yes);
def bebA = bearEngulf(0 , yes);
def bewS = close >= open[1] and close[1] < open[1];
def bebS = close <= open[1] and close[1] > open[1];
def bewT = if open[3] > close[3] then if open[2] > close[2] then if open[1] > close[1] then if close > open then if close >= open[1] then if close[1] >= open then if close - open > 0 then if close - open > open[1] - close[1] then yes else no else no else no else no else no else no else no else no;
def bebT = if open[3] < close[3] then if open[2] < close[2] then if open[1] < close[1] then if open > close then if open >= close[1] then if open[1] >= close then if open - close > 0 then if open - close > close[1] - open[1] then yes else no else no else no else no else no else no else no else no;
def bullishCandle = if calc then bewS else if calcA then bewA else bewT;
def bearishCandle = if calc then bebS else if calcA then bebA else bebT;
#//get RSI value
def nRsi = RSI(PRice = rsiSource, Length = rsiLenghth);
def rsiValue = if SmoothedRsi then MovingAverage(SmoothingType, nRsi, SmoothingPeriod) else nRsi;
def isRSIOB = rsiValue >= rsiOverBought and rsiValue;
def isRSIOS = rsiValue <= rsiOverSold and rsiValue;
def tradeSignal = ((isRSIOS or isRSIOS[1] or isRSIOS[2]) and bullishCandle ) or
((isRSIOB or isRSIOB[1] or isRSIOB[2]) and bearishCandle);
#//plot on chart
plot bullWedge = if tradeSignal and !bubble and bullishCandle then low else na;
plot bearWedge = if tradeSignal and !bubble and bearishCandle then high else na;
bullWedge.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
bearWedge.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
bullWedge.SetDefaultColor(Color.CYAN);
bearWedge.SetDefaultColor(Color.MAGENTA);
bullWedge.SetLineWeight(2);
bearWedge.SetLineWeight(2);
AddChartBubble(bubble and tradeSignal and bullishCandle, low, "OS", Color.GREEN, no);
AddChartBubble(bubble and tradeSignal and bearishCandle, high, "OB", Color.RED, yes);
#-- END CODE
Last edited by a moderator: