
    'i                     X    d dl mZmZmZmZ ddlmZmZ  G d de      Z G d de      Z	y)	    )absolute_importdivisionprint_functionunicode_literals   )	IndicatorMovAvc                   f     e Zd ZdZdZdZdddej                  ffZ e	dg      Z
d	 Z fd
Z xZS )Trixa  
    Defined by Jack Hutson in the 80s and shows the Rate of Change (%) or slope
    of a triple exponentially smoothed moving average

    Formula:
      - ema1 = EMA(data, period)
      - ema2 = EMA(ema1, period)
      - ema3 = EMA(ema2, period)
      - trix = 100 * (ema3 - ema3(-1)) / ema3(-1)

      The final formula can be simplified to: 100 * (ema3 / ema3(-1) - 1)

    The moving average used is the one originally defined by Wilder,
    the SmoothedMovingAverage

    See:
      - https://en.wikipedia.org/wiki/Trix_(technical_analysis)
      - http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:trix
    )TRIX)trix)period   )
_rocperiodr   _movavg        )
plothlinesc                    | j                   j                  g}|| j                   j                  g| j                   j                  d      z  z  }|| j                   j                  g| j                   j                  d      z  z  }|S )Nr   r   )pr   r   
notdefaultr   )selfplabelss     X/var/www/app/trading-bot/venv/lib/python3.12/site-packages/backtrader/indicators/trix.py
_plotlabelzTrix._plotlabel5   si    66==/DFF%%&):):<)HHHDFFMM?TVV%6%6x%@@@    c                    | j                   j                  | j                  | j                   j                        }| j                   j                  || j                   j                        }| j                   j                  || j                   j                        }d| || j                   j                         z  dz
  z  | j
                  _        t        t        | '          y )Nr   g      Y@g      ?)
r   r   datar   r   linesr   superr   __init__)r   ema1ema2ema3	__class__s       r   r    zTrix.__init__;   s    vv}}TYYtvv}}}=vv}}T$&&--}8vv}}T$&&--}8  4$0A0A/A*B#BS#HI

dD"$r   )__name__
__module____qualname____doc__aliasr   r	   EMAparamsdictplotinfor   r    __classcell__r$   s   @r   r   r      sE    & EE/(EII1FHFu%H	% 	%r   r   c                   *     e Zd ZdZdZdZ fdZ xZS )
TrixSignalz
    Extension of Trix with a signal line (ala MACD)

    Formula:
      - trix = Trix(data, period)
      - signal = EMA(trix, sigperiod)

    See:
      - http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:trix
    )signal))	sigperiod	   c                     t         t        |           | j                  j	                  | j
                  d   | j                  j                        | j                  _        y )Nr   r   )	r   r1   r    r   r   r   r3   lr2   )r   r$   s    r   r    zTrixSignal.__init__U   s>    j$(*djjmDFF<L<LMr   )r%   r&   r'   r(   r   r+   r    r.   r/   s   @r   r1   r1   G   s     	 E FN Nr   r1   N)

__future__r   r   r   r    r   r	   r   r1    r   r   <module>r:      s/   ** * )%9 )%XN Nr   