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

//@version=5

strategy(title='Scalping Strategy by Chadi', overlay=true)

// Chart Properties
testStartYear = input(2010, 'Backtest Start Year')
testStartMonth = input(01, 'Backtest Start Month')
testStartDay = input(1, 'Backtest Start Day')
testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)

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)

// A switch to control background coloring of the test period


testPeriodBackground = input(title='Color Background?', defval=true)
testPeriodBackgroundColor = testPeriodBackground and time >= testPeriodStart and
time <= testPeriodStop ? #6c6f6c : na

// User provided values


smaLength = input(title='SMA Length', defval=20) // Middle band period length
(moving average)
stdLength = input(title='StdDev Length', defval=20) // Range to apply bands to
ubOffset = input.float(title='Upper Band Offset', defval=2.0, step=0.5) // Number
of standard deviations above MA
lbOffset = input.float(title='Lower Band Offset', defval=2.0, step=0.5) // Number
of standard deviation below MA

testPeriod() =>
time >= testPeriodStart and time <= testPeriodStop ? true : false

smaValue = ta.sma(close, smaLength) // Middle band


stdDev = ta.stdev(close, stdLength)
upperBand = smaValue + stdDev * ubOffset // Top band
lowerBand = smaValue - stdDev * lbOffset // Bottom band

longCondition = ta.crossover(close, lowerBand)


closeLongCondition = close >= upperBand

if longCondition and testPeriod()


strategy.entry(id='CHRI', direction=strategy.long, qty=100)

strategy.close(id='CHRI', comment='BI3', when=closeLongCondition)

You might also like