Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.

0
at https://mozilla.org/MPL/2.0/
// © sumeetchothe

//@version=5
strategy("Time Range Breakout Indicator", overlay = true)

/// User Inputs

timein = input.session(defval = "1015-1500")


timeout = input.session(defval = "1500-1515")

tradein = time(timeframe.period, timein)


tradeout = time(timeframe.period, timeout)

longStop = input.float(defval = 0.1,minval = 0.001, maxval = 5, step = 0.001, title


= "Long SL")
longTarget = input.float(defval = 0.1,minval = 0.001, maxval = 5, step = 0.001,
title = "Long Target")

shortStop = input.float(defval = 0.1,minval = 0.001, maxval = 5, step = 0.001,


title = "Short SL")
shortTarget = input.float(defval = 0.1,minval = 0.001, maxval = 5, step = 0.001,
title = "Short Target")

longsl = strategy.position_avg_price * (1 - longStop)


longtgt = strategy.position_avg_price * (1 + longTarget)

shortsl = strategy.position_avg_price * (1 + shortStop)


shorttgt = strategy.position_avg_price * (1 - shortTarget)

var fHigh = 0.0


var fLow = 0.0

if hour == 9 and minute == 15


fHigh := high
fLow := low

plot(fHigh, color = color.green, style = plot.style_linebr)


plot(fLow, color = color.red, style = plot.style_linebr)

buy = high[1] < fHigh and high[2] < fHigh and high[3] < fHigh
and low[1] > fLow and low[2] > fLow and low[3] > fLow
and ta.crossover(close, fHigh)

short =high[1] < fHigh and high[2] < fHigh and high[3] < fHigh
and low[1] > fLow and low[2] > fLow and low[3] > fLow
and ta.crossunder(close, fLow)

sell = tradeout or (close < fLow)


cover = tradeout or (close > fHigh)

plotshape(buy, style = shape.triangleup, location = location.belowbar, color =


color.green, text = "", textcolor = color.white)
plotshape(short, style = shape.triangledown, location = location.abovebar, color =
color.red, text = "", textcolor = color.white)
if buy
strategy.entry("long", strategy.long, comment = "LONG")
fHigh := na

if short
strategy.entry("short", strategy.short, comment = "SHORT")
fLow := na

strategy.exit("long", from_entry = "long", stop = longsl, limit = longtgt,


comment_loss = "LONG_LOSS", comment_profit = "LONG_Profit")
strategy.exit("short", from_entry = "short", stop = shortsl, limit = shorttgt,
comment_loss = "SHORT_LOSS", comment_profit = "SHORT_Profit")

if tradeout
strategy.close("long", when = sell, comment = "L_exit")
strategy.close("short", when = cover, comment = "S_Exit")
fHigh := na
fLow := na

You might also like