Multiple Coefficient Correlation with Labels
Posted: Wed Dec 30, 2020 8:40 pm
Hello Coders/Traders
I added multiple Coefficient Correlation to chart, with labels to identify each symbol. However, label yloc is yloc.price. Label y.loc price value is not matching CC scale value, therefore I can't line up label to CC line.
Any suggestion to align both CC and label value to scale format?
Thank you.
I added multiple Coefficient Correlation to chart, with labels to identify each symbol. However, label yloc is yloc.price. Label y.loc price value is not matching CC scale value, therefore I can't line up label to CC line.
Any suggestion to align both CC and label value to scale format?
Code: Select all
//** CAD - Coefficient Correlation of AUDCAD, NZDCAD, EURCAD, GBPCAD to USDCAD***
//@version=4
study(title="Correlation Coeff", shorttitle="CC", format=format.price, precision=3)
sym1 = input(title="Symbol", type=input.symbol, defval="OANDA:AUDCAD", confirm=true)
sym2 = input(title="Symbol", type=input.symbol, defval="OANDA:NZDCAD", confirm=true)
sym3 = input(title="Symbol", type=input.symbol, defval="OANDA:EURCAD", confirm=true)
sym4 = input(title="Symbol", type=input.symbol, defval="OANDA:GBPCAD", confirm=true)
src = input(close, title="Source")
length = input(20, minval=1)
res=timeframe.period
ovr1 = security(sym1, res, src)
ovr2 = security(sym2, res, src)
ovr3 = security(sym3, res, src)
ovr4 = security(sym4, res, src)
hline = 0.0
plot(correlation(src, ovr1, length), "AUDCAD", color=color.olive, style=plot.style_line, transp=0)
plot(correlation(src, ovr2, length), "NZDCAD", color=color.fuchsia, style=plot.style_line, transp=0)
plot(correlation(src, ovr3, length), "EURCAD", color=color.blue, style=plot.style_line, linewidth=2, transp=0)
plot(correlation(src, ovr4, length), "GBPCAD", color=color.green, style=plot.style_line, linewidth=2, transp=0)
plot(hline, title="Zero Line", color=color.white, style=plot.style_linebr, linewidth=2)
// Offset label
forward_Offset1 = input(1, title="Offset Label 1")
forward_Offset2 = input(5, title="Offset Label 2")
forward_Offset3 = input(10, title="Offset Label 3")
forward_Offset4 = input(15, title="Offset Label 4")
bar_Index_Duration = time - time[1]
lable_Forward_Offset1 = forward_Offset1 * bar_Index_Duration
lable_Forward_Offset2 = forward_Offset2 * bar_Index_Duration
lable_Forward_Offset3 = forward_Offset3 * bar_Index_Duration
lable_Forward_Offset4 = forward_Offset4 * bar_Index_Duration
//Plot Label
cclbl1 = label.new(x = time + lable_Forward_Offset1, y = close, text = "AUDCAD", xloc = xloc.bar_time, yloc = yloc.price, color = color.olive, style = label.style_label_center, textcolor = color.white, size = size.small, textalign = text.align_center)
cclbl2 = label.new(x = time + lable_Forward_Offset2, y = close, text = "NZDCAD", xloc = xloc.bar_time, yloc = yloc.price, color = color.fuchsia, style = label.style_label_down, textcolor = color.white, size = size.small, textalign = text.align_center)
cclbl3 = label.new(x = time + lable_Forward_Offset3, y = close, text = "EURCAD", xloc = xloc.bar_time, yloc = yloc.price, color = color.blue, style = label.style_label_left, textcolor = color.white, size = size.small, textalign = text.align_center)
cclbl4 = label.new(x = time + lable_Forward_Offset4, y = close, text = "GBPCAD", xloc = xloc.bar_time, yloc = yloc.price, color = color.green, style = label.style_label_up, textcolor = color.white, size = size.small, textalign = text.align_center)
label.delete(cclbl1[1])
label.delete(cclbl2[1])
label.delete(cclbl3[1])
label.delete(cclbl4[1])
//What are y.loc options for overlay=false? y.loc for overlay=false, it can't be price, scale is not the same as price.