
    'i9                     F    d dl mZmZmZmZ ddlmZmZmZ  G d de      Z	y)    )absolute_importdivisionprint_functionunicode_literals   )MovingAverageBaseMovAvZeroLagIndicatorc                   l     e Zd ZdZdZdZdddej                  fdej                  ffZ	d Z
 fd	Z xZS )
DicksonMovingAveragea|  By Nathan Dickson

    The *Dickson Moving Average* combines the ``ZeroLagIndicator`` (aka
    *ErrorCorrecting* or *EC*) by *Ehlers*, and the ``HullMovingAverage`` to
    try to deliver a result close to that of the *Jurik* Moving Averages

    Formula:
      - ec = ZeroLagIndicator(period, gainlimit)
      - hma = HullMovingAverage(hperiod)

      - dma = (ec + hma) / 2

      - The default moving average for the *ZeroLagIndicator* is EMA, but can
        be changed with the parameter ``_movav``

        .. note:: the passed moving average must calculate alpha (and 1 -
                  alpha) and make them available as attributes ``alpha`` and
                  ``alpha1``

      - The 2nd moving averag can be changed from *Hull* to anything else with
        the param *_hma*

    See also:
      - https://www.reddit.com/r/algotrading/comments/4xj3vh/dickson_moving_average
    )DMA	DicksonMA)dma)	gainlimit2   )hperiod   _movav_hmac                 `   | j                   j                  | j                   j                  | j                   j                  g}|| j                   j                  g| j                   j                  d      z  z  }|| j                   j                  g| j                   j                  d      z  z  }|S )Nr   r   )pperiodr   r   r   
notdefaultr   )selfplabelss     W/var/www/app/trading-bot/venv/lib/python3.12/site-packages/backtrader/indicators/dma.py
_plotlabelzDicksonMovingAverage._plotlabel?   s}    66==$&&"2"2DFFNNCDFFMM?TVV%6%6x%@@@DFFKK=466#4#4V#<<<    c                 L   t        | j                  j                  | j                  j                  | j                  j                        }| j                  j                  | j                  j                        }||z   dz  | j                  _        t        t        | /          y )N)r   r   r   )r   g       @)r
   r   r   r   r   r   r   linesr   superr   __init__)r   echull	__class__s      r   r"   zDicksonMovingAverage.__init__E   sq    TVV]](,(8(8%)VV]]4 vv{{$&&..{1t)s*

 	"D24r   )__name__
__module____qualname____doc__aliasr    r	   EMAHMAparamsr   r"   __classcell__)r%   s   @r   r   r      sH    2 "EE	599		F
5 
5r   r   N)

__future__r   r   r   r    r   r	   r
   r    r   r   <module>r2      s$   ** * 9 835, 35r   