OPEN-SOURCE SCRIPT

Adaptive Weight Price Oscillator -Aynet

# Adaptive Weight Price Oscillator (AWPO) - Aynet

## Core Components

### 1. Input Parameters
- `fastLength`: Period for the fast EMA calculation (default: 10)
- `slowLength`: Period for the slow EMA calculation (default: 21)
- `adaptiveLength`: Period for calculating volatility-based adaptation (default: 34)
- `smoothing`: Smoothing factor for the adaptive weight (default: 2)

### 2. Price and Weight Calculations

#### Median Price
The indicator uses median price as its base calculation:
```pine
medianPrice = (high + low) / 2
```

#### Volatility-Based Weight
The `getVolatilityRatio` function calculates a volatility ratio:
```pine
getVolatilityRatio(length) =>
std = ta.stdev(medianPrice, length)
ratio = std != 0 ? ta.ema(math.abs(ta.change(medianPrice)), length) / std : 0
math.max(math.min(ratio, 1), 0)
```
This function:
1. Calculates standard deviation of median price
2. Computes the ratio of EMA of price changes to standard deviation
3. Constrains the result between 0 and 1

### 3. AWPO Calculation
The main AWPO value is calculated as:
```pine
awpo = (fastMA - slowMA) * adaptiveWeight
```
Where:
- `fastMA`: EMA of median price using fast length
- `slowMA`: EMA of median price using slow length
- `adaptiveWeight`: Smoothed volatility ratio

## Signal Generation

### 1. Signal Line
- Calculated as an EMA of the AWPO with default length of 9
- Used for generating trading signals

### 2. Trading Signals
The indicator generates several types of signals:

#### Crossover Signals
- Buy signal: When AWPO crosses above the signal line
- Sell signal: When AWPO crosses below the signal line

#### Divergence Signals
- Bearish Divergence: Price makes higher high while AWPO makes lower high
- Bullish Divergence: Price makes lower low while AWPO makes higher low

## Visual Components

### 1. Main Plots
- AWPO line (green/red based on direction)
- Signal line (yellow)
- Zero line (gray, dotted)
- Overbought/Oversold levels (dotted lines)

### 2. Color Fills
- AWPO to Signal line fill (green/red)
- AWPO to Zero line fill (green/red)
- Overbought/Oversold zone fills

### 3. Trade Signals
- Triangle up/down shapes for buy/sell signals
- Diamond shapes for divergence signals

## Anti-Repainting Measures
The code includes measures to prevent repainting:
```pine
var float safe_awpo = na
if barstate.isconfirmed
safe_awpo := awpo
```
This ensures signals only appear on confirmed bars.

## Alert Conditions
The indicator includes two alert conditions:
1. AWPO crossing above signal line (buy)
2. AWPO crossing below signal line (sell)
Breadth Indicatorsconcepteducational

Skrip sumber terbuka

Dalam semangat sebenar TradingView, penulis telah menerbitkan kod Pine ini sebagai sumber terbuka supaya pedagang dapat memahami dan mengesahkannya. Sorakan kepada penulis! Anda boleh menggunakan perpustakaan ini secara percuma, tetapi penggunaan semula kod dalam penerbitan ini adalah dikawal oleh Peraturan dalaman. Anda boleh menyukainya untuk menggunakannya pada carta.

Ingin menggunakan skrip ini pada carta?


Juga pada:

Penafian