Skip to content

trading.indicators.state.vwap_state

trading.indicators.state.vwap_state

VWAPState

Bases: Enum

The current price location relative to VWAP.

Attributes:

Name Type Description
BELOW_LOWER

The price is below the lower band.

BETWEEN_LOWER_AND_MIDDLE

The price is between the lower & VWAP band.

ABOVE_MIDDLE

The price is above the VWAP band.

get_state classmethod

get_state(price: float, snapshot: VWAPSnapshot) -> VWAPState

Returns the zone of the price relative to the VWAP bands.

Parameters:

Name Type Description Default
price float

The close price for the current bar.

required
snapshot VWAPSnapshot

The VWAP snapshot for the current bar.

required

Returns:

Name Type Description
VWAPState VWAPState

The price relative to the VWAP snapshot.

Source code in src\contango\trading\indicators\state\vwap_state.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@classmethod
def get_state(cls, price: float, snapshot: VWAPSnapshot) -> VWAPState:
    """
    Returns the zone of the price relative to the VWAP bands.

    Args:
        price: The close price for the current bar.
        snapshot: The VWAP snapshot for the current bar.

    Returns:
        VWAPState: The price relative to the VWAP snapshot.
    """
    if price < snapshot.lower:
        return VWAPState.BELOW_LOWER
    if price < snapshot.vwap:
        return VWAPState.BETWEEN_LOWER_AND_VWAP
    return VWAPState.ABOVE_VWAP