Buy Low Sell High Fibonacci Retracement on PineScript to be used in TradingView


SUBMITTED BY: realitycheck777

DATE: Feb. 14, 2023, 12:31 p.m.

FORMAT: Text only

SIZE: 1.6 kB

HITS: 445

  1. //@version=5
  2. // Bollinger Bands: Realitycheck777 : 14/SEP/2014 11:07 : 2.0
  3. // This displays the traditional Bollinger Bands, the difference is
  4. // that the 1st and 2nd StdDev are outlined with two colors and two
  5. // different levels, one for each Standard Deviation
  6. strategy(shorttitle='MBB', title='Bollinger Bands', overlay=true, currency=currency.NONE, initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
  7. src = input(close)
  8. length = input.int(34, minval=1)
  9. mult = input.float(2.0, minval=0.001, maxval=50)
  10. basis = ta.sma(src, length)
  11. dev = ta.stdev(src, length)
  12. dev2 = mult * dev
  13. upper = basis + dev2
  14. lower = basis - dev2
  15. upper1 = basis + dev
  16. lower1 = basis - dev
  17. colorBasis = src >= basis ? color.blue : color.orange
  18. pBasis = plot(basis, linewidth=2, color=colorBasis)
  19. pUpper1 = plot(upper1, color=color.new(color.blue, 0), style=plot.style_circles)
  20. pLower1 = plot(lower1, color=color.new(color.orange, 0), style=plot.style_circles)
  21. fill(pBasis, upper, color=color.new(color.blue, 80))
  22. fill(pUpper1, upper, color=color.new(color.blue, 80))
  23. fill(pBasis, lower, color=color.new(color.orange, 80))
  24. fill(pLower1, lower, color=color.new(color.orange, 80))
  25. longCondition = close > upper
  26. shortCondition = close < lower
  27. if longCondition
  28. strategy.entry("Long", strategy.long)
  29. if shortCondition
  30. strategy.entry("Short", strategy.short)
  31. if shortCondition and strategy.position_size > 0
  32. strategy.close("Long")
  33. if longCondition and strategy.position_size < 0
  34. strategy.close("Short")

comments powered by Disqus