OPEN-SOURCE SCRIPT
Mis à jour

15% Discount Overlay

121
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:
Notes de version
//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)

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.