AI-EngulfingCandle for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
9pjxY3D.png


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:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
213 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top