The script is called "D2MA" (Distance to Moving Average). It calculates the distance between the closing price and a user-selected type of moving average (MA). It also plots this distance on a chart, allowing users to see how far the price is from the chosen moving average. Users can choose to display this distance as either an absolute value or as a percentage.

Input Parameters

  • Length (len): The number of bars (or periods) used to calculate the moving average.
  • Source (src): The price data used for calculations, typically the closing price.
  • Percentage Distance (pc): A boolean option to display the distance as a percentage instead of an absolute value.
    MA Type (maType): The type of moving average to use.

  1. Simple Moving Average (SMA)
  2. Exponential Moving Average (EMA)
  3. Hull Moving Average (HMA)
  4. Arnaud Legoux Moving Average (ALMA)
  5. Triple Exponential Moving Average (T3)
  6. Power Weighted Moving Average (PWMA)

The script includes functions to calculate different types of moving averages:

The difference between the source price (e.g., closing price) and the calculated moving average. if Distance as Percentage, the distance expressed as a percentage of the moving average value.
Plotting the Data

Signal Line: The signal line changes colour (green or red) based on whether the distance is increasing or decreasing.
Visual Representation

How to Use

  1. Identify Trends: By seeing how far the price is from a selected moving average, traders can gauge the strength of a trend.
  2. Spot Reversals: Significant deviations from the moving average can signal potential reversals.
Mã được bảo vệ
Tập lệnh này được xuất bản mã nguồn đóng và bạn có thể sử dụng một cách tự do. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ. Bạn không thể xem hoặc sửa đổi mã nguồn.
Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?