0% found this document useful (0 votes)
29 views

Pull Back for Scalping

Uploaded by

PrashantKumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Pull Back for Scalping

Uploaded by

PrashantKumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

//@version=4

//

study(title="Scalping PullBack ", shorttitle="Scalping PullBack", overlay=true)

// Inputs
devUp1 = input(1.28, title="Stdev above (1)")
devDn1 = input(1.28, title="Stdev below (1)")

devUp2 = input(2.01, title="Stdev above (2)")


devDn2 = input(2.01, title="Stdev below (2)")

devUp3 = input(2.51, title="Stdev above (3)")


devDn3 = input(2.51, title="Stdev below (3)")

devUp4 = input(3.09, title="Stdev above (4)")


devDn4 = input(3.09, title="Stdev below (4)")

devUp5 = input(4.01, title="Stdev above (5)")


devDn5 = input(4.01, title="Stdev below (5)")

showDv2 = input(true, title="Show second group of bands?")


showDv3 = input(true, title="Show third group of bands?")
showDv4 = input(false, title="Show fourth group of bands?")
showDv5 = input(false, title="Show fifth group of bands?")

showPrevVWAP = input(false, title="Show previous VWAP close")

// Variables
var float vwapsum = na
var float volumesum = na
var float v2sum = na
var float prevwap = na

// Calculate VWAP
newSession = change(dayofweek)
vwapsum := newSession ? hl2 * volume : vwapsum + hl2 * volume
volumesum := newSession ? volume : volumesum + volume
v2sum := newSession ? volume * hl2 * hl2 : v2sum + volume * hl2 * hl2
myvwap = vwapsum / volumesum
dev = sqrt(max(v2sum / volumesum - myvwap * myvwap, 0))

// Plot VWAP and bands


plot(myvwap, style=plot.style_line, title="VWAP", color=color.black)
plot(myvwap + devUp1 * dev, style=plot.style_line, title="VWAP Upper",
color=color.gray)
plot(myvwap - devDn1 * dev, style=plot.style_line, title="VWAP Lower",
color=color.gray)
plot(showDv2 ? myvwap + devUp2 * dev : na, color=color.red, title="VWAP Upper (2)")
plot(showDv2 ? myvwap - devDn2 * dev : na, color=color.green, title="VWAP Lower (2)")

plot(showDv3 ? myvwap + devUp3 * dev : na, title="VWAP Upper (3)", color=color.red)


plot(showDv3 ? myvwap - devDn3 * dev : na, title="VWAP Lower (3)", color=color.green)

plot(showDv4 ? myvwap + devUp4 * dev : na, title="VWAP Upper (4)", color=color.red)


plot(showDv4 ? myvwap - devDn4 * dev : na, title="VWAP Lower (4)", color=color.green)

plot(showDv5 ? myvwap + devUp5 * dev : na, title="VWAP Upper (5)", color=color.red)


plot(showDv5 ? myvwap - devDn5 * dev : na, title="VWAP Lower (5)", color=color.green)

prevwap := newSession ? myvwap[1] : prevwap[1]


plot(showPrevVWAP ? prevwap : na, style=plot.style_line, color=close > prevwap ?
color.green : color.red)

// === INPUTS ===


HiLoLen = input(34, minval=2, title="High Low PAC channel Length")
fastEMAlength = input(89, minval=2)
mediumEMAlength = input(200, minval=2)
slowEMAlength = input(600, minval=2)
ShowFastEMA = input(true)
ShowMediumEMA = input(true)
ShowSlowEMA = input(false)
ShowHHLL = input(false)
ShowFractals = input(true)
filterBW = input(false, title="Show Ideal Fractals Only")
ShowBarColor = input(true, title="Show coloured Bars around PAC")
ShowBuySell = input(true, title="Show Buy/Sell Alert Arrows")
Lookback = input(3, minval=1, title="Pullback Lookback for PAC Cross Check")
DelayArrow = input(false, title="Show Alert Arrows Only on Closed Candles")
Delay = DelayArrow ? 1 : 0
ShowTrendBGcolor= input(true)
UseHAcandles = input(true, title="Use Heikin Ashi Candles in Algo Calculations")
//
// === /INPUTS ===

// === BASE FUNCTIONS ===

haClose = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, close)


: close
haOpen = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period,
open) : open
haHigh = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, high)
: high
haLow = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, low) :
low

// ||--- Fractal Recognition Functions: ---------------------------------------------------------------||


isRegularFractal(mode) =>
ret = mode == 1 ? high[4] < high[3] and high[3] < high[2] and high[2] > high[1] and
high[1] > high[0] : mode == -1 ?
low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] < low[0] :
false
ret

isBWFractal(mode) =>
ret = mode == 1 ? high[4] < high[2] and high[3] <= high[2] and high[2] >= high[1]
and
high[2] > high[0] : mode == -1 ?
low[4] > low[2] and low[3] >= low[2] and low[2] <= low[1] and low[2] < low[0] :
false
ret
// ||-----------------------------------------------------------------------------------------------------||

//
// === /BASE FUNCTIONS ===

// === SERIES SETUP ===


//

// ||--- Setup Moving Averages and PAC channel:


// ||-----------------------------------------------------------------------------------------------------||
fastEMA = ema(haClose, fastEMAlength)
mediumEMA = ema(haClose, mediumEMAlength)
slowEMA = ema(haClose, slowEMAlength)
pacC = ema(haClose, HiLoLen)
pacL = ema(haLow, HiLoLen)
pacU = ema(haHigh, HiLoLen)
TrendDirection = fastEMA > mediumEMA and pacL > mediumEMA ? 1 :
fastEMA < mediumEMA and pacU < mediumEMA ? -1 : 0

// ||--- Fractal Recognition:


// ||-----------------------------------------------------------------------------------------------------||
filteredtopf = filterBW ? isRegularFractal(1) : isBWFractal(1)
filteredbotf = filterBW ? isRegularFractal(-1) : isBWFractal(-1)
// ||-----------------------------------------------------------------------------------------------------||
// ||--- Higher Highs, Lower Highs, Higher Lows, Lower Lows
-------------------------------------------||
valuewhen_H0 = valuewhen(filteredtopf == true, high[2], 0)
valuewhen_H1 = valuewhen(filteredtopf == true, high[2], 1)
valuewhen_H2 = valuewhen(filteredtopf == true, high[2], 2)
//
higherhigh = filteredtopf == false ? false :
valuewhen_H1 < valuewhen_H0 and valuewhen_H2 < valuewhen_H0
lowerhigh = filteredtopf == false ? false :
valuewhen_H1 > valuewhen_H0 and valuewhen_H2 > valuewhen_H0
valuewhen_L0 = valuewhen(filteredbotf == true, low[2], 0)
valuewhen_L1 = valuewhen(filteredbotf == true, low[2], 1)
valuewhen_L2 = valuewhen(filteredbotf == true, low[2], 2)
//
higherlow = filteredbotf == false ? false :
valuewhen_L1 < valuewhen_L0 and valuewhen_L2 < valuewhen_L0
lowerlow = filteredbotf == false ? false :
valuewhen_L1 > valuewhen_L0 and valuewhen_L2 > valuewhen_L0

//
// === /SERIES ===

//
// === PLOTTING ===
//
// Plot the Price Action Channel (PAC) base on EMA high,low and close
L = plot(pacL, color=color.gray, linewidth=1, title="High PAC EMA", transp=50)
U = plot(pacU, color=color.gray, linewidth=1, title="Low PAC EMA", transp=50)
C = plot(pacC, color=color.red, linewidth=2, title="Close PAC EMA", transp=0)
fill(L, U, color=color.gray, transp=90, title="Fill HiLo PAC")

// Colour bars according to the close position relative to the PAC selected.
BARcolor = haClose > pacU ? color.blue : haClose < pacL ? color.red : color.gray
barcolor(ShowBarColor ? BARcolor : na, title="Bar Colours")
//
BGcolor = TrendDirection == 1 ? color.green :
TrendDirection == -1 ? color.red : color.yellow
bgcolor(ShowTrendBGcolor ? BGcolor : na, transp=90, title="Trend BG Color")

// Draw the EMA ribbon


plot(ShowFastEMA ? fastEMA : na, color=color.green, linewidth=2, transp=20,
title="fastEMA")
plot(ShowMediumEMA ? mediumEMA : na, color=color.blue, linewidth=3, transp=20,
title="mediumEMA")
plot(ShowSlowEMA ? slowEMA : na, color=color.black, linewidth=4, transp=20,
title="slowEMA")
//
plotshape(ShowFractals ? filteredtopf : na, title='Filtered Top Fractals',
style=shape.triangledown, location=location.abovebar, color=color.red, offset=-2)
plotshape(ShowFractals ? filteredbotf : na, title='Filtered Bottom Fractals',
style=shape.triangleup, location=location.belowbar, color=color.lime, offset=-2)
//
plotshape(ShowHHLL ? higherhigh : na, title='Higher High', style=shape.square,
location=location.abovebar, color=color.maroon, text="[HH]", offset=-2)
plotshape(ShowHHLL ? lowerhigh : na, title='Lower High', style=shape.square,
location=location.abovebar, color=color.maroon, text="[LH]", offset=-2)
plotshape(ShowHHLL ? higherlow : na, title='High Low', style=shape.square,
location=location.belowbar, color=color.green, text="[HL]", offset=-2)
plotshape(ShowHHLL ? lowerlow : na, title='Lower Low', style=shape.square,
location=location.belowbar, color=color.green, text="[LL]", offset=-2)
//
// === /PLOTTING ===

// === ALERTING ===


//

// Initialise Trading state.


TradeDirection = 0
TradeDirection := nz(TradeDirection[1])
//
pacExitU = haOpen < pacU and haClose > pacU and
barssince(haClose<pacC)<=Lookback
pacExitL = haOpen > pacL and haClose < pacL and
barssince(haClose>pacC)<=Lookback
plotshape(barssince(haClose<pacC),color=na,location=location.bottom,title="barssince(
haClose<pacC)")
plotshape(barssince(close>pacC),color=na,location=location.bottom,title="barssince(ha
Close>pacC)")
//
Buy = TrendDirection == 1 and pacExitU
Sell = TrendDirection == -1 and pacExitL
//
// Keep Current trading state until Pullback occurs or New Recovery.
TradeDirection := TradeDirection == 1 and haClose<pacC ? 0 :
TradeDirection == -1 and haClose>pacC ? 0 :
TradeDirection == 0 and Buy ? 1 :
TradeDirection == 0 and Sell ? -1 : TradeDirection

// Show buy/sell arrows


plotarrow(ShowBuySell and nz(TradeDirection[1+Delay]) == 0 and TradeDirection[Delay]
!= 0 ? TradeDirection[Delay] : na, offset=-Delay,
colorup=color.green, colordown=color.maroon, transp=20, minheight=20,
maxheight=50, title="Buy/Sell Arrow")
//
// Create alerts for TradingView Alarm subsystem.
Long = nz(TradeDirection[1]) == 0 and TradeDirection == 1
Short = nz(TradeDirection[1]) == 0 and TradeDirection == -1
alertcondition(Long, title="Buy Condition", message="BUY")
alertcondition(Short, title="Sell Condition", message="SELL")
//
// === /ALERTING ===

// === eof.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy