Aggressive Pullback Indicator


This advanced pullback indicator was created for Steven Hart’s Aggressive Pullback Strategy. It’s a trading tool I use every single day in conjunction with my ATR Stop Loss indicator. It sends me pullback alerts and draws my stops and targets for me which makes back testing 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.

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.



Source Code

// Created by Matthew J. Slabosz
// www.zenandtheartoftrading.com
// @version=3
study(title = "[ZEN] Aggressive Pullback Indicator", shorttitle="API", overlay = true, precision=5)

// 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="Reward To Risk Ratio (Stop Loss X ?):", defval=1.0, minval=0.1)

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

// Calculate stop loss info
decimals = abs(log(syminfo.mintick) / log(10)) 
stopSize = currentATR * stopSizeInput
    
// SL and Target variables
tradeStopPrice = 0.0
tradeTargetPrice = 0.0
longEntrySize = (close - lowest(low, 5)) + stopSize
shortEntrySize = (highest(high, 5) - close) + stopSize
    
// Plot data
plot(ema, title="EMA", color=red, transp=0, linewidth=1)

// 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

// Draw long signal only if rules are met
plotshape(validLong, title= "Bullish Engulfing", location=location.belowbar, color=green, transp=0, style=shape.triangleup, text="")

// 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

// Draw short signal only if rules are met
plotshape(validShort,  title= "Bearish Engulfing", color=red, transp=0, style=shape.triangledown, text="")

// Activate long flag and store position info
if(validLong)
    tradeStopPrice := close - longEntrySize
    tradeTargetPrice := close + (longEntrySize * riskToReward)
    
// Activate short flag and store position info
if(validShort)
    tradeStopPrice := close + shortEntrySize
    tradeTargetPrice := close - (shortEntrySize * riskToReward)
    
// Convert stop sizes to whole number for display purposes
if(decimals == 5)
    longEntrySize := longEntrySize * 10000
    shortEntrySize := shortEntrySize * 10000
if(decimals == 4)
    longEntrySize := longEntrySize * 1000
    shortEntrySize := shortEntrySize * 1000
if(decimals == 3)
    longEntrySize := longEntrySize * 100
    shortEntrySize := shortEntrySize * 100
if(decimals == 2)
    longEntrySize := longEntrySize * 10
    shortEntrySize := shortEntrySize * 10
    
// Draw stops & targets
plot((validLong or validLong[1]) ? (validLong ? tradeStopPrice : tradeStopPrice[1]) : na, title="Long Stop Price", color=red, style=linebr, transp=0)
plot((validShort or validShort[1]) ? (validShort ? tradeStopPrice : tradeStopPrice[1]) : na, title="Short Stop Price", color=red, style=linebr, transp=0)
plot((validLong or validLong[1]) ? (validLong ? tradeTargetPrice : tradeTargetPrice[1]) : na, title="Long Target Price", color=green, style=linebr, transp=0)
plot((validShort or validShort[1]) ? (validShort ? tradeTargetPrice : tradeTargetPrice[1]) : na, title="Short Target Price", color=green, 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 XXX")

Last Updated: 8th May, 2019


TradingView Charting Platform

Leave a Comment, Question or Suggestion