Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- // Created by Matthew J. Slabosz
- // www.zenandtheartoftrading.com
- study("MJS - Dynamic Structure Indicator", shorttitle="DSI", overlay=true)
- // User user input
- lookback = input(title="Lookback Period (In Bars):", type=input.integer, defval=10)
- higherRes = input(title="Reference Timeframe:", defval="240", type=input.resolution)
- drawResistance = input(title="Draw Resistance Zones?", type=input.bool, defval=true)
- drawSupport = input(title="Draw Support Zones?", type=input.bool, defval=true)
- enableMaxZoneSize = input(title="Enable Max Zone Size?", type=input.bool, defval=true)
- maxZoneSize = input(title="Max Zone Size (Pips):", type=input.float, defval=50, minval=1)
- minZoneSize = input(title="Min Zone Size (Pips):", type=input.float, defval=1, minval=1)
- drawZoneSize = input(title="Draw Zone Size Values?", type=input.bool, defval=false)
- offset = input(title="Offset:", type=input.integer, defval=2)
- // Get HTF data
- htfClose = security(syminfo.tickerid, higherRes, close[1])
- htfHigh = security(syminfo.tickerid, higherRes, high[1])
- htfLow = security(syminfo.tickerid, higherRes, low[1])
- // Gather previous major swing high/lows and then grab their wick and close data to map future potential reversal/support zones
- resTop = valuewhen(htfHigh >= highest(htfHigh, lookback) and htfHigh[1] < htfHigh and htfHigh[2] < htfHigh, htfHigh, 0)
- resBot = valuewhen(htfClose >= highest(htfClose, lookback) and htfHigh[1] < htfHigh and htfHigh[2] < htfHigh, htfClose, 0)
- supTop = valuewhen(htfClose <= lowest(htfClose, lookback) and htfLow[1] > htfLow and htfLow[2] > htfLow, htfClose, 0)
- supBot = valuewhen(htfLow <= lowest(htfLow, lookback) and htfLow[1] > htfLow and htfLow[2] > htfLow, htfLow, 0)
- // Calculate zone sizes in pips
- resistanceSize = abs(resTop - resBot)
- supportSize = abs(supTop - supBot)
- // Zone size validation / pip conversion
- atr = atr(14)
- maxZonePips = atr < 0.1 ? maxZoneSize / 10000 : atr > 1.0 ? maxZoneSize : maxZoneSize / 100
- minZonePips = atr < 0.1 ? minZoneSize / 10000 : atr > 1.0 ? minZoneSize : minZoneSize / 100
- plot(drawZoneSize ? resistanceSize : na, color=color.black, transp=0, title="Resistance Zone Size (pips)")
- plot(drawZoneSize ? supportSize : na, color=color.black, transp=0, title="Support Zone Size (pips)")
- validResistance = (not enableMaxZoneSize or
- resistanceSize <= maxZonePips and resistanceSize >= minZonePips) and
- resTop == resTop[1] and resBot == resBot[1] and drawResistance
- validSupport = (not enableMaxZoneSize or
- supportSize <= maxZonePips and supportSize >= minZonePips) and
- supTop == supTop[1] and supBot == supBot[1] and drawSupport
- // Draw invisible plot lines required for zone color fill
- r1 = plot(resTop == resTop[1] and validResistance ? resTop : na, color=na, transp=100, offset=offset)
- r2 = plot(resBot == resBot[1] and validResistance ? resBot : na, color=na, transp=100, offset=offset)
- s1 = plot(supTop == supTop[1] and validSupport ? supTop : na, color=na, transp=100, offset=offset)
- s2 = plot(supBot == supBot[1] and validSupport ? supBot : na, color=na, transp=100, offset=offset)
- // Fill zones
- fill(r1, r2, color=resTop != resTop[1] or resBot != resBot[1] or not validResistance ? color.white : close > resTop ? color.green : color.red, transp=50)
- fill(s1, s2, color=supTop != supTop[1] or supBot != supBot[1] or not validSupport ? color.white : close < supBot ? color.red : color.green, transp=50)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement