Code:
input length = 14;
plot ADR = MovingAverage(AverageType.wilders, high-low, length);
def plBuy = GetAveragePrice();
def plStraightLine = highestall(plBuy);
plot x=plStraightLine;
x.SetDefaultColor(Color.white);
x.SetLineWeight(1);
plot pl1 = x * 1.015;
pl1.SetDefaultColor(Color.GREEN);
pl1.SetLineWeight(1);
plot pl2 = x - ADR;
pl1.SetDefaultColor(Color.RED);
pl1.SetLineWeight(1);
I have the above study plot three lines on my upper chart once a security is bought. It plots a line for average price, an upper line for 1.5% above average price (my price target) and a lower line that equals average price minus ADR (my stop). However, once I sell and completely liquidate the security, the lines remain on the chart. Is there a way to add code so the lines/plots are removed once the security is sold/liquidated and I no longer hold shares? If so, any help with adding that code to what I already have would be greatly appreciated. Thank you.