Master Owl
Master Owl

Reputation: 17

Open Daily Line Normal Distribution

I've a discrepancy between my indicator and the line plotted.

(SDev Levels wrongHere the screenshot of the chart and below the code in pinescritp)

The standard deviation -1 in the script is -1.54%. Plotted on the chart the line is -1.78%.

I don't know why there is a discrepancy between the input and the output. Please can someone give an idea?

Thank you very much

//@version=5

indicator('Daily SD Levels', 'Daily SD Levels', true)

// Request the daily open
[do_1] = request.security(syminfo.tickerid, 'D', [open], lookahead = barmerge.lookahead_on)

// Add "D" label on the daily open line
if barstate.islast // Ensures the label is plotted only on the latest bar
    label.new(bar_index, do_1, text = "D", style = label.style_label_down, 
              color = color.new(color.yellow, 80), textcolor = color.white)

// Standard deviation calculation
lookbackInput = input(5)
var float doStdev = na
if do_1 != do_1[1]
    doStdev := ta.stdev(do_1, lookbackInput)

// Plotting bands around the daily open //BEFORE 0.63
plot1 = do_1 + doStdev * 0.77
plot2 = do_1 + doStdev * -0.77
plot3 = do_1 + doStdev * 1.54
plot4 = do_1 + doStdev * -1.54
plot5= do_1 + doStdev * 2.31
plot6= do_1 + doStdev * -2.31
plot7= do_1 + doStdev * 3.08
plot8= do_1 + doStdev * -3.08
plot9= do_1 + doStdev * 4.62
plot10= do_1 + doStdev * -4.62

plot(plot9, title= "SD +3", color = color.green)
plot(plot7, title= "SD +2", color = color.green)
plot(plot5, title= "SD +1.5", color = color.green)
plot(plot3, title= "SD +1", color = color.green)
plot(plot1, title= "SD +0.5", color = color.green)
// Plot the daily open line
plot(do_1, title = 'Open', color = color.new(color.yellow, 0), linewidth = 1, trackprice = false)
plot(plot2, title= "SD -0.5", color = color.red)
plot(plot4, title= "SD -1", color = color.red)
plot(plot6, title= "SD -1.5", color = color.red)
plot(plot8, title= "SD -2", color = color.red)
plot(plot10, title= "SD -3", color = color.red)
// Add labels for the standard deviation levels
if barstate.islast // Ensures labels are only added on the latest bar
    label.new(bar_index, plot1, text = "SD +0.5", style = label.style_label_left, 
              color = color.new(color.green, 80), textcolor = color.white)
    label.new(bar_index, plot2, text = "SD -0.5", style = label.style_label_left, 
              color = color.new(color.red, 80), textcolor = color.white)
    label.new(bar_index, plot3, text = "SD +1", style = label.style_label_left, 
              color = color.new(color.green, 80), textcolor = color.white)
    label.new(bar_index, plot4, text = "SD -1", style = label.style_label_left, 
              color = color.new(color.red, 80), textcolor = color.white)
    label.new(bar_index, plot5, text = "SD +1.5", style = label.style_label_left, 
              color = color.new(color.green, 80), textcolor = color.white)
    label.new(bar_index, plot6, text = "SD -1.5", style = label.style_label_left, 
              color = color.new(color.red, 80), textcolor = color.white)
    label.new(bar_index, plot7, text = "SD +2", style = label.style_label_left, 
              color = color.new(color.green, 80), textcolor = color.white)
    label.new(bar_index, plot8, text = "SD -2", style = label.style_label_left, 
              color = color.new(color.red, 80), textcolor = color.white)
    label.new(bar_index, plot9, text = "SD +3", style = label.style_label_left, 
              color = color.new(color.green, 80), textcolor = color.white)
    label.new(bar_index, plot10, text = "SD -3", style = label.style_label_left, 
              color = color.new(color.red, 80), textcolor = color.white)

Upvotes: 0

Views: 39

Answers (0)

Related Questions