
    'ia	                     B    d dl mZmZmZmZ ddlmZmZ  G d de      Zy)    )absolute_importdivisionprint_functionunicode_literals   )	IndicatorMovAvc                   d     e Zd ZdZdZdZddej                  ffZ e	dg      Z
d Z fd	Z xZS )
DetrendedPriceOscillatora  
    Defined by Joe DiNapoli in his book *"Trading with DiNapoli levels"*

    It measures the price variations against a Moving Average (the trend)
    and therefore removes the "trend" factor from the price.

    Formula:
      - movav = MovingAverage(close, period)
      - dpo = close - movav(shifted period / 2 + 1)

    See:
      - http://en.wikipedia.org/wiki/Detrended_price_oscillator
    )DPO)dpo)period   movavg        )
plothlinesc                     | j                   j                  g}|| j                   j                  g| j                   j                  d      z  z  }|S )Nr   )pr   r   
notdefault)selfplabelss     W/var/www/app/trading-bot/venv/lib/python3.12/site-packages/backtrader/indicators/dpo.py
_plotlabelz#DetrendedPriceOscillator._plotlabel8   s>    66==/DFFLL>DFF$5$5g$>>>    c                    | j                   j                  | j                  | j                   j                        }| j                   || j                   j                   dz  dz         z
  | j                  _        t        t        | #          y )N)r      r   )	r   r   datar   linesr   superr   __init__)r   ma	__class__s     r   r   z!DetrendedPriceOscillator.__init__=   sb    VV\\$))DFFMM\: R!(;a(?%@@

&68r   )__name__
__module____qualname____doc__aliasr   r	   Simpleparamsdictplotinfor   r   __classcell__)r!   s   @r   r   r      sH     E E w56F u%H
9 9r   r   N)	
__future__r   r   r   r    r   r	   r    r   r   <module>r/      s    ,* * (9y (9r   