Advertisement
xmd79

MJS - Dynamic Structure Indicator

Apr 23rd, 2021
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. //@version=4
  2. // Created by Matthew J. Slabosz
  3. // www.zenandtheartoftrading.com
  4. study("MJS - Dynamic Structure Indicator", shorttitle="DSI", overlay=true)
  5.  
  6. // User user input
  7. lookback = input(title="Lookback Period (In Bars):", type=input.integer, defval=10)
  8. higherRes = input(title="Reference Timeframe:", defval="240", type=input.resolution)
  9. drawResistance = input(title="Draw Resistance Zones?", type=input.bool, defval=true)
  10. drawSupport = input(title="Draw Support Zones?", type=input.bool, defval=true)
  11. enableMaxZoneSize = input(title="Enable Max Zone Size?", type=input.bool, defval=true)
  12. maxZoneSize = input(title="Max Zone Size (Pips):", type=input.float, defval=50, minval=1)
  13. minZoneSize = input(title="Min Zone Size (Pips):", type=input.float, defval=1, minval=1)
  14. drawZoneSize = input(title="Draw Zone Size Values?", type=input.bool, defval=false)
  15. offset = input(title="Offset:", type=input.integer, defval=2)
  16.  
  17. // Get HTF data
  18. htfClose = security(syminfo.tickerid, higherRes, close[1])
  19. htfHigh = security(syminfo.tickerid, higherRes, high[1])
  20. htfLow = security(syminfo.tickerid, higherRes, low[1])
  21.  
  22. // Gather previous major swing high/lows and then grab their wick and close data to map future potential reversal/support zones
  23. resTop = valuewhen(htfHigh >= highest(htfHigh, lookback) and htfHigh[1] < htfHigh and htfHigh[2] < htfHigh, htfHigh, 0)
  24. resBot = valuewhen(htfClose >= highest(htfClose, lookback) and htfHigh[1] < htfHigh and htfHigh[2] < htfHigh, htfClose, 0)
  25. supTop = valuewhen(htfClose <= lowest(htfClose, lookback) and htfLow[1] > htfLow and htfLow[2] > htfLow, htfClose, 0)
  26. supBot = valuewhen(htfLow <= lowest(htfLow, lookback) and htfLow[1] > htfLow and htfLow[2] > htfLow, htfLow, 0)
  27.  
  28. // Calculate zone sizes in pips
  29. resistanceSize = abs(resTop - resBot)
  30. supportSize = abs(supTop - supBot)
  31.  
  32. // Zone size validation / pip conversion
  33. atr = atr(14)
  34. maxZonePips = atr < 0.1 ? maxZoneSize / 10000 : atr > 1.0 ? maxZoneSize : maxZoneSize / 100
  35. minZonePips = atr < 0.1 ? minZoneSize / 10000 : atr > 1.0 ? minZoneSize : minZoneSize / 100
  36. plot(drawZoneSize ? resistanceSize : na, color=color.black, transp=0, title="Resistance Zone Size (pips)")
  37. plot(drawZoneSize ? supportSize : na, color=color.black, transp=0, title="Support Zone Size (pips)")
  38. validResistance = (not enableMaxZoneSize or
  39. resistanceSize <= maxZonePips and resistanceSize >= minZonePips) and
  40. resTop == resTop[1] and resBot == resBot[1] and drawResistance
  41. validSupport = (not enableMaxZoneSize or
  42. supportSize <= maxZonePips and supportSize >= minZonePips) and
  43. supTop == supTop[1] and supBot == supBot[1] and drawSupport
  44.  
  45. // Draw invisible plot lines required for zone color fill
  46. r1 = plot(resTop == resTop[1] and validResistance ? resTop : na, color=na, transp=100, offset=offset)
  47. r2 = plot(resBot == resBot[1] and validResistance ? resBot : na, color=na, transp=100, offset=offset)
  48. s1 = plot(supTop == supTop[1] and validSupport ? supTop : na, color=na, transp=100, offset=offset)
  49. s2 = plot(supBot == supBot[1] and validSupport ? supBot : na, color=na, transp=100, offset=offset)
  50.  
  51. // Fill zones
  52. fill(r1, r2, color=resTop != resTop[1] or resBot != resBot[1] or not validResistance ? color.white : close > resTop ? color.green : color.red, transp=50)
  53. fill(s1, s2, color=supTop != supTop[1] or supBot != supBot[1] or not validSupport ? color.white : close < supBot ? color.red : color.green, transp=50)
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement