strategy(“My strategy”, overlay=true, margin_long=100, margin_short=100)
longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
//@version=5
// Bollinger Bands: Madrid : 14/SEP/2014 11:07 : 2.0
// This displays the traditional Bollinger Bands, the difference is
// that the 1st and 2nd StdDev are outlined with two colors and two
// different levels, one for each Standard Deviation
indicator(shorttitle='MBB', title='Bollinger Bands', overlay=true)
// Input parameters
src = input(close)
length = input.int(34, minval=1)
mult = input.float(2.0, minval=0.001, maxval=50)
// Bollinger Bands calculations
basis = ta.sma(src, length)
dev = ta.stdev(src, length)
dev2 = mult * dev
upper1 = basis + dev
lower1 = basis - dev
upper2 = basis + dev2
lower2 = basis - dev2
// Color settings
colorBasis = src >= basis ? color.blue : color.orange
// Plotting Bollinger Bands
pBasis = plot(basis, linewidth=2, color=colorBasis)
pUpper1 = plot(upper1, color=color.new(color.blue, 0), style=plot.style_circles)
pUpper2 = plot(upper2, color=color.new(color.blue, 0))
pLower1 = plot(lower1, color=color.new(color.orange, 0), style=plot.style_circles)
pLower2 = plot(lower2, color=color.new(color.orange, 0))
fill(pBasis, pUpper2, color=color.new(color.blue, 80))
fill(pUpper1, pUpper2, color=color.new(color.blue, 80))
fill(pBasis, pLower2, color=color.new(color.orange, 80))
fill(pLower1, pLower2, color=color.new(color.orange, 80))
// Trading Strategy
var float stopLoss = na
var float takeProfit = na
// Long condition: Price closes above the upper Bollinger Band
// Short condition: Price closes below the lower Bollinger BandshortCondition = ta.crossunder(close, lower2)
// Entry and exit logic
if (longCondition)
strategy.entry("Long", strategy.long)
stopLoss := na
takeProfit := na
if (shortCondition)
strategy.entry("Short", strategy.short)
stopLoss := na
takeProfit := na
// Exit logic for long positions
if (strategy.position_size > 0 and shortCondition)
strategy.close("Long")
// Exit logic for short positions
if (strategy.position_size < 0 and longCondition)
strategy.close("Short")
This is the error message I get when trying to insert script into my trading view chart. First time attempting so. have no idea how or where to fix error message.
Scripts must contain one declaration statement: indicator()
, strategy()
or library()
. Your script has 2
I entered the script into Jason chatgpt and asked to fix error but in keeps creating a new error and unable to add to my charts
greg s is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.