0% found this document useful (0 votes)
15 views2 pages

Stoch Detector

Uploaded by

Flo Mar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Stoch Detector

Uploaded by

Flo Mar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//@version=5

indicator("Stochastic Pattern Detector", overlay=false)

// Adjustable Stochastic Settings via Inputs


k_period = input.int(1, title="K Period", minval=1)
k_smooth = input.int(1, title="K Smoothing", minval=1)
d_smooth = input.int(1, title="D Smoothing", minval=1)
stochastic_length = input.int(1, title="Stochastic Length", minval=1) // Default
length for Stochastic

// Stochastic Calculation
k = ta.stoch(close, high, low, stochastic_length)
k_smoothed = ta.sma(k, k_smooth) // Smoothed K Line
d = ta.sma(k_smoothed, d_smooth) // D Line

// Input settings for point thresholds


useEMA=input.bool(true,"Use EMA",group="EMA Setting")
len = input.int(200, title="EMA Length")
ema200=ta.ema(close,len)

long_first_move = input.int(40, title="Long First Move Threshold", minval=1,group =


"Stoch Move Setting Long")
long_second_move_up = input.int(20, title="Long Second Move Up Threshold",
minval=1)
long_second_move_down = input.int(10, title="Long Second Move Down Threshold",
minval=1)
short_first_move = input.int(40, title="Short First Move Threshold", minval=1,group
= "Stoch Move Setting Short")
short_second_move_down = input.int(20, title="Short Second Move Down Threshold",
minval=1)
short_second_move_up = input.int(10, title="Short Second Move Up Threshold",
minval=1)

// Variables to detect the first and second movements


var float stoch_prev = na
var float first_move = na
var float second_move = na

// Long Pattern Detection


long_condition_1 = ((k[2] - k[1]) >= long_first_move)
long_condition_2_1 = ((k - k[1]) <= long_second_move_up) and (k - k[1])>=0
long_condition_2_2 = ((k[1] - k) <= long_second_move_down) and (k[1] - k)>=0

// Short Pattern Detection


short_condition_1 = ((k[1] - k[2])>= short_first_move)
short_condition_2_1 = (k[1] - k) <= short_second_move_down and (k[1] - k) >=0
short_condition_2_2 = ((k - k[1]) <= short_second_move_up) and (k - k[1])>=0

// Pattern signals
long_signal_1 = long_condition_1 and long_condition_2_1
long_signal_2 = long_condition_1 and long_condition_2_2
short_signal_1 = short_condition_1 and short_condition_2_1
short_signal_2 = short_condition_1 and short_condition_2_2

long=false
short=false
if useEMA
long:=(long_signal_1 or long_signal_2 ) and close>ema200
short:=(short_signal_1 or short_signal_2) and close<ema200
if not useEMA
long:=long_signal_1 or long_signal_2
short:=short_signal_1 or short_signal_2

// Plotting signals on the price chart (overlay)


plotshape(long, title="Long Pattern", location=location.belowbar,
color=color.green, force_overlay = true, style=shape.triangleup, size=size.small)
plotshape(short, title="Short Pattern",force_overlay = true,
location=location.abovebar, color=color.red, style=shape.triangledown,
size=size.small)
plot(useEMA?ema200:na, title="EMA", color=color.green, linewidth=2,force_overlay =
true)

// Plot Stochastic Oscillator lines


plot(k, title="%K Line", color=color.blue, linewidth=2)
plot(d, title="%D Line", color=color.orange, linewidth=1)
hline(80, "Overbought", color=color.red)
hline(20, "Oversold", color=color.green)

You might also like