//-------------------------------------------------------------------------
// Code Name: SmashBar Larry Style
//-------------------------------------------------------------------------
//------------------------------------------------------------------------------------//
// Strategy: Smash Day Pattern - Type C
// Developer: Larry Williams
// Concept: Trading strategy based on a failed price pattern.
// Time Frame: Any ?
// Inspiration: https://oxfordstrat.com/trading-strategies/smash-day-pattern-c/
//------------------------------------------------------------------------------------//
// Definition of code parameters
DEFPARAM CumulateOrders = false // Cumulating positions deactivated
DEFPARAM PreloadBars = 10000
// Position Size
positionsize=1
tradetype=3 // long = 1 ; short = 2 ; long&short = 3
//====== SmashBar STRATEGY ==============================================
// Long pattern
c10=low<lowest[2](low[1])
c11=close<low[1]
long = c10 and c11
// Short pattern
c12=high>highest[2](high[1])
c13=close>high[1]
short = c12 and c13
// Conditions to enter Long positions
if tradetype=1 or tradetype=3 then
IF NOT ONMARKET AND long THEN
BUY positionsize CONTRACT AT MARKET
ENDIF
endif
// Conditions to enter Short positions
if tradetype=2 or tradetype=3 then
IF NOT ONMARKET AND short THEN
SELLSHORT positionsize CONTRACT AT MARKET
ENDIF
endif
//==== TRAILING STOP %
trailingPercent = .24 //org .26
stepPercent = .012 //org .014
if onmarket then
trailingstart = tradeprice(1)*(trailingpercent/100) //trailing will start @trailinstart points profit
trailingstep = tradeprice(1)*(stepPercent/100) //% step to move the stop
endif
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart THEN
newSL = tradeprice(1)+trailingstep
ENDIF
//next moves
IF newSL>0 AND close-newSL>trailingstep THEN
newSL = newSL+trailingstep
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart THEN
newSL = tradeprice(1)-trailingstep
ENDIF
//next moves
IF newSL>0 AND newSL-close>trailingstep THEN
newSL = newSL-trailingstep
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF