OPEN-SOURCE SCRIPT
Updated

15% Discount Overlay

122
If you want to implement this in a strategy context on TradingView, we need to use the strategy() function to create a backtestable strategy that calculates 15% off the current price and displays a label on the chart.

Below is the updated script that includes the strategy() function. This will allow you to execute a basic strategy while still displaying the label for the 15% off price:
Release Notes
//version=6
indicator("15% Discount Overlay", overlay=true)

// Get the current close price
current_price = close

// Calculate the 15% discount
discount_price = current_price * 0.85

// Plot the discount price as a line
plot(discount_price, color=color.blue, linewidth=2, title="Normal")
plot(close, color=color.red, linewidth=2, title="15% Discount")

if bar_index % 10 == 0 or bar_index == last_bar_index
label.new(bar_index, close, text=str.tostring(close, "#.##"), style=label.style_label_up, color=color.white, textcolor=color.red, size=size.small)
label.new(bar_index, discount_price, text=str.tostring(discount_price, "#.##"), style=label.style_label_up, color=color.white, textcolor=color.blue, size=size.small)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.