Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator('Power Indicator Multi TF', overlay=true)
- //DeMark
- sellLength = input.int(title='Sell Length', defval=19, minval=1)
- buyLength = input.int(title='Buy Length', defval=19, minval=1)
- inp = input(title='Source', defval=close)
- tf1 = input.timeframe(title='Timeframe 1', defval='1')
- tf2 = input.timeframe(title='Timeframe 2', defval='2')
- tf3 = input.timeframe(title='Timeframe 3', defval='3')
- tf4 = input.timeframe(title='Timeframe 4', defval='4')
- tf5 = input.timeframe(title='Timeframe 5', defval='5')
- rep = input(title='Allow Repainting?', defval=false)
- 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")
- // buy/sell function
- buySell(symbol, tf, myBuyLength, mySellLength) =>
- uCount = 0
- dCount = 0
- mySrc = request.security(symbol, tf, inp[rep ? 0 : barstate.isrealtime ? 1 : 0])[rep ? 0 : barstate.isrealtime ? 0 : 1]
- for i = 0 to mySellLength - 1 by 1
- uCount += (nz(mySrc[i]) > nz(mySrc[i + mySellLength]) ? 1 : 0)
- for j = 0 to myBuyLength - 1 by 1
- dCount += (nz(mySrc[j]) < nz(mySrc[j + myBuyLength]) ? 1 : 0)
- dsi = dCount == myBuyLength ? 1 : uCount == mySellLength ? -1 : 0
- // end buysell function
- // calculate buy / sell signals across timeframes
- buySellTF1 = buySell(syminfo.tickerid, tf1, buyLength, sellLength)
- buySellTF2 = buySell(syminfo.tickerid, tf2, buyLength, sellLength)
- buySellTF3 = buySell(syminfo.tickerid, tf3, buyLength, sellLength)
- buySellTF4 = buySell(syminfo.tickerid, tf4, buyLength, sellLength)
- buySellTF5 = buySell(syminfo.tickerid, tf5, buyLength, sellLength)
- buyCount = ta.crossover(buySellTF1,0) ? 1 : 0
- buyCount := ta.crossover(buySellTF2,0) ? buyCount + 1 : buyCount
- buyCount := ta.crossover(buySellTF3,0) ? buyCount + 1 : buyCount
- buyCount := ta.crossover(buySellTF4,0) ? buyCount + 1 : buyCount
- buyCount := ta.crossover(buySellTF5,0) ? buyCount + 1 : buyCount
- sellCount = ta.crossunder(buySellTF1, 0) ? 1 : 0
- sellCount := ta.crossunder(buySellTF2,0) ? sellCount + 1 : sellCount
- sellCount := ta.crossunder(buySellTF3,0) ? sellCount + 1 : sellCount
- sellCount := ta.crossunder(buySellTF4,0) ? sellCount + 1 : sellCount
- sellCount := ta.crossunder(buySellTF5,0) ? sellCount + 1 : sellCount
- // define colors
- bear1 = color.rgb(160,0,0)
- bear2 = color.rgb(180,0,0)
- bear3 = color.rgb(200,0,0)
- bear4 = color.rgb(220,0,0)
- bear5 = color.rgb(255,0,0)
- bull1 = color.rgb(0,160,0)
- bull2 = color.rgb(0,180,0)
- bull3 = color.rgb(0,200,0)
- bull4 = color.rgb(0,220,0)
- bull5 = color.rgb(0,255,0)
- // plot buy/sell signals
- plotshape(buyCount == 1 and buyCount >= minLevel, 'Buy', shape.triangleup, location.belowbar, color=bull1, text="Buy x1", textcolor=bull1)
- plotshape(buyCount == 2 and buyCount >= minLevel, 'Buy', shape.triangleup, location.belowbar, color=bull2, text="Buy x2", textcolor=bull2)
- plotshape(buyCount == 3 and buyCount >= minLevel, 'Buy', shape.triangleup, location.belowbar, color=bull3, text="Buy x3", textcolor=bull3)
- plotshape(buyCount == 4 and buyCount >= minLevel, 'Buy', shape.triangleup, location.belowbar, color=bull4, text="Buy x4", textcolor=bull4)
- plotshape(buyCount == 5 and buyCount >= minLevel, 'Buy', shape.triangleup, location.belowbar, color=bull5, text="Buy x5", textcolor=bull5)
- plotshape(sellCount == 1 and sellCount >= minLevel, 'Sell', shape.triangledown, location.abovebar, color=bear1, text="Sell x1", textcolor=bear1)
- plotshape(sellCount == 2 and sellCount >= minLevel, 'Sell', shape.triangledown, location.abovebar, color=bear2, text="Sell x2", textcolor=bear2)
- plotshape(sellCount == 3 and sellCount >= minLevel, 'Sell', shape.triangledown, location.abovebar, color=bear3, text="Sell x3", textcolor=bear3)
- plotshape(sellCount == 4 and sellCount >= minLevel, 'Sell', shape.triangledown, location.abovebar, color=bear4, text="Sell x4", textcolor=bear4)
- plotshape(sellCount == 5 and sellCount >= minLevel, 'Sell', shape.triangledown, location.abovebar, color=bear5, text="Sell x5", textcolor=bear5)
- // add alert conditions
- alertcondition(buyCount==1,'Buy x1','{{ticker}} buy x1 on {{interval}}')
- alertcondition(buyCount==2,'Buy x2','{{ticker}} buy x2 on {{interval}}')
- alertcondition(buyCount==3,'Buy x3','{{ticker}} buy x3 on {{interval}}')
- alertcondition(buyCount==4,'Buy x4','{{ticker}} buy x4 on {{interval}}')
- alertcondition(buyCount==5,'Buy x5','{{ticker}} buy x5 on {{interval}}')
- alertcondition(buyCount>=minLevel, 'Any Buy Above Minimum Signals', '{{ticker}} buy (minimum signals threshold met) on {{interval}}')
- alertcondition(sellCount==1,'Sell x1','{{ticker}} sell x1 on {{interval}}')
- alertcondition(sellCount==2,'Sell x2','{{ticker}} sell x2 on {{interval}}')
- alertcondition(sellCount==3,'Sell x3','{{ticker}} sell x3 on {{interval}}')
- alertcondition(sellCount==4,'Sell x4','{{ticker}} sell x4 on {{interval}}')
- alertcondition(sellCount==5,'Sell x5','{{ticker}} sell x5 on {{interval}}')
- alertcondition(sellCount>=minLevel, 'Any Sell Above Minimum Signals', '{{ticker}} sell (minimum signals threshold met) on {{interval}}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement