Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © calcajack
- //@version=4
- strategy("Bollinger Bands Strategy", shorttitle="BB Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=5)
- //definisco gli INPUT
- standard_dev = input(20, "deviazione standard", input.integer, minval=1, maxval=50)
- offset = input(2,"offset", input.float, minval=0.1, maxval=10)
- // calcolo e disegno le tre bande
- centralBand = sma(close, 20)
- plot(centralBand, "SMA", color.new(color.red, 50) )
- upperBand = centralBand + stdev(close, standard_dev)*offset
- plot(upperBand, "Upper Band", color.new(color.blue, 25) )
- lowerBand = centralBand - stdev(close, standard_dev)*offset
- plot(lowerBand, "Lower Band", color.new(color.blue, 25) )
- //plot(candleClose, "candleClose", color.new(color.yellow, 0) )
- //condizioni per apertura Long
- openLong = crossover(close, lowerBand)
- strategy.entry("long", true,when=openLong)
- //condizioni per apertura Short
- openShort = crossunder(close, upperBand)
- strategy.entry("short", false,when=openShort)
- //condizioni per chiusura Long
- closeLong1 = crossover(close, centralBand)
- closeLong2 = crossover(high, upperBand)
- strategy.close("long", when=closeLong1, qty_percent=66)
- strategy.close("long", when=closeLong2)
- strategy.close("long", when=crossunder(close,centralBand))
- //condizioni per chiusura Short
- closeShort1 = crossunder(close, centralBand)
- closeShort2 = crossunder(low, lowerBand)
- strategy.close("short", when=closeShort1, qty_percent=66)
- strategy.close("short", when=closeShort2)
- strategy.close("short", when=crossover(close,centralBand))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement