Last active
September 6, 2024 05:25
-
-
Save tansanDOTeth/431981fbd4a186ebb35c0c5b59d8f014 to your computer and use it in GitHub Desktop.
Average True Range Percentage with Wicks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Average True Range Percentage with Wicks | |
// This was hacked together, so everything is hardcoded. I'm open to add more configuration inputs if there is demand for it. | |
// @tansanDOTeth | |
//@version=5 | |
indicator("Average True Range Percent with Wicks", shorttitle = "ATRP with Wicks") | |
// Get user input | |
numberOfDaysForWicks = input.int(title = "Number of Days for Wicks", defval = 360, step = 1, minval = 1, tooltip = "Number of days to calculate highest upper and lower wick relative.") | |
sellColor = #199af69c | |
buyColor = color.rgb(247, 75, 241) | |
trpEmaColor = color.rgb(243, 243, 33) | |
histogramLinewidth = 4 | |
trueRangeAggregatePeriod = 200 | |
trueRange = ta.tr / hl2 * 100 | |
trueRangeAggregate = ta.ema(trueRange, trueRangeAggregatePeriod) | |
// Plot indicator | |
plot(trueRange, title = 'True range percent', color = color.new(color.silver, 10), style = plot.style_histogram, linewidth = histogramLinewidth) | |
plot(trueRangeAggregate, title = 'EMA 200', color = trpEmaColor, style = plot.style_line) | |
// Calculate upper and lower wick lengths | |
upperWick = high - math.max(open, close) | |
lowerWick = math.min(open, close) - low | |
// Calculate upper and lower wicks relative to TRP | |
upperWickRelative = (upperWick / ta.tr) * trueRange | |
lowerWickRelative = (lowerWick / ta.tr) * trueRange | |
// Plot upper and lower wicks | |
plot(upperWickRelative, title = 'Upper Wick', color = color.new(buyColor, 5), style = plot.style_histogram, linewidth = histogramLinewidth) | |
plot(lowerWickRelative, title = 'Lower Wick', color = color.new(sellColor, 5), style = plot.style_histogram, linewidth = histogramLinewidth) | |
// Find highest upperWickRelative and lowerWickRelative in the last X datapoints | |
highestUpperWickRelative = ta.highest(upperWickRelative, numberOfDaysForWicks) | |
highestLowerWickRelative = ta.highest(lowerWickRelative, numberOfDaysForWicks) | |
// Plot highest upperWickRelative and lowerWickRelative | |
plot(highestUpperWickRelative, title = 'Highest Upper Wick Relative', color = color.new(buyColor, 50), linewidth = 1) | |
plot(highestLowerWickRelative, title = 'Highest Lower Wick Relative', color = color.new(sellColor, 50), linewidth = 1) | |
emaDays = 30 | |
// Calculate EMA 200 of upper and lower wicks | |
emaUpperWick = ta.ema(upperWickRelative, emaDays) | |
emaLowerWick = ta.ema(lowerWickRelative, emaDays) | |
// Plot EMA 200 of upper and lower wicks | |
plot(emaUpperWick, title = 'EMA 200 of Upper Wick', color = buyColor, linewidth = 1) | |
plot(emaLowerWick, title = 'EMA 200 of Lower Wick', color = sellColor, linewidth = 1) | |
// Timezone Sessions | |
// Tokyo Session | |
s1 = input.session(title='Tokyo', defval='0100-1000') | |
asiaTimePeriod = time(timeframe.period, s1, "UTC") | |
bgcolor(na(asiaTimePeriod) ? na : color.new(color.red, 95)) | |
// London Session | |
s2 = input.session(title='London', defval='0800-1700') | |
londonTimePeriod = time(timeframe.period, s2, "UTC") | |
bgcolor(na(londonTimePeriod) ? na : color.new(color.blue, 95)) | |
// New York Session | |
s3 = input.session(title='New York', defval='1300-2200') | |
nyTimePeriod = time(timeframe.period, s3, "UTC") | |
bgcolor(na(nyTimePeriod) ? na : color.new(color.yellow, 95)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment