
    'i                         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	 G d de	      Z
 G d d	e	      Z G d
 de
e      Z G d de	      Z G d dee      Zy)    )absolute_importdivisionprint_functionunicode_literals   )	IndicatorFindFirstIndexHighestFindFirstIndexLowestc                   R     e Zd ZdZdZdZdZ edddg      Zd Z	d	 Z
 fd
Z xZS )
_AroonBasea  
    Base class which does the calculation of the AroonUp/AroonDown values and
    defines the common parameters.

    It uses the class attributes _up and _down (boolean flags) to decide which
    value has to be calculated.

    Values are not assigned to lines but rather stored in the "up" and "down"
    instance variables, which can be used by subclasses to for assignment or
    further calculations
    F))period   )	upperbandF   )	lowerband   g?r   d   )plotymarginplotyhlinesc                 4    | j                   j                  g}|S N)pr   )selfplabelss     Y/var/www/app/trading-bot/venv/lib/python3.12/site-packages/backtrader/indicators/aroon.py
_plotlabelz_AroonBase._plotlabel-   s    66==/    c                     | j                   xj                  | j                  j                  | j                  j                  gz  c_        y r   )plotinfor   r   r   r   )r   s    r   	_plotinitz_AroonBase._plotinit1   s0    !!dff&6&68H8H%II!r   c                    | j                   j                  dz   }| j                  rYt        | j                  j
                  |      }d| j                   j                  z  | j                   j                  |z
  z  | _        | j                  rYt        | j                  j                  |      }d| j                   j                  z  | j                   j                  |z
  z  | _
        t        t        | 7          y )Nr   )r   g      Y@)r   r   _upr	   datahighup_downr
   lowdownsuperr   __init__)r   	idxperiodhhidxllidx	__class__s       r   r*   z_AroonBase.__init__4   s     FFMMA%	88)$))..KEtvv}},1FGDG::(yIE.466==53HIDIj$(*r   )__name__
__module____qualname____doc__r"   r&   paramsdictr   r   r    r*   __classcell__r.   s   @r   r   r      s>    
 CEDF1c(;HJ+ +r   r   c                   *     e Zd ZdZdZdZ fdZ xZS )AroonUpa  
    This is the AroonUp from the indicator AroonUpDown developed by Tushar
    Chande in 1995.

    Formula:
      - up = 100 * (period - distance to highest high) / period

    Note:
      The lines oscillate between 0 and 100. That means that the "distance" to
      the last highest or lowest must go from 0 to period so that the formula
      can yield 0 and 100.

      Hence the lookback period is period + 1, because the current bar is also
      taken into account. And therefore this indicator needs an effective
      lookback period of period + 1.

    See:
      - http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:aroon
    T)aroonupc                 `    t         t        |           | j                  | j                  _        y r   )r)   r8   r*   r%   linesr9   r   r.   s    r   r*   zAroonUp.__init__]   s     gt%'!WW

r   )r/   r0   r1   r2   r"   r;   r*   r5   r6   s   @r   r8   r8   E   s    & CE% %r   r8   c                   *     e Zd ZdZdZdZ fdZ xZS )	AroonDowna  
    This is the AroonDown from the indicator AroonUpDown developed by Tushar
    Chande in 1995.

    Formula:
      - down = 100 * (period - distance to lowest low) / period

    Note:
      The lines oscillate between 0 and 100. That means that the "distance" to
      the last highest or lowest must go from 0 to period so that the formula
      can yield 0 and 100.

      Hence the lookback period is period + 1, because the current bar is also
      taken into account. And therefore this indicator needs an effective
      lookback period of period + 1.

    See:
      - http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:aroon
    T)	aroondownc                 `    t         t        |           | j                  | j                  _        y r   )r)   r>   r*   r(   r;   r?   r<   s    r   r*   zAroonDown.__init__{   s     i')#yy

r   )r/   r0   r1   r2   r&   r;   r*   r5   r6   s   @r   r>   r>   c   s    & EE) )r   r>   c                       e Zd ZdZdZy)AroonUpDowna7  
    Developed by Tushar Chande in 1995.

    It tries to determine if a trend exists or not by calculating how far away
    within a given period the last highs/lows are (AroonUp/AroonDown)

    Formula:
      - up = 100 * (period - distance to highest high) / period
      - down = 100 * (period - distance to lowest low) / period

    Note:
      The lines oscillate between 0 and 100. That means that the "distance" to
      the last highest or lowest must go from 0 to period so that the formula
      can yield 0 and 100.

      Hence the lookback period is period + 1, because the current bar is also
      taken into account. And therefore this indicator needs an effective
      lookback period of period + 1.

    See:
      - http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:aroon
    )AroonIndicatorNr/   r0   r1   r2   alias r   r   rB   rB      s    ,  Er   rB   c                   <     e Zd ZdZdZdZdZdZ fdZ fdZ	 xZ
S )AroonOscillatora  
    It is a variation of the AroonUpDown indicator which shows the current
    difference between the AroonUp and AroonDown value, trying to present a
    visualization which indicates which is stronger (greater than 0 -> AroonUp
    and less than 0 -> AroonDown)

    Formula:
      - aroonosc = aroonup - aroondown

    See:
      - http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:aroon
    T)AroonOsc)aroonoscc                     t         t        |           | j                  j                  d d  D ](  }| j                  j                  j                  |        * y r   )r)   rH   r    r   r   append)r   yhliner.   s     r   r    zAroonOscillator._plotinit   sH    ot.0mm//2 	6FMM%%,,fW5	6r   c                 z    t         t        |           | j                  | j                  z
  | j
                  _        y r   )r)   rH   r*   r%   r(   r;   rJ   r<   s    r   r*   zAroonOscillator.__init__   s)    ot-/"gg		1

r   )r/   r0   r1   r2   r"   r&   rE   r;   r    r*   r5   r6   s   @r   rH   rH      s-     CEEE62 2r   rH   c                       e Zd ZdZdZy)AroonUpDownOscillatorz
    Presents together the indicators AroonUpDown and AroonOsc

    Formula:
      (None, uses the aforementioned indicators)

    See:
      - http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:aroon
    )AroonUpDownOscNrD   rF   r   r   rP   rP      s      Er   rP   N)
__future__r   r   r   r    r   r	   r
   r   r8   r>   rB   rH   rP   rF   r   r   <module>rT      sf   ** * E D'+ '+T%j %<)
 )< '9  42j 2@
 K 
 r   