
    'i$                     n    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	 G d d	e      Z
y
)    )absolute_importdivisionprint_functionunicode_literals   )	IndicatorCmpExc                   B     e Zd ZdZdZ ed      ZdZd Z fdZ	 xZ
S )
PivotPointa:  
    Defines a level of significance by taking into account the average of price
    bar components of the past period of a larger timeframe. For example when
    operating with days, the values are taking from the already "past" month
    fixed prices.

    Example of using this indicator:

      data = btfeeds.ADataFeed(dataname=x, timeframe=bt.TimeFrame.Days)
      cerebro.adddata(data)
      cerebro.resampledata(data, timeframe=bt.TimeFrame.Months)

    In the ``__init__`` method of the strategy:

      pivotindicator = btind.PivotPoiont(self.data1)  # the resampled data

    The indicator will try to automatically plo to the non-resampled data. To
    disable this behavior use the following during construction:

      - _autoplot=False

    Note:

      The example shows *days* and *months*, but any combination of timeframes
      can be used. See the literature for recommended combinations

    Formula:
      - pivot = (h + l + c) / 3  # variants duplicate close or add open
      - support1 = 2.0 * pivot - high
      - support2 = pivot - (high - low)
      - resistance1 = 2.0 * pivot - low
      - resistance2 = pivot + (high - low)

    See:
      - http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:pivot_points
      - https://en.wikipedia.org/wiki/Pivot_point_(technical_analysis)
    )ps1s2r1r2Fsubplot)openFcloseF	_autoplotTc                     | j                   j                  r=t        | j                  d      r&| j                  j                  | j                  _        y y y Ndatar   r   hasattrr   plotinfo
plotmasterselfs    ^/var/www/app/trading-bot/venv/lib/python3.12/site-packages/backtrader/indicators/pivotpoint.py	_plotinitzPivotPoint._plotinitJ   ;    66tyy&)+/99>>( *     c                     | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  }| j
                  j                  r ||z   d|z  z   dz  x| j                  _        }nR| j
                  j                  r ||z   |z   |z   dz  x| j                  _        }n||z   |z   dz  x| j                  _        }d|z  |z
  | j                  _        d|z  |z
  | j                  _        |||z
  z
  | j                  _	        |||z
  z   | j                  _
        t        t        | 7          | j
                  j                  rd| j                  _         |         y y N       @      @g      @F)r   r   highlowr   r   linesr   r   r   r   superr   __init__r   r   plotr!   ohlcr   	__class__s         r"   r.   zPivotPoint.__init__P   s(   IINNIINNIIMMIIOO66<< !Aa366DJJL1VV[[ !A	A44DJJL1 !A	S00DJJL1a!

a!

QU

QU

j$(*66!&DMMF r%   __name__
__module____qualname____doc__r,   dictr   paramsr#   r.   __classcell__r5   s   @r"   r   r      s0    $J +EE"HF: r%   r   c                   B     e Zd ZdZdZ ed      ZdZd Z fdZ	 xZ
S )FibonacciPivotPointa(  
    Defines a level of significance by taking into account the average of price
    bar components of the past period of a larger timeframe. For example when
    operating with days, the values are taking from the already "past" month
    fixed prices.

    Fibonacci levels (configurable) are used to define the support/resistance levels

    Example of using this indicator:

      data = btfeeds.ADataFeed(dataname=x, timeframe=bt.TimeFrame.Days)
      cerebro.adddata(data)
      cerebro.resampledata(data, timeframe=bt.TimeFrame.Months)

    In the ``__init__`` method of the strategy:

      pivotindicator = btind.FibonacciPivotPoiont(self.data1)  # the resampled data

    The indicator will try to automatically plo to the non-resampled data. To
    disable this behavior use the following during construction:

      - _autoplot=False

    Note:

      The example shows *days* and *months*, but any combination of timeframes
      can be used. See the literature for recommended combinations

    Formula:
      - pivot = (h + l + c) / 3  # variants duplicate close or add open
      - support1 = p - level1 * (high - low)  # level1 0.382
      - support2 = p - level2 * (high - low)  # level2 0.618
      - support3 = p - level3 * (high - low)  # level3 1.000
      - resistance1 = p + level1 * (high - low)  # level1 0.382
      - resistance2 = p + level2 * (high - low)  # level2 0.618
      - resistance3 = p + level3 * (high - low)  # level3 1.000

    See:
      - http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:pivot_points
    )r   r   r   s3r   r   r3Fr   r   r   r   )level1g r?)level2g-?)level3g      ?c                     | j                   j                  r=t        | j                  d      r&| j                  j                  | j                  _        y y y r   r   r    s    r"   r#   zFibonacciPivotPoint._plotinit   r$   r%   c                 p   | j                   j                  }| j                   j                  }| j                   j                  }| j                   j                  }| j
                  j                  r ||z   d|z  z   dz  x| j                  _        }nR| j
                  j                  r ||z   |z   |z   dz  x| j                  _        }n||z   |z   dz  x| j                  _        }|| j
                  j                  ||z
  z  z
  | j                  _        || j
                  j                  ||z
  z  z
  | j                  _
        || j
                  j                  ||z
  z  z
  | j                  _        || j
                  j                  ||z
  z  z   | j                  _        || j
                  j                  ||z
  z  z   | j                  _        || j
                  j                  ||z
  z  z   | j                  _        t         t"        | K          | j
                  j&                  rd| j(                  _         |         y y r'   )r   r   r*   r+   r   r   r,   rD   r   rE   r   rF   rA   r   r   rB   r-   r@   r.   r   r   r/   r0   s         r"   r.   zFibonacciPivotPoint.__init__   s   IINNIINNIIMMIIOO66<< !Aa366DJJL1VV[[ !A	A44DJJL1 !A	S00DJJL1DFFMMQU33

DFFMMQU33

DFFMMQU33

DFFMMQU33

DFFMMQU33

DFFMMQU33

!41366!&DMMF r%   r6   r>   s   @r"   r@   r@   j   s0    'P 6EE"HF: r%   r@   c                   B     e Zd ZdZdZ ed      ZdZd Z fdZ	 xZ
S )DemarkPivotPointa  
    Defines a level of significance by taking into account the average of price
    bar components of the past period of a larger timeframe. For example when
    operating with days, the values are taking from the already "past" month
    fixed prices.

    Example of using this indicator:

      data = btfeeds.ADataFeed(dataname=x, timeframe=bt.TimeFrame.Days)
      cerebro.adddata(data)
      cerebro.resampledata(data, timeframe=bt.TimeFrame.Months)

    In the ``__init__`` method of the strategy:

      pivotindicator = btind.DemarkPivotPoiont(self.data1)  # the resampled data

    The indicator will try to automatically plo to the non-resampled data. To
    disable this behavior use the following during construction:

      - _autoplot=False

    Note:

      The example shows *days* and *months*, but any combination of timeframes
      can be used. See the literature for recommended combinations

    Formula:
      - if close < open x = high + (2 x low) + close

      - if close > open x = (2 x high) + low + close

      - if Close == open x = high + low + (2 x close)

      - p = x / 4

      - support1 = x / 2 - high
      - resistance1 = x / 2 - low

    See:
      - http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:pivot_points
    )r   r   r   Fr   rC   c                     | j                   j                  r=t        | j                  d      r&| j                  j                  | j                  _        y y y r   r   r    s    r"   r#   zDemarkPivotPoint._plotinit   r$   r%   c                 t   | j                   j                  d| j                   j                  z  z   | j                   j                  z   }d| j                   j                  z  | j                   j                  z   | j                   j                  z   }| j                   j                  | j                   j                  z   d| j                   j                  z  z   }t	        | j                   j                  | j                   j
                  |||      }|dz  | j                  _        |dz  | j                   j                  z
  | j                  _        |dz  | j                   j                  z
  | j                  _	        t        t        | 3          | j                  j                  rd| j                  _         |         y y )Nr(   r)   F)r   r*   r+   r   r	   r   r,   r   r   r   r-   rJ   r.   r   r   r/   )r!   x1x2x3xr5   s        r"   r.   zDemarkPivotPoint.__init__   s!   YY^^cDIIMM11DIIOOC499>>!DIIMM1DIIOOCYY^^diimm+cDIIOO.CC$))//499>>2r2>3w

C$))..0

C$))--/

.066!&DMMF r%   r6   r>   s   @r"   rJ   rJ      s0    (R EE"HF: r%   rJ   N)
__future__r   r   r   r    r   r	   r   r@   rJ    r%   r"   <module>rT      s@   ** * L L^S) SlJy Jr%   