Advertisement
xmd79

Power Indicator Multi TF

Jan 10th, 2023
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. //@version=5
  2.  
  3. indicator('Power Indicator Multi TF', overlay=true)
  4.  
  5. //DeMark
  6.  
  7. sellLength = input.int(title='Sell Length', defval=19, minval=1)
  8. buyLength = input.int(title='Buy Length', defval=19, minval=1)
  9. inp = input(title='Source', defval=close)
  10. tf1 = input.timeframe(title='Timeframe 1', defval='1')
  11. tf2 = input.timeframe(title='Timeframe 2', defval='2')
  12. tf3 = input.timeframe(title='Timeframe 3', defval='3')
  13. tf4 = input.timeframe(title='Timeframe 4', defval='4')
  14. tf5 = input.timeframe(title='Timeframe 5', defval='5')
  15. rep = input(title='Allow Repainting?', defval=false)
  16. minLevel = input.int(title='Minimum Signals', defval=4, tooltip="The minimum number of timeframes for a signal to occur for the indicator to print a buy/sell signal")
  17.  
  18. // buy/sell function
  19.  
  20. buySell(symbol, tf, myBuyLength, mySellLength) =>
  21. uCount = 0
  22. dCount = 0
  23. mySrc = request.security(symbol, tf, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
  24. for i = 0 to mySellLength - 1 by 1
  25. uCount += (nz(mySrc[i]) > nz(mySrc[i + mySellLength]) ? 1 : 0)
  26. for j = 0 to myBuyLength - 1 by 1
  27. dCount += (nz(mySrc[j]) < nz(mySrc[j + myBuyLength]) ? 1 : 0)
  28. dsi = dCount == myBuyLength ? 1 : uCount == mySellLength ? -1 : 0
  29. // end buysell function
  30.  
  31. // calculate buy / sell signals across timeframes
  32.  
  33. buySellTF1 = buySell(syminfo.tickerid, tf1, buyLength, sellLength)
  34. buySellTF2 = buySell(syminfo.tickerid, tf2, buyLength, sellLength)
  35. buySellTF3 = buySell(syminfo.tickerid, tf3, buyLength, sellLength)
  36. buySellTF4 = buySell(syminfo.tickerid, tf4, buyLength, sellLength)
  37. buySellTF5 = buySell(syminfo.tickerid, tf5, buyLength, sellLength)
  38.  
  39. buyCount = ta.crossover(buySellTF1,0) ? 1 : 0
  40. buyCount := ta.crossover(buySellTF2,0) ? buyCount + 1 : buyCount
  41. buyCount := ta.crossover(buySellTF3,0) ? buyCount + 1 : buyCount
  42. buyCount := ta.crossover(buySellTF4,0) ? buyCount + 1 : buyCount
  43. buyCount := ta.crossover(buySellTF5,0) ? buyCount + 1 : buyCount
  44.  
  45. sellCount = ta.crossunder(buySellTF1, 0) ? 1 : 0
  46. sellCount := ta.crossunder(buySellTF2,0) ? sellCount + 1 : sellCount
  47. sellCount := ta.crossunder(buySellTF3,0) ? sellCount + 1 : sellCount
  48. sellCount := ta.crossunder(buySellTF4,0) ? sellCount + 1 : sellCount
  49. sellCount := ta.crossunder(buySellTF5,0) ? sellCount + 1 : sellCount
  50.  
  51. // define colors
  52.  
  53. bear1 = color.rgb(160,0,0)
  54. bear2 = color.rgb(180,0,0)
  55. bear3 = color.rgb(200,0,0)
  56. bear4 = color.rgb(220,0,0)
  57. bear5 = color.rgb(255,0,0)
  58.  
  59. bull1 = color.rgb(0,160,0)
  60. bull2 = color.rgb(0,180,0)
  61. bull3 = color.rgb(0,200,0)
  62. bull4 = color.rgb(0,220,0)
  63. bull5 = color.rgb(0,255,0)
  64.  
  65. // plot buy/sell signals
  66.  
  67. plotshape(buyCount == 1 and buyCount >= minLevel, 'Buy', shape.triangleup, location.belowbar, color=bull1, text="Buy x1", textcolor=bull1)
  68. plotshape(buyCount == 2 and buyCount >= minLevel, 'Buy', shape.triangleup, location.belowbar, color=bull2, text="Buy x2", textcolor=bull2)
  69. plotshape(buyCount == 3 and buyCount >= minLevel, 'Buy', shape.triangleup, location.belowbar, color=bull3, text="Buy x3", textcolor=bull3)
  70. plotshape(buyCount == 4 and buyCount >= minLevel, 'Buy', shape.triangleup, location.belowbar, color=bull4, text="Buy x4", textcolor=bull4)
  71. plotshape(buyCount == 5 and buyCount >= minLevel, 'Buy', shape.triangleup, location.belowbar, color=bull5, text="Buy x5", textcolor=bull5)
  72.  
  73. plotshape(sellCount == 1 and sellCount >= minLevel, 'Sell', shape.triangledown, location.abovebar, color=bear1, text="Sell x1", textcolor=bear1)
  74. plotshape(sellCount == 2 and sellCount >= minLevel, 'Sell', shape.triangledown, location.abovebar, color=bear2, text="Sell x2", textcolor=bear2)
  75. plotshape(sellCount == 3 and sellCount >= minLevel, 'Sell', shape.triangledown, location.abovebar, color=bear3, text="Sell x3", textcolor=bear3)
  76. plotshape(sellCount == 4 and sellCount >= minLevel, 'Sell', shape.triangledown, location.abovebar, color=bear4, text="Sell x4", textcolor=bear4)
  77. plotshape(sellCount == 5 and sellCount >= minLevel, 'Sell', shape.triangledown, location.abovebar, color=bear5, text="Sell x5", textcolor=bear5)
  78.  
  79. // add alert conditions
  80.  
  81. alertcondition(buyCount==1,'Buy x1','{{ticker}} buy x1 on {{interval}}')
  82. alertcondition(buyCount==2,'Buy x2','{{ticker}} buy x2 on {{interval}}')
  83. alertcondition(buyCount==3,'Buy x3','{{ticker}} buy x3 on {{interval}}')
  84. alertcondition(buyCount==4,'Buy x4','{{ticker}} buy x4 on {{interval}}')
  85. alertcondition(buyCount==5,'Buy x5','{{ticker}} buy x5 on {{interval}}')
  86. alertcondition(buyCount>=minLevel, 'Any Buy Above Minimum Signals', '{{ticker}} buy (minimum signals threshold met) on {{interval}}')
  87.  
  88. alertcondition(sellCount==1,'Sell x1','{{ticker}} sell x1 on {{interval}}')
  89. alertcondition(sellCount==2,'Sell x2','{{ticker}} sell x2 on {{interval}}')
  90. alertcondition(sellCount==3,'Sell x3','{{ticker}} sell x3 on {{interval}}')
  91. alertcondition(sellCount==4,'Sell x4','{{ticker}} sell x4 on {{interval}}')
  92. alertcondition(sellCount==5,'Sell x5','{{ticker}} sell x5 on {{interval}}')
  93. alertcondition(sellCount>=minLevel, 'Any Sell Above Minimum Signals', '{{ticker}} sell (minimum signals threshold met) on {{interval}}')
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement