Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator(" Trend Strength Over Time", shorttitle="TSOT", overlay=false)
- // Calculate 75th percentile of price for each length
- percentile_13H = ta.percentile_nearest_rank(high, 13, 75)
- percentile_21H = ta.percentile_nearest_rank(high, 21, 75)
- percentile_34H = ta.percentile_nearest_rank(high, 34, 75)
- percentile_55H = ta.percentile_nearest_rank(high, 55, 75)
- percentile_89H = ta.percentile_nearest_rank(high, 89, 75)
- // Calculate 25th percentile of price for each length
- percentile_13L = ta.percentile_nearest_rank(low, 13, 25)
- percentile_21L = ta.percentile_nearest_rank(low, 21, 25)
- percentile_34L = ta.percentile_nearest_rank(low, 34, 25)
- percentile_55L = ta.percentile_nearest_rank(low, 55, 25)
- percentile_89L = ta.percentile_nearest_rank(low, 89, 25)
- // Calculate 75th and 25th for length 144 (longest length)
- highest_high = ta.percentile_nearest_rank(high, 144, 75)
- lowest_low = ta.percentile_nearest_rank(low, 144, 25)
- // Calculate trend strength conditions
- trendBull1 = percentile_13H > highest_high
- trendBull2 = percentile_21H > highest_high
- trendBull3 = percentile_34H > highest_high
- trendBull4 = percentile_55H > highest_high
- trendBull5 = percentile_89H > highest_high
- trendBull6 = percentile_13L > highest_high
- trendBull7 = percentile_21L > highest_high
- trendBull8 = percentile_34L > highest_high
- trendBull9 = percentile_55L > highest_high
- trendBull10 = percentile_89L > highest_high
- trendBear1 = percentile_13H < lowest_low
- trendBear2 = percentile_21H < lowest_low
- trendBear3 = percentile_34H < lowest_low
- trendBear4 = percentile_55H < lowest_low
- trendBear5 = percentile_89H < lowest_low
- trendBear6 = percentile_13L < lowest_low
- trendBear7 = percentile_21L < lowest_low
- trendBear8 = percentile_34L < lowest_low
- trendBear9 = percentile_55L < lowest_low
- trendBear10 = percentile_89L < lowest_low
- countBull =
- (trendBull1 ? 1 : 0) +
- (trendBull2 ? 1 : 0) +
- (trendBull3 ? 1 : 0) +
- (trendBull4 ? 1 : 0) +
- (trendBull5 ? 1 : 0) +
- (trendBull6 ? 1 : 0) +
- (trendBull7 ? 1 : 0) +
- (trendBull8 ? 1 : 0) +
- (trendBull9 ? 1 : 0) +
- (trendBull10 ? 1 : 0)
- countBear =
- (trendBear1 ? 1 : 0) +
- (trendBear2 ? 1 : 0) +
- (trendBear3 ? 1 : 0) +
- (trendBear4 ? 1 : 0) +
- (trendBear5 ? 1 : 0) +
- (trendBear6 ? 1 : 0) +
- (trendBear7 ? 1 : 0) +
- (trendBear8 ? 1 : 0) +
- (trendBear9 ? 1 : 0) +
- (trendBear10 ? 1 : 0)
- // Calculate weak bull count
- weakBullCount =
- (percentile_13L < highest_high and percentile_13L > lowest_low ? 1 : 0) +
- (percentile_21L < highest_high and percentile_21L > lowest_low ? 1 : 0) +
- (percentile_34L < highest_high and percentile_34L > lowest_low ? 1 : 0) +
- (percentile_55L < highest_high and percentile_55L > lowest_low ? 1 : 0) +
- (percentile_89L < highest_high and percentile_89L > lowest_low ? 1 : 0)
- // Calculate weak bear count
- weakBearCount =
- (percentile_13H > lowest_low and percentile_13H < highest_high ? 1 : 0) +
- (percentile_21H > lowest_low and percentile_21H < highest_high ? 1 : 0) +
- (percentile_34H > lowest_low and percentile_34H < highest_high ? 1 : 0) +
- (percentile_55H > lowest_low and percentile_55H < highest_high ? 1 : 0) +
- (percentile_89H > lowest_low and percentile_89H < highest_high ? 1 : 0)
- // Calculate bull strength and bear strength
- bullStrength = 10 * (countBull + 0.5*weakBullCount - 0.5*weakBearCount - countBear)
- bearStrength = 10 * (countBear + 0.5*weakBearCount - 0.5*weakBullCount - countBull)
- // Calculate the current trend
- currentTrendValue = bullStrength - bearStrength
- // Calulate volume strenght
- V13 = (ta.sma(volume,13)) /ta.sma(volume,144)
- V21 = (ta.sma(volume,21)) /ta.sma(volume,144)
- V34 = (ta.sma(volume,34)) /ta.sma(volume,144)
- V55 = (ta.sma(volume,55)) /ta.sma(volume,144)
- V89 = (ta.sma(volume,89)) /ta.sma(volume,144)
- VCF= (0.5*V13+0.25*V21+0.125*V34+0.08*V55+ 0.045*V89)
- // Determine the color based on current trend value
- color_change = currentTrendValue> 0 ? color.green : (currentTrendValue < 0 ? color.red : color.blue)
- plot(bullStrength, color=color_change, title="Trend Strength")
- plot(VCF, color=color.white, title="Volume Strength")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement