Untitled
unknown
plain_text
a year ago
3.6 kB
13
Indexable
//@version=5
indicator("BPT BR Squeeze", overlay=false)
// Inputs
SqLength = input(20, "SqLength")
Length1 = input(9, "Length1")
Length2 = input(13, "Length2")
Length3 = input(21, "Length3")
CounterTrendMode = input(false, "CounterTrendMode")
ChangeMidLine = input(false, "ChangeMidLine")
nK = input.float(1.5, "nK")
nBB = input.float(2.0, "nBB")
AlertLine = input.float(1, "AlertLine")
// Variables
var float Var0 = na
var float Var1 = na
var float Var2 = na
var float Var3 = na
var float Var4 = na
var float Var5 = na
var float Var6 = na
var float Var7 = na
var float Value1 = na
var float Value2 = na
// Plot Variables
var float squeezePlot = na
var float diffHistoPlot = na
// Initialize Colors
var color squeezeColor = color.blue // Start with blue as default
var color diffHistoColor = na
squeezeColor := color.blue
// Calculation Logic
if not ChangeMidLine
if (bar_index == 0)
Var5 := syminfo.mintick != 0 ? syminfo.pointvalue / syminfo.mintick : na
Var4 := ta.atr(SqLength)
Var3 := ta.stdev(close, SqLength)
Var6 := (nK * Var4)
Var7 := (Var6 != 0 ? (nBB * Var3) / Var6 : na)
// Set the squeeze plot value
squeezePlot := 0
// Color logic based on Var7 and AlertLine
if Var7 < AlertLine
squeezeColor := color.red // Active squeeze
else if Var7 > AlertLine
squeezeColor := color.blue // Squeeze released
if Var7 < AlertLine and Var7[1] > AlertLine
squeezeColor := color.green
// Midline change
if ChangeMidLine
Value1 := ta.wma((high + low + close) / 3, Length3)
squeezePlot := 0
squeezeColor := (Value1 > ta.wma((high + low + close) / 3, Length3)[1]) ? color.green : color.red
// DiffHisto calculation
Value2 := ta.sma(ta.wma(close, Length1), Length2) - ta.sma(ta.wma(close, Length2), Length2 + 7)
diffHistoPlot := Value2
diffHistoColor := (Value2 > 0 ? (Value2 > Value2[1] ? color.lime : color.green) : (Value2 < 0 ? (Value2 < Value2[1] ? color.maroon : color.red) : na))
if CounterTrendMode
Var0 := ta.cci(close, 13)
Condition3 = (Var0[1] > 50)
Condition4 = (Var0 < 50)
Condition5 = (Var0[1] < 100)
Condition6 = (Var0 > 100)
Condition7 = (Value2 > 0)
Condition8 = (Value2[1] > 0)
Condition9 = (Value2[2] > 0)
Condition10 = (Var0 < 100)
if Condition3 and Condition4 and Condition7 and Condition8 and Condition9
Var1 := 1
diffHistoColor := color.green
if (Var1 == 1 and Value2 < 0)
Var1 := 0
if (Var1 == 1 and Condition10 and Condition7)
diffHistoColor := color.green
if (Var1 == 1 and Condition5 and Condition6)
Var1 := 0
diffHistoColor := color.green
Condition11 = (Var0[1] < -50)
Condition12 = (Var0 > -50)
Condition13 = (Var0[1] > -100)
Condition14 = (Var0 < -100)
Condition15 = (Value2 < 0)
Condition16 = (Value2[1] < 0)
Condition17 = (Value2[2] < 0)
Condition18 = (Var0 > -100)
if Condition11 and Condition12 and Condition15 and Condition16 and Condition17
Var2 := 1
diffHistoColor := color.green
if (Var2 == 1 and Value2 > 0)
Var2 := 0
if (Var2 == 1 and Condition18 and Condition15)
diffHistoColor := color.green
if (Var2 == 1 and Condition13 and Condition14)
Var2 := 0
diffHistoColor := color.red
// Now plot the values and colors globally
plot(squeezePlot, title="Squeeze", color=squeezeColor, style=plot.style_circles, linewidth = 3)
plot(diffHistoPlot, title="DiffHisto", color=diffHistoColor, style=plot.style_histogram, linewidth = 2)
Editor is loading...
Leave a Comment