Heikin Ashi all in one in ThinkOrSwim

Ajordan930

New member
Ok I have been messing around with building an indicator (very new to coding) that is based on a strategy that is a variation of a system from a trader on Facebook who has a discord but with some adjustments based on a technique used by a friend of mine.

Code below.

Indicator includes
  • 4 ema's
    • 1 is a 1 ema dot
  • VWAP w/2SD
  • 50 SMA
  • 200 SMA
  • Labels for the following
    • ADD
    • VIX
    • TICK
    • RSI
    • Position status (Long Calls, No Set Up, Short Puts, Long Reversal, or Short Reversal)

Strategy in a nutshell to qualify for "A+ set up
Bullish set up
  • 2 consecutive Heikin Ashi candles bullish
  • 9 over 21 ema
  • price over VWAP
  • RSI over 55
If all criteria's are met A+ Buy, Long Calls banner up top, green arrows below candles (you can adjust distance via the atr multiplier setting) and candles will turn green. Bearish set up is the reverse but RSI is below 55. Also I have potential reversals coded in or you could say reversion to VWAP will show yellow arrow and candle when below VWAP and orange when above price moving down.

1732677151932.png

Ruby:
# Section 1: Moving Averages (EMAs and SMAs)
#--------------------------------------------
input EmaDotLength = 1;
input ShortEmaLength = 9;
input MidEmaLength = 15;
input LongEmaLength = 21;
input showCloud = yes;  # Option to turn the EMA cloud on/off

# Define EMAs
def emaDot = ExpAverage(close, EmaDotLength);  # EMA Dot (1-period)
def shortEma = ExpAverage(close, ShortEmaLength);
def MidEma = ExpAverage(close, MidEmaLength);
def LongEma = ExpAverage(close, LongEmaLength);

# Plot EMA Dot (1-period EMA as a white dot)
plot EmaDotPlot = emaDot;
EmaDotPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
EmaDotPlot.SetDefaultColor(Color.WHITE);
EmaDotPlot.SetLineWeight(2);

plot ShortEMAPlot = shortEma;
ShortEMAPlot.SetDefaultColor(Color.CYAN);
ShortEMAPlot.SetLineWeight(2);

plot MidEMAPlot = MidEma;
MidEMAPlot.SetDefaultColor(Color.grAY);
MidEMAPlot.SetLineWeight(1);

plot LongEmaPlot = LongEma;
LongEMAPlot.SetDefaultColor(Color.white);
LongEMAPlot.SetLineWeight(3);

# Cloud between short and long EMAs (toggle with showCloud)
AddCloud(if showCloud then shortEma else Double.NaN, if showCloud then LongEma else Double.NaN, Color.GREEN, Color.RED);

# Define SMAs
input FastSMALength = 50;
input SlowSMALength = 200;
def sma50 = SimpleMovingAvg(close, FastSMALength);
def sma200 = SimpleMovingAvg(close, SlowSMALength);

# Plot SMAs
plot Sma50Plot = sma50;
Sma50Plot.SetDefaultColor(Color.GREEN);
Sma50Plot.SetLineWeight(2);
Sma50Plot.SetStyle(Curve.MEDIUM_DASH);

plot Sma200Plot = sma200;
Sma200Plot.SetDefaultColor(Color.RED);
Sma200Plot.SetLineWeight(2);
Sma200Plot.SetStyle(Curve.MEDIUM_DASH);

#STUDY adds label with current TICK reading
addLabel(Yes, "$TICK: " + close("$TICK"),if close("$TICK") > 0 then color.green else color.red );

addLabel(Yes, "$ADD: " + close("$ADD"),if close("$ADD") > 0 then color.green else color.red );

addLabel(Yes, "VIX: " + close("VIX"),if close("VIX") > 0 then color.red else color.green );


# Section 2: Technical Indicators (VWAP, RSI Calc)
#--------------------------------------------------------------
input showVWAP = yes;  # Option to show VWAP
input showVWAP_SD = yes;  # Option to show VWAP with 2 SD bands

# VWAP Calculation
def vwap = reference VWAP()."VWAP";
def vwapSDUpper = vwap + 2 * stdev(close, 10);  # 2 SD upper band
def vwapSDLower = vwap - 2 * stdev(close, 10);  # 2 SD lower band

# Plot VWAP and SD bands based on user settings
plot VWAPLine = if showVWAP then vwap else Double.NaN;
VWAPLine.SetDefaultColor(Color.PLUM);
VWAPLine.SetLineWeight(2);

plot VWAPUpperBand = if showVWAP and showVWAP_SD then vwapSDUpper else Double.NaN;
VWAPUpperBand.SetDefaultColor(Color.PLUM);
VWAPUpperBand.SetLineWeight(1);
VWAPUpperBand.SetStyle(Curve.SHORT_DASH);

plot VWAPLowerBand = if showVWAP and showVWAP_SD then vwapSDLower else Double.NaN;
VWAPLowerBand.SetDefaultColor(Color.PLUM);
VWAPLowerBand.SetLineWeight(1);
VWAPLowerBand.SetStyle(Curve.SHORT_DASH);


# RSI
# Define RSI
input rsiLength = 14;
input rsiOversold = 55;
input rsiOverbought = 55;

def rsi = RSI(length = rsiLength);

# Add RSI Label
AddLabel(yes, "RSI: " + AsText(rsi, NumberFormat.TWO_DECIMAL_PLACES),
    if rsi > rsiOverbought then Color.GREEN
    else if rsi < rsiOversold then Color.RED
    else Color.YELLOW);




# Section 4: Strategy Logic
#--------------------------
# ATR Input for bubble offset
input atrLength = 14;  # Length of ATR calculation
input atrMultiplier = 1.0;  # ATR Multiplier for offset
input showBubbles = no;  # Option to show/hide A+ bubbles

# Calculate ATR
def atr = Average(TrueRange(high, close, low), atrLength);

# Calculate Heikin Ashi Candles
def haClose = (open + high + low + close) / 4;
def haOpen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, (open + close) / 2);

# Define Bullish and Bearish Heikin Ashi Candles
def isBullishHaCandle = haClose > haOpen;
def isBearishHaCandle = haClose < haOpen;

# Conditions for Long, Short, and Reversal
def longCondition = shortEma > longEma and isBullishHaCandle[1] and isBullishHaCandle and rsi > rsiOverbought and close > vwap;
def shortCondition = shortEma < longEma and isBearishHaCandle[1] and isBearishHaCandle and rsi < rsiOversold and close < vwap;
def reversalCondition1 = shortEma > longEma and isBullishHaCandle[1] and isBullishHaCandle and rsi > rsiOverbought and close < vwap;
def reversalCondition2 = shortEma < longEma and isBearishHaCandle[1] and isBearishHaCandle and rsi < rsiOversold and close > vwap;

# Track the first bar where longCondition or shortCondition is true
rec firstLong = if longCondition and !longCondition[1] then 1 else 0;
rec firstShort = if shortCondition and !shortCondition[1] then 1 else 0;

# Offset bubble locations by ATR
def longBubbleOffset = low - (atrMultiplier * atr);
def shortBubbleOffset = high + (atrMultiplier * atr);

# Add Chart Bubbles for the first instance of long or short condition with ATR offset, respect showBubbles input
AddChartBubble(showBubbles and firstLong, longBubbleOffset, "A+Buy", Color.Green, no);  # Long condition bubble
AddChartBubble(showBubbles and firstShort, shortBubbleOffset, "A+Sell", Color.Red, yes);  # Short condition bubble
 
Last edited by a moderator:
@Ajordan930 I do not see any of the top labels or the bubbles that is shown in your screenshot, I loaded the code in thinkscript and added it to the chart, is there anything else I should do? I also selected Hiekin Ashi candle type, thanks!

Screenshot 2024-12-11 at 1.23.59 PM.png
 
@Ajordan930 I do not see any of the top labels or the bubbles that is shown in your screenshot, I loaded the code in thinkscript and added it to the chart, is there anything else I should do? I also selected Hiekin Ashi candle type, thanks!

View attachment 23554
Let me take a look at it when I get home. I have a couple of versions that I have coded so let me verify them and I will repost. I separated out the labels in one to make the code less complex for TOS so I can post that one as well.
 
Updated code I switched to since fist post

Here is another variation of the previous with one without the internals labels. I separated it out to make the script less complicated for TOS. Also I added a label that will display when the short EMA crosses VWAP

A+ Set up + 2 consecutive bullish candles + RSI over 55 + 9 short ema over long ema + plus over VWAP and will plot that 1st instance

https://tos.mx/!Xy3SwwIu
1733965561554.png


The labels are blacked out due to after hours on the internals
Here are the 3 internals TICK, ADD, and VIX

https://tos.mx/!cjtft4mx
 
Updated code I switched to since fist post

Here is another variation of the previous with one without the internals labels. I separated it out to make the script less complicated for TOS. Also I added a label that will display when the short EMA crosses VWAP

A+ Set up + 2 consecutive bullish candles + RSI over 55 + 9 short ema over long ema + plus over VWAP and will plot that 1st instance

https://tos.mx/!Xy3SwwIu
View attachment 23557

The labels are blacked out due to after hours on the internals
Here are the 3 internals TICK, ADD, and VIX

https://tos.mx/!cjtft4mx

@Ajordan930 thank you, is there a scanner you use along with this?
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
388 Online
Create Post

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