
    iC                     H   S SK Jr  S SKJr  S SKJrJr  S SKJrJ	r	J
r
  S SKJr  S SKJrJrJrJrJrJr  / SQr S*S	\S
\S\S\	S\4
S jjr  S*S	\S\
S\S\	S\4
S jjr S*S	\S
\S\S\	S\4
S jjr  S*S	\S\
S\S\	S\4
S jjr  S+S	\S
\S\S\S\S\	S\S\4S jjr  S+S	\S\
S\S\S\S\	S\4S jjr    S,S\S\
S\
S\S\S\S\S\S\	S\4S  jjr  S-S	\S
\S\S\S\	S\4S! jjr   S.S"\S#\S$\	S%\	S\	S\S\4S& jjr   S/S'\S\
\-  S\
\-  S\S(\S#\S$\	S\	S\S\4S) jjrg)0    )partial)nan)	DataFrameSeries)DictLikeIntIntFloat)zero)v_boolv_driftv_floatv_intv_offsetv_series)	aboveabove_valuebelowbelow_valuecrosscross_valuesignalstsignalsxsignalsNxyasintoffsetreturnc                 0    [        [        SS9" X4X#S.UD6$ )a  Above

Determines if each ```x``` value is above (or ```>=```) each ```y``` value.

Parameters:
    x (Series): ```x```
    y (Series): ```y```
    asint (bool): Returns as ```Int```.
    offset (Int): Post shift. Default: ```0```

Returns:
    (Series): State where ```x >=  y```.

Example:
    ```py
    x = Series([4, 2, 0, -1, 1])
    y = Series([1, 1, 1, 1, 1])

    x_above_y = ta.above(x, y)
    # x_above_y = Series([1, 1, 0, 0, 1])
    ```
Tr   r   r   r   _above_belowr   r   r   r   kwargss        S/var/www/html/trading/venv/lib/python3.13/site-packages/pandas_ta/utils/_signals.pyr   r   !   s!    2 <t,QXXQWXX    valuec                     [        U[        [        45      (       d  [        S5        g[	        XR
                  U R                  SS5      S9n[        [        SS9" X4X#S.UD6$ )	a  Above Value

Determines if each ```x``` value is above (or ```>=```) a
constant ```value```.

Parameters:
    x (Series): ```x```
    value (IntFloat): Value to compare with ```x```.
    asint (bool): Returns as ```Int```.

Returns:
    (Series): State where ```x >= y```.

Example:
    ```py
    x = Series([4, 2, 0, -1, 1])
    x_above_1 = ta.above_value(x, 1)
    # x_above_1 = Series([1, 1, 0, 0, 1])
    ```
[X] value is not a numberN._indexnameTr    r!   	
isinstanceintfloatprintr   r.   replacer   r#   r   r(   r   r   r%   r   s         r&   r   r   =   s]    0 ec5\**)*uGGUG*<*<S#*FGA<t,QXXQWXXr'   c                 0    [        [        SS9" X4X#S.UD6$ )a  Below

Determines if each ```x``` value is below (or ```<=```) each ```y``` value.

Parameters:
    x (Series): ```x```
    y (Series): ```y```
    asint (bool): Returns as ```Int```.
    offset (Int): Post shift. Default: ```0```

Returns:
    (Series): State where ```x <= y```.

Example:
    ```py
    x = Series([4, 2, 0, -1, 1])
    y = Series([1, 1, 1, 1, 1])

    x_below_y = ta.below(x, y)
    # x_below_y = Series([0, 0, 1, 1, 1])
    ```
Fr    r!   r"   r$   s        r&   r   r   \   s!    2 <u-aY%YRXYYr'   c                     [        U[        [        45      (       d  [        S5        g[	        XR
                  U R                  SS5      S9n[        [        SS9" X4X#S.UD6$ )	a  Below Value

Determines if each ```x``` value is below (or ```<=```) a
constant ```value```.

Parameters:
    x (Series): ```x```
    value (IntFloat): Value to compare with ```x```.
    asint (bool): Returns as ```Int```.
    offset (Int): Post shift. Default: ```0```

Returns:
    (Series): State where ```x <= y```.

Example:
    ```py
    x = Series([4, 2, 0, -1, 1])
    x_below_1 = ta.below_value(x, 1)
    # x_below_1 = Series([0, 0, 1, 1, 1])
    ```
r*   Nr+   r,   r-   Fr    r!   r0   r6   s         r&   r   r   x   s]    2 ec5\**)*uGGUG*<*<S#*FGA<u-aY%YRXYYr'   r   equalr%   c                 f   [        U 5      n [        U5      n[        U5      nU R                  [        5        UR                  [        5        U(       a3  U(       a  X:  OX:  nU R	                  S5      UR	                  S5      :  nO2U(       a  X:*  OX:  nU R	                  S5      UR	                  S5      :  nXx-  n	SU	R
                  S'   U(       a  U	R                  [        5      n	US:w  a  U	R	                  U5      n	U R                   SU(       a  SOS SUR                   3U	l        SU	l	        U	$ )a  Cross

Determines where ```x``` crosses ```y```, either _above_ or _below_,
strictly (_equal_) or not.

Parameters:
    x (Series): ```x```
    y (Series): ```y```
    above (bool): Check above. Check below, set ```above=False```
    equal (bool): At least/most, ```=```, check.
    asint (bool): Returns as ```Int```.
    offset (Int): Post shift. Default: ```0```

Returns:
    (Series): Values where ```x``` crosses ```y```.

Example:
    ```py
    x = Series([4, 2, 0, -1, 1])
    y = Series([1, 1, 1, 1, 1])

    # Cross Above Examples
    x_xae_y = ta.cross(x, y, above=True, equal=True)
    # x_xae_y = Series([0, 0, 0, 0, 1])

    x_xa_y = ta.cross(x, y, above=True, equal=False)
    # x_xa_y = Series([0, 0, 0, 0, 0])

    # Cross Below Examples
    x_xbe_y = ta.cross(x, y, above=False, equal=True)
    # x_xbe_y = Series([0, 0, 1, 0, 1])

    x_xb_y = ta.cross(x, y, above=False, equal=False)
    # x_xb_y = Series([0, 0, 1, 0, 0])
    ```
   Fr   r,   XAXBsignal)
r   r   applyr
   shiftilocastyper2   r/   category)
r   r   r   r9   r   r   r%   currentpreviousr   s
             r&   r   r      s    V 	AAfFGGDMGGDM !!&qu771:
*!!&qu771:
*EEJJqMS! {F# FF81UT5Qqvvh?EJENLr'   c                 h    [        XR                  U R                  SS5      S9n[        XX#XE40 UD6$ )a  Cross Value

Determines where ```x``` crosses a constant ```value```, either _above_
or _below_, strictly (_equal_) or not.

Parameters:
    x (Series): ```x```
    value (IntFloat): Value to compare with ```x```.
    above (bool): Check above. Check below, set ```above=False```
    equal (bool): At least/most, ```=```, check.
    asint (bool): Returns as ```Int```.
    offset (Int): Post shift. Default: ```0```

Returns:
    (Series): Values where ```x``` crosses ```y```.

Example:
    ```py
    x = Series([4, 2, 0, -1, 1])

    # Cross Above Examples
    x_xae_y = ta.cross_value(x, 1, above=True, equal=True)
    # x_xae_y = Series([0, 0, 0, 0, 1])

    x_xa_y = ta.cross_value(x, 1, above=True, equal=False)
    # x_xa_y = Series([0, 0, 0, 0, 0])

    # Cross Below Examples
    x_xbe_y = ta.cross_value(x, 1, above=False, equal=True)
    # x_xbe_y = Series([0, 0, 1, 0, 1])

    x_xb_y = ta.cross_value(x, 1, above=False, equal=False)
    # x_xb_y = Series([0, 0, 1, 0, 0])
    ```
r+   r,   r-   )r   r.   r5   r   )r   r(   r   r9   r   r   r%   r   s           r&   r   r      s8    R 	uGGUG*<*<S#*FGAuU=f==r'   	indicatorxaxbcross_valuesxseries	xseries_a	xseries_bcross_seriesc	                    [        5       n	Ubm  [        U[        [        45      (       aR  U(       a3  [	        XSUS9n
[	        XSUS9nXU
R
                  '   XUR
                  '   O[        XUS9nXUR
                  '   Ubm  [        U[        [        45      (       aR  U(       a3  [	        XSUS9n[	        XSUS9nXUR
                  '   XUR
                  '   O[        XUS9nXUR
                  '   Uc  UnUc  UnUb<  [        U5      (       a,  U(       a  [        XSUS9nO
[        XUS9nUU	UR
                  '   Ub<  [        U5      (       a,  U(       a  [        XSUS9nO
[        XUS9nUU	UR
                  '   U	$ )a  Signals

Mulitfuncational signal checker that determines whether an
indicator crosses above/below value or Series.

Parameters:
    indicator (Series): Indicator to check for signal crossings.
    cross_values (bool): Check if crossed value.
    xseries (Series): Cross Series
    xseries_a (Series): Cross Above Series
    xseries_b (Series): Cross Below Series
    cross_series (bool): Check if crossed ```xseries```.

Other Parameters:
    xa (IntFloat): Crossing above value.
    xb (IntFloat): Crossing below value.
    offset (Int): Post shift. Default: ```0```

Returns:
    (DataFrame): 2 columns

Note:
    See sources of: ```er```, ```macd```, ```rsi```, and ```rsx```
    for examples of use.
T)r   r   F)r   )r   r1   r2   r3   r   r/   r   r   r   r   r   r   )rG   rH   rI   rJ   rK   rL   rM   rN   r   dfxa_startxa_endxd_abovexb_startxb_endxd_belowxsaxsbs                     r&   r   r     sb   > 
B	~*R#u66"9VLH eFKF (x}}$v{{O"9@H (x}}	~*R#u66"9VLH eFKF (x}}$v{{O"9@H (x}} 		)!4!4	DHC	V<C388)!4!4	E&IC	V<C388Ir'   c                    [        U 5      n [        U5      n[        U5      nU R                  [        5        UR                  [        5        U(       a  X:  nOX:*  nU(       a  UR	                  [
        5      nUS:w  a  UR                  U5      nU R                   SU(       a  SOS SUR                   3Ul        SUl        U$ )a  Above / Below

Determines if ```x``` is above or below ```y```.

Parameters:
    x (Series): ```x```
    y (Series): ```y```
    above (bool): Above check. Below: ```above=False```
    equal (bool): At least/most, ```=```, check.
    asint (bool): Returns as ```Int```.
    offset (Int): Post shift. Default: ```0```

Returns:
    (Series): Values where ```x``` values are above/below ```y``` values.
r   r,   ABr>   )	r   r   r?   r
   rB   r2   r@   r/   rC   )r   r   r   r   r   r%   rD   s          r&   r#   r#   b  s    * 	AAfFGGDMGGDM &&..% {--' ffXQes5Qqvvh?GLGNr'   trendasbooltrade_offsetdriftc                    [        U 5      n U c  g[        US5      n[        US5      n[        U5      n[	        U5      nU R                  [        5      nUR                  U5      R                  U5      R                  S5      R                  [        5      nUS:  R                  [        5      nUS:  R                  5       R                  [        5      n	U(       a?  UR                  [        5      nUR                  [        5      nU	R                  [        5      n	SUSUSUSU	0n
[        XR                  S9nUS:w  a  UR                  U5      nS	U;   a  UR                  US	   S
S9  SUl        SUl        U$ )a  Trend Signals

This function creates Trend, Trades, Entries and Exit values per bar when
given a trend condition e.g. ```trend = close > sma(close, 50)```.

Source:
    * Kevin Johnson

Parameters:
    trend (Series): ```trend``` Series. Boolean or integer values of
        ```0``` and ```1```
    asbool (bool): Return booleans. Default: ```False```
    trade_offset (value): Shift trade entries/exits with live: ```0``` and
        backesting: ```1```. Default: ```0```
    drift (int): Difference amount. Default: ```1```
    offset (int): Post shift. Default: ```0```

Other Parameters:
    fillna (value): ```pd.DataFrame.fillna(value)```

Returns:
    (DataFrame): 4 columns

Note: Column Detail
    * Trends (trend: 1, no trend: 0)
    * Trades (Enter: 1, Exit: -1, Otherwise: 0)
    * Entries (entry: 1, nothing: 0)
    * Exits (exit: 1, nothing: 0)

Note: Details
    A ```trend``` is a state or condition, that is as simple
    as ```Close > MA``` or something more complex that has boolean
    or integer (trend: 1, no trend: 0) values.

Tip: VectorBT
    * For backtesting, set ```trade_offset=1```.
    * Setting ```asbool=True``` is useful for backtesting with vectorbt's
      ```Portfolio.from_signal(close, entries, exits)``` method.

Example:
    These are two different outcomes for each (long/short) position and
    depends on the source and it's behavior.

    Signals when ```Close > SMA50(Close)```

        ta.tsignals(close > ta.sma(close, 50), asbool=False)

    Signals when ```EMA(Close, 8) > EMA(Close, 21)```

        ta.tsignals(ta.ema(close, 8) > ta.ema(close, 21), asbool=True)

Warning:
    Check ALL outcomes BEFORE making an Issue
NFr   	TS_Trends	TS_Trades
TS_EntriesTS_Exits)r.   fillnaTinplaceTSr\   )r   r   r   r   r   rB   r2   diffr@   re   absboolr   r.   r/   rC   )r\   r]   r^   r_   r   r%   trendstradesentriesexitsdatarP   s               r&   r   r     sV   x UOE}FE"Fq)LENEfF \\#F[[%%l3::1=DDSIFz!!#&GaZ%%c*Et$..&T" f
f
w
U	D 
4||	,B {XXf 6
		&"D	1 BGBKIr'   sourcelongc                    [        U 5      n U c  g[        U5      nU(       a  [        X5      n	[        XSS9* n
O[        XSS9n	[        X5      * n
X-   nUR                  S[        0SS9  UR                  SSS9  UR                  SSS9  US:  R                  [        5      nU(       d  S	U-
  nUUUS
.n[        U40 UD6n[        SUR                  SS	UR                  -
  05        SU;   a  UR                  US   SS9  SUl        SUl        U$ )a  Cross Signals

This function creates Trend, Trades, Entries and Exits values per bar
for crossing events.

Sources:
    * Kevin Johnson

Parameters:
    source (Series): ```source``` Signal
    xa (Series): Series the Signal crosses above if ```above=True```
    xb (Series): Series the Signal crosses below if ```above=True```
    above (bool): The ```source``` crossing; below is ```False```.
        Default: ```True```
    long (bool): The ```source``` position; short is ```False```.
        Default: ```True```
    offset (int): Post shift. Default: ```0```
    asbool (bool): Return booleans. Default: ```False```
    trade_offset (value): Shift trade entries/exits with live: ```0``` and
        backesting: ```1```. Default: ```0```

Other Parameters:
    fillna (value): ```pd.DataFrame.fillna(value)```

Returns:
    (DataFrame): 4 columns

Note: Column Detail
    * Trends  (trend: 1, no trend: 0)
    * Trades  (Enter: 1, Exit: -1, Otherwise: 0)
    * Entries (entry: 1, nothing: 0)
    * Exits   (exit: 1, nothing: 0)

Tip: VectorBT
    * For backtesting, set ```trade_offset=1```.
    * Setting ```asbool=True``` is useful for backtesting with vectorbt's
      ```Portfolio.from_signal(close, entries, exits)``` method.

Example:
    These are two different outcomes for each (long/short) position and
    depends on the source and it's behavior.

        rsi = df.ta.rsi()

    When RSI crosses above 20 and then below 80 in a long position:

        ta.xsignals(source=rsi, xa=20, xb=80, above=True, long=True)
        # Simpler
        # ta.xsignals(rsi, 20, 80, True, True)

    When RSI crosses below 20 and then above 80 in a long position:

        ta.xsignals(source=rsi, xa=20, xb=80, above=False, long=True)
        # Simpler
        # ta.xsignals(rsi, 20, 80, False, True)

    * Similarly, short positions (```long=False```) also differ depending
      on ```above``` state.

Warning:
    Check ALL parameter combination outcomes BEFORE making an Issue.
NFr    r   Trf   inside)
limit_arearg   r;   )r]   r^   r   XS_LONGXS_SHORTre   XSr\   )r   r   r   r5   r   ffillre   rB   r2   r   r   ra   r/   rC   )rq   rH   rI   r   rr   r]   r^   r   r%   rn   ro   rm   rl   tskwargsrP   s                  r&   r   r     s2   N fF~fF f)Vu55f6V((_F NNAs8TN*
LLHdL3
MM!TM"qj  %FV $H
 
&	%H	%B 
BLL
Q%  6
		&"D	1 BGBKIr'   )TN)TTTN)NNNNNNNN)TTN)NNNN)TTNNN) 	functoolsr   numpyr   pandasr   r   pandas_ta._typingr   r   r	   pandas_ta.utils._mathr
   pandas_ta.utils._validater   r   r   r   r   r   __all__rk   r   r   r   r   r   r   r   r#   r   r    r'   r&   <module>r      sY     $ 5 5 & 
 =AYYY!%Y69YY: /3YYY'+YY Y@ =AZZZ!%Z69ZZ: /3ZZZ'+ZZ ZD '+&*IIII#I I !$I 	I
 I\ '+&**>*>*>*>#*> *> !$*>
 *>^ <@1526-1	MM#M08MM(.M M *0M 	M (+	M
 Md '+----#- - 	-d #'+/dddd%(d d #+d 	dX &*-1tt6t 	6t 	t #	t
 t
 (+t t #+t tr'   