Here I have a study that will draw a horizontal line from purchase date of average purchase press. Line only moves to re-average when new shares are bought or sold. So if we can have that, trading view has a Drawing tool that will show the area of profit/loss towards profit target and stop loss. Is it possible from this code to add profit/loss horizontal line from purchase price (based on ATR,%,$) to somewhat match the drawing tool on tradingview?
# plot a horizontal line
# at the average price of your open position
def open_position_avg_price = GetAveragePrice();
# color the plot line based on position side
# quantity will be negative if short
def open_position_qty = GetQuantity();
def PnL_Line_Color = if open_position_qty < 0 then -1 else 1;
#debug
#plot PnL_Line_Color__plot = PnL_Line_Color;
# apply long or short logic to line color
plot open_position_avg_price__plot = if (open_position_avg_price <= 0) then Double.NaN else open_position_avg_price;
open_position_avg_price__plot.AssignValueColor(if PnL_Line_Color > 0 then Color.GREEN else Color.RED);
open_position_avg_price__plot.SetLineWeight(3);
# plot a horizontal line
# at the average price of your open position
def open_position_avg_price = GetAveragePrice();
# color the plot line based on position side
# quantity will be negative if short
def open_position_qty = GetQuantity();
def PnL_Line_Color = if open_position_qty < 0 then -1 else 1;
#debug
#plot PnL_Line_Color__plot = PnL_Line_Color;
# apply long or short logic to line color
plot open_position_avg_price__plot = if (open_position_avg_price <= 0) then Double.NaN else open_position_avg_price;
open_position_avg_price__plot.AssignValueColor(if PnL_Line_Color > 0 then Color.GREEN else Color.RED);
open_position_avg_price__plot.SetLineWeight(3);