Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. //---------------AFR--------------------\\
  2.  
  3. // Inputs
  4. p = input(300, "Period",group = "AFR")
  5. atr_factor = input.float(2.6, "Factor", step = 0.1,group = "AFR")
  6. boolafr = input.bool(true, "Use AFR?",group = "AFR")
  7.  
  8. // Calculations
  9. afratr = ta.atr(p)
  10. e = afratr * atr_factor
  11.  
  12. afr = close
  13. afr := nz(afr[1], afr)
  14.  
  15. atr_factoryHigh = close + e
  16. atr_factoryLow = close - e
  17.  
  18. if atr_factoryLow > afr
  19. afr := atr_factoryLow
  20. if atr_factoryHigh < afr
  21. afr := atr_factoryHigh
  22.  
  23. col = afr > afr[1] ? #00FF00 : #FF0000
  24. col := afr == afr[1] ? col[1] : col
  25.  
  26. buy = afr > afr[1] and not (afr[1] > afr[2])
  27. sell = afr < afr[1] and not (afr[1] < afr[2])
  28. ls = 0
  29. ls := buy ? 1 : sell ? -1 : ls[1]
  30.  
  31. int afrsignal = na
  32.  
  33. if boolafr
  34.  
  35. //----------------------------PERP SWITCH------------------------------\\
  36. // var bool afrlong = na // code taken from chatGPT
  37. // var bool afrshort = na
  38.  
  39. // afrlong := na(afrlong) ? afr > afr[1] ? true : false : afrlong[1]
  40. // afrshort := na(afrshort) ? afr < afr[1] ? true : false : afrshort[1]
  41. //----------------------------END OF SWITCH------------------------------\\
  42.  
  43. //TPI STUFF//
  44. afrlong = afr > afr[1] and ls != ls[1]
  45. afrshort = afr < afr[1] and ls != ls[1]
  46. if afrlong
  47. entrycount += 1
  48. longcomment += " AFR"
  49. afrsignal := 1
  50. if afrshort
  51. entrycount -= 1
  52. shortcomment += " AFR"
  53. afrsignal := -1
  54.  
  55. sigcount += 1
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement