4444

4444

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Join us https://t.me/cryptomena1

//@version=5

indicator(title='Osc+ ST+sqzmom',overlay=false,max_lines_count = 100)
n1 = input(10, 'Channel Length')
n2 = input(21, 'Average Length')
obLevel1 = input(60, 'Over Bought Level 1')
obLevel2 = input(53, 'Over Bought Level 2')
osLevel1 = input(-60, 'Over Sold Level 1')
osLevel2 = input(-53, 'Over Sold Level 2')

ap = hlc3
esa = ta.ema(ap, n1)
d = ta.ema(math.abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ta.ema(ci, n2)

wt1 = tci
wt2 = ta.sma(wt1, 4)

plot(0, color=color.new(color.gray, 0))
ob1 = plot(obLevel1, color=color.new(color.maroon, 90))
os1 = plot(osLevel1, color=color.new(color.aqua, 90))
ob2 = plot(obLevel2, color=color.new(color.maroon, 90))
os2 = plot(osLevel2, color=color.new(color.aqua, 90))

p1 = plot(wt1, color=color.new(color.aqua, 0))
p2 = plot(wt2, color=color.new(color.maroon, 0))
plot(wt1 - wt2, color=wt2 - wt1 > 0 ? color.new(color.maroon, 50) : color.new(color.aqua, 50), style=plot.style_histogram)
plot(ta.cross(wt1, wt2) ? wt2 : na, color=color.new(color.black, 0), style=plot.style_circles, linewidth=3)
plot(ta.cross(wt1, wt2) ? wt2 : na, color=wt2 - wt1 > 0 ? color.maroon : color.aqua, style=plot.style_circles, linewidth=2)


fill(p1,p2,color = wt2 - wt1 > 0 ? color.new(color.red, 50) : color.new(color.aqua, 50))
fill(ob1,ob2,color = color.new(color.maroon, 20))
fill(os1,os2,color = color.new(color.aqua, 20))

////////////////////////////////////////////////////////////////////

// Supertrend Inputs
atrPeriod = input.int(10, 'ATR Length', minval = 1)
factor = input.float(2.5, 'Factor', minval = 0.01, step = 0.01)

// Squeeze Momentum Indicator Inputs
source = input(close, 'Source')
bbLength = input.int(20, 'Bollinger Bands Length', minval = 1)
bbMult = input.float(2, 'Bollinger Bands MultFactor', step = 0.25)
kcLength = input(20, 'Keltner\'s Channel Length')
kcMult = input.float(1.5, 'Keltner\'s Channel MultFactor', step = 0.25)
useTrueRange = input(true, 'Use TrueRange (Keltner\'s Channel)')
signalLength = input(5, 'Signal Length')
tooltip_sqz = 'The Squeeze Indicator measures the relationship between Bollinger Bands and Keltner\'s Channels to help identify consolidations and signal when prices are likely to break out (whether up or down). ' + 'The Squeeze Indicator finds sections of the Bollinger Bands which fall inside the Keltner\'s Channels and in this case the market is said to be in a squeeze (indicator turns off, displayed with grey diamond shapes in this study). ' + 'When the volatility increases, so does the distance between the bands, conversely, when the volatility declines, the distance also decreases and in such cases the squeeze is said to be released (indicator turns on, displayed with triangle up or triangle down shapes)'
components = input.bool(false, 'Components of the Squeeze Indicator', tooltip = tooltip_sqz)

// Customizable thresholds
lowerThreshold = input(-1.0, title = 'Lower Threshold')
upperThreshold = input(1.0, title = 'Upper Threshold')

// Hardcoded tp + sl multipliers
targetMultiplier1 = 1
targetMultiplier2 = 2
targetMultiplier3 = 3
stopLossMultiplier = 3

// Input switches for alerts
alertTrendChange = input.bool(true, title='Enable Trend Change Alert')

// Calculate Supertrend
= ta.supertrend(factor, atrPeriod)

// Plot the Supertrend line
plot(supertrend, color = direction < 0 ? color.green : color.red, title = 'ST', style = plot.style_stepline_diamond,force_overlay=true)

// Determine if the trend is up or down
upTrend = direction < 0
downTrend = direction > 0

// Track previous trend state
var int previousDirection = na
previousDirection := upTrend ? 1 : -1

// Calculate ATR for targets and stop loss
atrValue = ta.atr(atrPeriod)

// Initialize target and stop loss levels
var float entryPrice = na
var float targetLevel1 = na
var float targetLevel2 = na
var float targetLevel3 = na
var float stopLossLevel = na

// Initialize counters for lines and labels
var int count_up = 0
var int count_down = 0

// Initialize a new variable to track if new lines and labels are drawn
var bool newLinesDrawn = false

// Calculate target and stop loss levels
if upTrend
entryPrice := close
targetLevel1 := close + atrValue * targetMultiplier1
targetLevel2 := close + atrValue * targetMultiplier2
targetLevel3 := close + atrValue * targetMultiplier3
stopLossLevel := close - atrValue * stopLossMultiplier
count_up := count_up + 1
count_down := 0
else if downTrend
entryPrice := close
targetLevel1 := close - atrValue * targetMultiplier1
targetLevel2 := close - atrValue * targetMultiplier2
targetLevel3 := close - atrValue * targetMultiplier3
stopLossLevel := close + atrValue * stopLossMultiplier
count_down := count_down + 1
count_up := 0


// Calculate BB
basis = ta.sma(source, bbLength)
dev = kcMult * ta.stdev(source, bbLength)
bbUpper = basis + dev
bbLower = basis - dev

// Calculate KC
ma = ta.sma(source, kcLength)
trRange = useTrueRange ? ta.tr : high - low
rangema = ta.sma(trRange, kcLength)
kcUpper = ma + rangema * kcMult
kcLower = ma - rangema * kcMult

sqzOn = bbLower > kcLower and bbUpper < kcUpper
sqzOff = bbLower < kcLower and bbUpper > kcUpper
noSqz = sqzOn == false and sqzOff == false

val = ta.linreg(source - math.avg(math.avg(ta.highest(high, kcLength), ta.lowest(low, kcLength)), ta.sma(source, kcLength)), kcLength, 0)
signal = ta.sma(val, signalLength)
dir = val // - signal

// Plotting Squeeze Momentum Indicator
segitigaUp = sqzOff and dir > dir and dir >= upperThreshold
segitigaDown = sqzOff and dir < dir and dir

Read More

Share:

Latest News