Advertisement
Maurizio-Ciullo

2 tk (1in %) 1 sl + color.plot

Jul 4th, 2021 (edited)
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © calcajack
  3.  
  4. //@version=4
  5. strategy("Bollinger Bands Strategy", shorttitle="BB Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=5)
  6.  
  7. //definisco gli INPUT
  8.  
  9. standard_dev = input(20, "deviazione standard", input.integer, minval=1, maxval=50)
  10. offset = input(2,"offset", input.float, minval=0.1, maxval=10)
  11.  
  12. // calcolo e disegno le tre bande
  13.  
  14. centralBand = sma(close, 20)
  15. plot(centralBand, "SMA", color.new(color.red, 50) )
  16.  
  17. upperBand = centralBand + stdev(close, standard_dev)*offset
  18. plot(upperBand, "Upper Band", color.new(color.blue, 25) )
  19.  
  20. lowerBand = centralBand - stdev(close, standard_dev)*offset
  21. plot(lowerBand, "Lower Band", color.new(color.blue, 25) )
  22.  
  23. //plot(candleClose, "candleClose", color.new(color.yellow, 0) )
  24.  
  25.  
  26. //condizioni per apertura Long
  27.  
  28. openLong = crossover(close, lowerBand)
  29. strategy.entry("long", true,when=openLong)
  30.  
  31. //condizioni per apertura Short
  32.  
  33. openShort = crossunder(close, upperBand)
  34. strategy.entry("short", false,when=openShort)
  35.  
  36. //condizioni per chiusura Long
  37.  
  38. closeLong1 = crossover(close, centralBand)
  39. closeLong2 = crossover(high, upperBand)
  40. strategy.close("long", when=closeLong1, qty_percent=66)
  41. strategy.close("long", when=closeLong2)
  42. strategy.close("long", when=crossunder(close,centralBand))
  43.  
  44. //condizioni per chiusura Short
  45.  
  46. closeShort1 = crossunder(close, centralBand)
  47. closeShort2 = crossunder(low, lowerBand)
  48. strategy.close("short", when=closeShort1, qty_percent=66)
  49. strategy.close("short", when=closeShort2)
  50. strategy.close("short", when=crossover(close,centralBand))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement