Professional Documents
Culture Documents
Volume Breakout
Volume Breakout
Volume Breakout
///// breakout
////////////////////////////
// A switch to control background coloring of the test period - Use for easy
visualization of backtest range and manual calculation of
// buy and hold (via measurement) if doing prior periods since value in Strategy
Tester extends to current date by default
testPeriodBackground = input(title='Color Background - Test Period?', defval=false)
testPeriodBackgroundColor = testPeriodBackground and time >= Start and time <=
Finish ? #00FF00 : na
//bgcolor(testPeriodBackgroundColor, transp=95)
// == FILTERING ==
// Inputs
useMaFilter = input(title='Use MA for Filtering?', defval=false)
maType = input.string(defval='EMA', options=['EMA', 'SMA'], title='MA Type For
Filtering')
maLength = input.int(defval=200, title='MA Period for Filtering', minval=1)
// Check to see if the useMaFilter check box is checked, this then inputs this
conditional "maFilterCheck" variable into the strategy entry
maFilterCheck = if useMaFilter == true
maFilter
else
0
// === PLOT SWING HIGH/LOW AND MOST RECENT LOW TO USE AS STOP LOSS EXIT POINT ===
// Inputs
//pvtLenL = input(3, minval=1, title="Pivot Length Left Hand Side") //use if
you want to change this to an input
//pvtLenR = input(3, minval=1, title="Pivot Length Right Hand Side") //use if
you want to change this to an input
pvtLenL = 3
pvtLenR = 3
// Get High and Low Pivot Points
pvthi_ = ta.pivothigh(high2, pvtLenL, pvtLenR)
pvtlo_ = ta.pivotlow(low2, pvtLenL, pvtLenR)
// Count How many candles for current Pivot Level, If new reset.
counthi = ta.barssince(not na(pvthi))
countlo = ta.barssince(not na(pvtlo))
pvthis = fixnan(pvthi)
pvtlos = fixnan(pvtlo)
hipc = ta.change(pvthis) != 0 ? na : color.maroon
lopc = ta.change(pvtlos) != 0 ? na : color.green
// Stop Levels
stopBuff = input.float(0.0, minval=-2, title='Stop Loss Buffer off Swing Low (%)')
stopPerc = stopBuff * .01 // Turn stop buffer input into a percentage
stopLevel = ta.valuewhen(pvtlo_, low2[pvtLenR], 0) //Stop Level at Swing Low
stopLevel2 = stopLevel - stopLevel * stopPerc // Stop Level with user-defined
buffer to avoid stop hunts and give breathing room
//plot(stopLevel2, style=plot.style_line, color=color.new(color.orange, 50),
show_last=1, linewidth=1, trackprice=true)
buyLevel = ta.valuewhen(pvthi_, high2[pvtLenR], 0) //Buy level at Swing High
buyLevel2 = buyLevel + buyLevel * stopPerc // Buy-stop level with user-defined
buffer to avoid stop hunts and give breathing room
//plot(buyLevel2, style=plot.style_line, color=color.new(color.aqua, 50),
show_last=1, linewidth=1, trackprice=true)
if buyStudy
label.new(x=bar_index, y=math.min(low, low[1]), text="B", color=color.blue,
textcolor=color.white, style=label.style_label_up, size=size.small)
if sellStudy
label.new(x=bar_index, y=math.max(high, high[1]), text="S",
color=color.fuchsia, textcolor=color.white, style=label.style_label_down,
size=size.small)