'Plot stop loss and take profit on chart, pinescript

I have defined the price levels have a way to close trades at that price, but i want to visually show the levels, just to visually verify them. Im new and could not find help on how to. Do this on other sources.



Solution 1:[1]

If you already calculated the prices then just plot them.

This is an example for a strategy("", overlay=true)

in_long_tp_per = input.float(2.0, "Take profit %") * 0.01
in_long_sl_per = input.float(1.0, "Stop loss %") * 0.01

long_tp_price = strategy.position_avg_price * (1 + in_long_tp_per)
long_sl_price = strategy.position_avg_price * (1 - in_long_sl_per)

if (strategy.position_size > 0)
    strategy.exit("exit", "long", limit = long_tp_price, stop = long_sl_price)

plot(long_tp_price , "TP", color.green, 2, plot.style_circles)
plot(long_sl_price , "SL", color.red, 2, plot.style_circles)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vitruvius