
The script is below:
//@version=5
strategy("My strategy", overlay=true, margin_long=100, margin_short=100)
//Indicator math
sd_g1 = 'Calibration'
sd_g2 = 'Standard Deviation Settings'
length = input(50, 'Distribution Width')
src = input(close, 'Source of Mean')
realtime = input(true, 'Real Time Bar Switch')
s_sd1 = input(true, 'Switch | StDev', inline='sd_a', group=sd_g2), i_sd1 = input.float(1.00, '', inline='sd_a', group=sd_g2, minval = 0, step = 0.01)
s_sd2 = input(true, 'Switch | StDev', inline='sd_b', group=sd_g2), i_sd2 = input.float(2.00, '', inline='sd_b', group=sd_g2, minval = 0, step = 0.01)
s_sd3 = input(true, 'Switch | StDev', inline='sd_c', group=sd_g2), i_sd3 = input.float(1.5, '', inline='sd_c', group=sd_g2, minval = 0, step = 0.01)
sd = ta.stdev(src, length)
z1 = open + (i_sd1 * sd)
z2 = open - (i_sd1 * sd)
z3 = open + (i_sd2 * sd)
z4 = open - (i_sd2 * sd)
z5 = open + (i_sd3 * sd)
z6 = open - (i_sd3 * sd)
//strategy
longCondition = close == z2
longCloseCondition = timenow == time_close
if (longCondition)
strategy.entry("long", strategy.long)
if (longCloseCondition)
strategy.close("long", immediately = true)