Aggressive Pullback Indicator





This simple pullback indicator was created for Steven Hart’s Aggressive Pullback Strategy. It was one of the first scripts I ever made, and for a long time it was a trading tool I used every single day in conjunction with my ATR Stop Loss indicator.

It sends you pullback alerts and draws your stops and targets for you which makes backtesting and trade execution a lot faster.

This is an extremely powerful strategy when used with the right rules. I will not divulge my trading strategy rules here as they are too long and too valuable to share for free.

But if you are an experienced trader who has traded rules-based systematic trading strategies before then I have no doubt that you will be able to come up with profitable rules to trade these signals. If you need help coming up with ideas or understanding the process behind rules-based strategy development then I encourage you to check out my trading mentor’s education course The EAP Program.

If you like this basic pullback indicator then you may want to try out my updated and advanced version of this script which I currently use to trade the forex markets – The Ultimate Pullback Indicator.

How It Works

I will detail the basics as best I can, but if you want to learn the specific rules that I personally use with this indicator then you can sign up to my mentor Steven Hart’s EAP training program at TheTradingChannel.net.

When price is above the 50-EMA (Exponential Moving Average), the script begins looking for Long signals. When price is below the 50-EMA, the script begins looking for Short signals.

The trading signals are generated by engulfing candles.

For Long trades price must be above the 50-EMA then pull back at least 2 candles before putting in a bullish engulfing candle.

For Short trades price must be below the 50-EMA then pull back at least 2 candles before putting in a bearish engulfing candle.

The Stop Loss is set as 1ATR above/below swing high/lows (from the candle close). The Take Profit is 1ATR above/below the entry price (by default).

Some of these settings can be adjusted if you want to test variations of these parameters.

Settings

EMA Length:
You can adjust the length of the Exponential Moving Average with this setting.

Stop Distance (ATR):
This value is treated as an ATR multiplier.

Reward To Risk Ratio (Stop Loss x ?):
This setting will determine your profit-target distance. It is calculated based on your stop loss, so if you have a 20 pip stop loss and this is set to 3, then your take profit price will be drawn 60 pips above your entry candle.


Pine Script Basics Course
 

Source Code

// Created by Matthew J. Slabosz
// www.zenandtheartoftrading.com
// Last Updated: 2nd October, 2020
// @version=4
study(title="Aggressive Pullback Indicator", shorttitle="API", overlay=true)

// Get user input
emaLength = input(title="EMA Length:", defval=50, minval=1)
stopSizeInput = input(title="Stop Distance (ATR):", defval=1.0, minval=0.0)
riskToReward = input(title="R:R:", defval=1.0, minval=0.1)

// Get EMA & ATR
ema = ema(close, emaLength)
currentATR = atr(14)

// Calculate stop loss size
stopSize = currentATR * stopSizeInput

// Get SL and Target prices
tradeStopPrice = 0.0
tradeTargetPrice = 0.0
longEntrySize = close - lowest(low, 5) + stopSize
shortEntrySize = highest(high, 5) - close + stopSize

// Validate long signals
rule1L = close > ema and 
   open[1] > close[1] and close > open and close >= open[1] and close[1] >= open and 
   close - open > open[1] - close[1]  // Bullish engulfing?
rule2L = open < open[2]  // Satisfies pullback rule?
rule3L = close < open[5]  // Satisfies maximum engulfing rule?
rule4L = close < highest(open, 5)  // Satisfies swing high and ATR validation?
rule5L = highest(high, 5) > ema and (high[1] > ema or high[2] > ema)  // Make sure the past 2 candles have at least touched or stayed above the ema, cleans up some invalid signals
rule6L = close > ema and (close[1] > ema or close[2] > ema)  // Make sure no more than 1 candle has recently closed below EMA
validLong = rule1L and rule2L and (rule3L or rule4L) and rule5L and rule6L

// Validate short signals
rule1S = close < ema and 
   close[1] > open[1] and open > close and open >= close[1] and open[1] >= close and 
   open - close > close[1] - open[1]  // Bearish engulfing?
rule2S = open > open[2]  // Satisfies pullback rule?
rule3S = close > open[5]  // Satisfies maximum engulfing rule?
rule4S = close > lowest(open, 5)  // Satisfies swing low and ATR validation?
rule5S = lowest(low, 5) < ema and (low[1] < ema or low[2] < ema)  // Make sure the past 2 candles have at least touched or stayed below the ema, cleans up some invalid signals
rule6S = close < ema and (close[1] < ema or close[2] < ema)  // Make sure no more than 1 candle has recently closed above EMA
validShort = rule1S and rule2S and (rule3S or rule4S) and rule5S and rule6S

// Store long signal stop loss & target for drawing later
if validLong
    tradeStopPrice := close - longEntrySize
    tradeTargetPrice := close + longEntrySize * riskToReward

// Store short signal stop loss & target for drawing later
if validShort
    tradeStopPrice := close + shortEntrySize
    tradeTargetPrice := close - shortEntrySize * riskToReward
    
// Draw EMA
plot(ema, title="EMA", color=color.red, transp=0, linewidth=1)

// Draw signals
plotshape(validLong, title="Bullish Engulfing", location=location.belowbar, color=color.green, transp=0, style=shape.triangleup)
plotshape(validShort, title="Bearish Engulfing", color=color.red, transp=0, style=shape.triangledown)

// Draw stops & targets over 2 bars so the lines are more visible
plot(validLong or validLong[1] ? validLong ? tradeStopPrice : tradeStopPrice[1] : na, title="Long Stop Price", color=color.red, style=plot.style_linebr, transp=0)
plot(validShort or validShort[1] ? validShort ? tradeStopPrice : tradeStopPrice[1] : na, title="Short Stop Price", color=color.red, style=plot.style_linebr, transp=0)
plot(validLong or validLong[1] ? validLong ? tradeTargetPrice : tradeTargetPrice[1] : na, title="Long Target Price", color=color.green, style=plot.style_linebr, transp=0)
plot(validShort or validShort[1] ? validShort ? tradeTargetPrice : tradeTargetPrice[1] : na, title="Short Target Price", color=color.green, style=plot.style_linebr, transp=0)

// Send out an alert if this candle meets our conditions
alertcondition(validLong or validShort, title="API Alert!", message="Trend continuation signal for {{ticker}}")

Last Updated: 2nd October, 2020


Free Premium Charts!

5 1 vote
Article Rating
Subscribe
Notify of
guest
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Kerry Reinsel
Kerry Reinsel
1 year ago

Will your source code for PullBacks work on TOS platform? And for stocks, etf’s?

Hector Enrique Carmenati
Hector Enrique Carmenati
Reply to  mjslabosz
7 months ago

How much would you pay me for making the code in ThinkOrSwim?
I would make it for free but the covid pandemic has affected my incomes.