0% found this document useful (0 votes)
1K views3 pages

Pine Script Trading Strategy Example

This document contains a trading strategy script written in Pine Script for use on TradingView. It implements a Bollinger Bands strategy with conditions for entering long and short positions based on price movements relative to the upper and lower bands, as well as the VWAP. The script also includes parameters for trailing profit and minimum profit points, along with session timing for trading and square-off windows.

Uploaded by

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

Pine Script Trading Strategy Example

This document contains a trading strategy script written in Pine Script for use on TradingView. It implements a Bollinger Bands strategy with conditions for entering long and short positions based on price movements relative to the upper and lower bands, as well as the VWAP. The script also includes parameters for trailing profit and minimum profit points, along with session timing for trading and square-off windows.

Uploaded by

9710532359
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
[Link]

//@version=5
strategy(title="BB", overlay = true)

inputforema = input(title="EMA", defval=50)


source=close
vwap=[Link](open)
length = [Link](21, minval=1)
mult = [Link](1.0, minval=0.001, maxval=50)
basis = [Link](source, length)
dev = mult * [Link](source, length)
upper = basis + dev
Lower = basis - dev
traillong=(basis+upper)/2
trailshort=(basis+Lower)/2
tradeWindow = [Link](title='Trade Timings', defval='0915-1530:23456')
sqOffWindow = [Link](title='Square off Timings', defval='1520-1525:23456')

var infinity = 9999999999


barsInSession(sess) =>
time([Link], sess) != 0

sessionBegins(sess) =>
t = time("D", sess)
[Link] and na(t[1]) and not na(t) or t[1] < t

inSession = barsInSession(tradeWindow)
sqSession = barsInSession(sqOffWindow)
sqOffTime = sqSession and not sqSession[1]

showLimits = [Link]

trail_profit_points = [Link](title = 'Trail profit by points', defval = 10)


minimum_profit_points = [Link](title = 'Minimum profit by points', defval = 80)

var bool longcondition = na


var bool shortcondition = na
var bool long_stop_loss = na
var bool short_stop_loss = na
var float initial_long_entry_price = na
var float initial_short_entry_price = na
var float stoploss_trigger_price_long = na
var float stoploss_trigger_price_short = na
EMA = [Link](close, inputforema)
VOLWAP = [Link](close)
plot(VOLWAP,title="VWAP",color=[Link])
plot(EMA, title="EMA", color=[Link])
plot(upper,title="upper",color=[Link])
plot(Lower,title="lower",color=[Link])
plot(basis,title="basis",color=[Link])

longcondition := inSession and close>upper and close>vwap


if longcondition
initial_long_entry_price := close
stoploss_trigger_price_long := initial_long_entry_price+minimum_profit_points

if close>stoploss_trigger_price_long
long_stop_loss := [Link](close,upper)

longSL = [Link](close,traillong) or sqOffTime or long_stop_loss


if longSL
initial_long_entry_price := na
stoploss_trigger_price_long := na
long_stop_loss := na

[Link]("BUY", [Link], 2, when=longcondition)


[Link]("BUY", when=longSL)

shortcondition := inSession and close<Lower and close<vwap


if shortcondition
initial_short_entry_price := close
stoploss_trigger_price_short := initial_short_entry_price-minimum_profit_points

if close<stoploss_trigger_price_short
short_stop_loss := [Link](close,Lower)

shortSL = [Link](close,trailshort) or sqOffTime or short_stop_loss


if shortSL
initial_short_entry_price := na
stoploss_trigger_price_short := na
short_stop_loss := na

[Link]("SELL",[Link], 2,when=shortcondition)
[Link]("SELL",when=shortSL)
// Back-Testing //

You might also like