OPEN-SOURCE SCRIPT
已更新

Percentual Variation

This script is an indicator for plotting percentage-based lines using the previous day's closing price. It is useful for traders who want to visualize support and resistance levels derived from predefined percentages. Here's what the script does:

Calculates percentage levels:

It uses the previous day's closing price to calculate two positive levels (above the close) and two negative levels (below the close) based on fixed percentages:
+0.25% and +0.50% (above the close).
-0.25% and -0.50% (below the close).
Plots the lines on the chart:

Draws four horizontal lines representing the calculated levels:
Green lines indicate levels above the closing price.
Red lines indicate levels below the closing price.
Displays labels on the chart:

Adds labels near the lines showing the corresponding percentage, such as "+0.25%", "+0.50%", "-0.25%", and "-0.50%".
This script provides a clear visual representation of key percentage-based levels, which can be used as potential entry, exit, or target points in trading strategies.
發行說明
"Configurable Percentage Variation"

This script, written in Pine Script version 6, is designed to display levels of percentage variations around the previous day's closing price on a trading chart. Users can configure these levels, including their percentage values, line colors, and line styles, directly through the script's input settings.

#### Key Features:
1. **Configurable Percentage Levels**:
- Define up to four percentage variation levels (`Percentage 1` to `Percentage 4`).
- Each level is calculated based on the closing price of the previous day.

2. **Customizable Line Appearance**:
- Users can modify the **color** of each line through the input settings.
- Choose from three **line styles**: Solid, Dashed, and Dotted.

3. **Dynamic Updates**:
- The script automatically updates the lines at the beginning of each trading day and extends them throughout the current session.

4. **Labels with Percentage and Price**:
- At the end of each trading session, the script displays labels near the lines, showing the percentage value and its corresponding price.

5. **User-Friendly Inputs**:
- Easily adjust the percentage values and visual aspects of the lines (color and style) without modifying the code.

6. **Precision Placement**:
- Lines are drawn with reference to the previous day's closing price and extend dynamically across the current trading session.

#### How to Use:
1. Load the script onto your trading chart.
2. Use the input fields to:
- Set the percentage variations.
- Choose the line color for better visual distinction.
- Select the line style (Solid, Dashed, or Dotted).
3. Observe the lines representing the calculated percentage levels for the day, and the labels indicating their specific values.

This script empowers users to tailor the visual representation of percentage levels to their preference, enhancing chart analysis and decision-making.
發行說明
This correction ensures that the percentage and price levels are correctly displayed in the labels. The issue was caused by improper text formatting in the label.new and label.set_text functions.

The solution includes:

Proper text formatting using str.tostring with "#.##" for percentages and format.mintick for price values.
Adding line breaks (\n) to separate the percentage and price on the label for better readability.
Ensuring that labels are only created once and updated as needed.
This fixes the issue of labels not displaying the desired information correctly.
發行說明
Modifications to the Calculation
Adjusted Lines to Start from the Beginning of the Day

What I Did:
I modified the script to ensure that the percentage-based lines (positive and negative levels) start at the beginning of the current trading day rather than at the current bar. To achieve this:

I calculated the timestamp for the start of the day using the timestamp() function.
I retrieved the bar_index corresponding to the start of the day using the request.security() function.
The x1 coordinate of the lines was updated to use this startBarIndex.
Why I Did It:
This change ensures that the percentage levels are visualized as spanning the entire trading day, providing better clarity and relevance for intraday analysis.

Dynamic Line Updates

What I Did:
I ensured that the lines dynamically extend to the current bar by updating their x2 coordinate to match the current bar_index. The x1 coordinate remains fixed at the start of the day.

Why I Did It:
This ensures that the lines remain relevant and up-to-date as new bars are added throughout the trading day.

Benefits of the Modifications
Clearer Visualization:
By anchoring the lines to the start of the day, it’s easier to see how the price interacts with these levels throughout the session.

Intraday Relevance:
The percentage levels are now tied to the day's context, making them more useful for day traders or those analyzing intraday price movements.

免責聲明