Advertisement
xmd79

Supply and Demand Zone

Jan 11th, 2023
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © MBCryptocurrency
  3.  
  4. //@version=5
  5. indicator("Supply and Demand Zone", overlay=true, timeframe="", timeframe_gaps=false)
  6.  
  7.  
  8. //CCI
  9.  
  10. ma = ta.sma(hlc3, 14)
  11. cci = (hlc3 - ma) / (0.015 * ta.dev(hlc3, 20))
  12.  
  13.  
  14.  
  15.  
  16.  
  17. timeframe1= input.timeframe('60','First CCI timeframe')
  18. timeframe2= input.timeframe('120','second CCI timeframe')
  19.  
  20. CCI15= request.security(syminfo.tickerid, timeframe1 ,cci,gaps = barmerge.gaps_off)
  21.  
  22. CCI60= request.security(syminfo.tickerid, timeframe2,cci,gaps = barmerge.gaps_off)
  23.  
  24.  
  25.  
  26. ///RSI
  27.  
  28.  
  29.  
  30. up = ta.rma(math.max(ta.change(close), 0), 14)
  31. down = ta.rma(-math.min(ta.change(close), 0), 14)
  32. rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
  33. rsiMA = ta.sma(rsi, 14)
  34. isBB = "SMA" == "Bollinger Bands"
  35.  
  36.  
  37.  
  38.  
  39. timeframe=input.timeframe('60', " RSI timeframe")
  40. rsi15= request.security(syminfo.tickerid,timeframe ,rsi,gaps = barmerge.gaps_off)
  41.  
  42. cross= ta.cross(cci,-100)
  43. cross2=ta.cross(cci,100)
  44.  
  45.  
  46. //condition
  47.  
  48. signal_buy = false
  49. signal_sell = false
  50.  
  51.  
  52. if CCI15 < -100 and CCI60 < -150 and rsiMA < 35 and rsi15 < 50 //buy when long time is above zero and short time is below zero
  53. signal_buy := true
  54.  
  55. if CCI15 > 100 and CCI60 > 150 and rsiMA > 65 and rsi15 > 50 //sell when long time is below zero and short time is above zero
  56. signal_sell := true
  57.  
  58. //only first signal to show
  59.  
  60. Buy = false
  61. Sell = false
  62.  
  63.  
  64.  
  65.  
  66. Buy := signal_buy ? true : signal_sell ? false : cross ? false :cross2 ? false : Buy[1]
  67. Sell := signal_sell ? true : signal_buy ? false : cross ? false :cross2 ? false : Sell[1]
  68.  
  69.  
  70.  
  71. Final_buy = signal_buy and not (Buy[1])
  72. Final_sell = signal_sell and not (Sell[1])
  73.  
  74.  
  75.  
  76.  
  77. // alerts
  78. alertcondition(Final_buy, "Buy", "Time to Buy")
  79.  
  80. alertcondition(Final_sell , "Sell", "Time to Sell")
  81.  
  82.  
  83. //plotshapes
  84.  
  85. plotshape(Final_sell, title="Sell", style = shape.triangledown, color=color.rgb(255, 0, 0, 50) , size = size.small, location = location.abovebar, text = "Sell Zone", textcolor= color.yellow)
  86.  
  87.  
  88. plotshape(Final_buy, title="Buy", style = shape.triangleup, color=color.rgb(0, 255, 0, 50) , size = size.small, location = location.belowbar, text = "Buy Zone", textcolor= color.blue)
  89.  
  90.  
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement