Strategy · Pine Script v5 · On the chart

Hotch Break Strat (Template)

by rajatjpatel· code credited to Hotchachachaaa

A strategy framework that provides switches for ATR bands, a trading session, a trend filter, three moving averages and take profit and stop loss levels.

View on GitHub

Repaints

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code130
Settings25inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago18 Oct 2022

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

130 lines of Pine Script v5 from message (10).txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

message (10).txt
// © Hotchachachaaa

//@version=5
//// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// ©Hotchachachaaa
//@version=5
MAX_LABELS = 100
strategy("Hotch break strat", overlay=true, pyramiding=20, default_qty_type= strategy.percent_of_equity, default_qty_value = 1, calc_on_every_tick=true, slippage=0,commission_type=strategy.commission.percent,commission_value=0.014,max_labels_count = MAX_LABELS)
strat_dir_input = input.string(title="Strategy Direction", defval="all", options=["long", "short", "all"])
strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.all
strategy.risk.allow_entry_in(strat_dir_value)
//////////////////////////////////////////////////////////////////////
ATRBandsOO = input.bool(title="ATR Bands", group="Features", defval= true)
SessionOO = input.bool(title="Session", group="Features", defval= true)
TSOO = input.bool(title="Trend SNEK", group="Features", defval= true)
MA1OO = input.bool(title="MA 1", group="Features", defval= true)
MA2OO = input.bool(title="MA 2", group="Features", defval= true)
MA3OO = input.bool(title="MA 3", group="Features", defval= true)
TPSLOO = input.bool(title="TP/SL", group="Features", defval= true)

string sessionInput = input.session("0600-1800", "Session")
string daysInput = input.string("1234567", tooltip = "1 = Sunday, 7 = Saturday")
sessionString = sessionInput + ":" + daysInput
inSession = not na(time(timeframe.period, sessionString))
bgcolor(inSession ? color.new(color.silver,85) : na)

// Testing Start End Dates

testStartYear = input(2020, "Backtest Start Year")
testStartMonth = input(10, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

//Stop date if you want to use a specific range of dates

testStopYear = input(2030, "Backtest Stop Year")
testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(30, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)


testPeriod() =>
    time >= testPeriodStart and time <= testPeriodStop ? true : false
 
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////ADD INDICATOR CODE HERE.  










///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TP and SL ATR ,group= "Take Profit and Stop Loss"
atrPeriodsltp = input.int(title = "ATR Period for TP & SL", defval = 14, minval = 1,group= "Take Profit and Stop Loss")
srcUpper = input(title = "Source TP",  defval = close,group= "Take Profit and Stop Loss")
srcLower = input(title = "Source SL",  defval = close,group= "Take Profit and Stop Loss")
atrMultiplierTP = input(title = "ATR Multiplier TP", defval = 3,group= "Take Profit and Stop Loss")
atrMultiplierSL = input(title = "ATR Multiplier SL", defval = 1,group= "Take Profit and Stop Loss")

// TP and SL ATR
atr = ta.atr(atrPeriodsltp)
colorATRUpper = (trend==1  ? color.lime : trend==-1 ? color.red :  na )
colorATRLower = (trend==-1 ? color.lime : trend==1 ? color.red :  na )

ATRUpper = trend == 1 ? (srcUpper + atr * atrMultiplierTP) : trend == -1 ? (srcUpper + atr * atrMultiplierSL) :na
ATRLower = trend == 1 ? (srcLower - atr * atrMultiplierSL) : trend == -1 ? (srcLower - atr * atrMultiplierTP) :na


plot(ATRUpper,title="TP/SL Upper",color =ATRBandsOO ? colorATRUpper :na, offset=1 )
plot(ATRLower,title="TP/SL lower",color =ATRBandsOO ? colorATRLower :na, offset=1 )



/////////////////////////////////////////////////////// Long and Short Conditions /////////////////////////////////////////////////////////////
entryType= input.string(title="Sup/Res Entry", defval="ST1",options= ["ST1","ST2"], group= "Trade Logic")
pipsby= input.int(title = "Pips", defval = 20, minval = 1)
slcalc = input.string(title="SL Calculation type", defval="ATR",options= ["ATR","Pips"], group= "Trade Logic")
pipsMult= input.int(title = "Pip Multiplier", defval = 3, minval = 1)


varip float currentLongSL= na
varip float currentShortSL= na             
varip float currentLongTP= na
varip float currentShortTP= na
varip float closeLast =na 
varip float lowUsePivotAtTimeOfEntry = na
varip float highUsePivotAtTimeOfEntry = na

shortcondition = /////////////////////// ASSIGN LONG TRADE LOGIC HERE. 
longcondition =    /////////////////////// ASSIGN SHORT TRADE LOGIC HERE. 

longCloseCondition =  ta.crossunder(low,currentLongSL) or ta.crossover(high,currentLongTP) or ta.crossunder(close,lowUsePivotST2) and not (open - close < high - open)
shortCloseCondition =   ta.crossover(high,currentShortSL) or ta.crossunder(low,currentShortTP) or ta.crossover(close,highUsePivotST2 ) and not(open - low > close - open)



// Place Orders

if (longcondition) and testPeriod() and strategy.position_size == 0
    closeLast := close
    currentLongSL := slcalc == "ATR" ? ATRLower : slcalc == "Pips" ? low[1] - (20 *syminfo.mintick) : na
    currentLongTP := slcalc == "ATR" ? ATRUpper : slcalc == "Pips" ? math.abs(close- currentLongSL)*pipsMult + close : na
    strategy.entry("Long", strategy.long)

if (shortcondition) and testPeriod() and strategy.position_size == 0
    closeLast := close
    currentLongSL := slcalc == "ATR" ? ATRLower : slcalc == "Pips" ? low[1] - (20 *syminfo.mintick) : na
    currentLongTP := slcalc == "ATR" ? ATRUpper : slcalc == "Pips" ? math.abs(close- currentLongSL)*pipsMult + close : na
    strategy.entry("Short", strategy.long)



l2= plot(strategy.position_size <= 0 ? na : currentLongSL, color=color.red,  linewidth=2, join = false,style=plot.style_linebr)
l1=plot(strategy.position_size <= 0 ? na : currentLongTP, color=color.green,  linewidth=2, join = false,style=plot.style_linebr)
closeLast1 =plot(strategy.position_size <= 0 ? na : closeLast, color=color.blue, linewidth=2, join = false,style=plot.style_linebr)
s2 =plot(strategy.position_size >= 0 ? na : currentShortSL, color=color.red,  linewidth=2, join = false,style=plot.style_linebr)
s1= plot(strategy.position_size >= 0 ? na : currentShortTP, color=color.green,  linewidth=2,join = false,style=plot.style_linebr)
closeLast2 =plot(strategy.position_size >= 0 ? na : closeLast, color=color.blue, linewidth=2, join = false,style=plot.style_linebr)

fill(closeLast1,l2,color=color.new(color.red, 90))
fill(closeLast1,l1,color=color.new(color.green, 90))
fill(closeLast2,s2,color=color.new(color.red, 90))
fill(closeLast2,s1,color=color.new(color.green, 90))
strategy.close("Long",longCloseCondition)
strategy.close("Short",shortCloseCondition)

Overview

Hotch Break Strat (Template) has a session and weekday filter, backtest start and stop dates, and a long, short or both setting. Take profit and stop loss are ATR multiples, three and one by default. The section for entry indicators is blank in this file, so entries depend on code the user adds. It stacks up to 20 entries at 1 percent of equity and calculates on every tick.

Details

Published by

rajatjpatel on GitHub

Code credit

Hotchachachaaa, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy can add several entries in the same direction
  • The strategy enters trades without a stop loss

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Strategy Directionstringallstrat_dir_input
ATR BandsbooltrueATRBandsOO
SessionbooltrueSessionOO
Trend SNEKbooltrueTSOO
MA 1booltrueMA1OO
MA 2booltrueMA2OO
MA 3booltrueMA3OO
TP/SLbooltrueTPSLOO
Sessionsession0600-1800sessionInput
daysInputstring1234567daysInput
Backtest Start Yearint2020testStartYear
Backtest Start Monthint10testStartMonth
Show all 25 settings
SettingTypeDefaultVariable
Backtest Start Dayint1testStartDay
Backtest Stop Yearint2030testStopYear
Backtest Stop Monthint12testStopMonth
Backtest Stop Dayint30testStopDay
ATR Period for TP & SLint14atrPeriodsltp
Source TPsourceclosesrcUpper
Source SLsourceclosesrcLower
ATR Multiplier TPint3atrMultiplierTP
ATR Multiplier SLint1atrMultiplierSL
Sup/Res EntrystringST1entryType
Pipsint20pipsby
SL Calculation typestringATRslcalc
Pip Multiplierint3pipsMult
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This overlay strategy offers two selectable entry modes: a Bollinger squeeze on typical price and a simple moving-average cross. It filters trades by weekday, session, date range, and an optional news window, and can restrict direction or invert the side. Risk

Strategy v5 Volatility & bandsMoving averages
Updated yesterday · None stated GitHub repository of Boilerplate Configurable Strategy [Yosiet]

Daily Bias + FVG Strategy

by TradersPost
228 stars

This overlay strategy plots previous-day high and low, the daily open, and fair value gap zones on the price chart. It takes entries on a selectable timeframe when the FVG requirement and an optional session window allow them, then uses an ATR or fixed pip sto

Strategy v6 SMC / ICT / price actionSupport & resistance Repaints
Updated 3 months ago · None stated GitHub repository of Daily Bias + FVG Strategy
106 stars

This strategy places buy-stop and sell-stop orders around the opening-session high and low, offset by a user-defined pip gap, and only allows those orders during a separate trading session. It exits with a fixed or ATR-based stop loss and a matching take-profi

Strategy v5 Sessions & timeBreakout Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 50 Pips A Day Strategy - Kaspricci

Turtle MACD Time-Zone Filter

by skywalker0803r
42 stars

This strategy enters long when price closes above the prior Donchian high and short when it closes below the prior Donchian low, only while flat and inside a Taipei-hour window. It exits on a MACD histogram reversal or through an ATR stop and a percentage take

Strategy v5 BreakoutOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Turtle MACD Time-Zone Filter

ORION: Hybrid Strategy

by eddiebelaval
7 stars

This strategy identifies volatility breakout opportunities by constructing dynamic ATR-based price boxes and detecting volatility squeezes. Trades are filtered using an exponential moving average trend condition and designated session hours. Entries trigger up

Strategy v5 Volatility & bandsBreakout
Updated 3 months ago · None stated GitHub repository of ORION: Hybrid Strategy

More Sessions & time scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers