Candle

Class used to represent a Candle (from a clandlesticks graph). This class is used in list of candles of estrade.candle_set.CandleSet instances.

A candle holds a list of ticks happening between the time/nb defined in CandleSet.

Parameters

Name Type Description Default
timeframe str candle timeframe required
epic_ref str reference of epic required
open_tick Tick first tick of candle required
open_at datetime date where the candle was opened None
meta Dict[str, Any] free of use dictionnary None

Note

The open_at can be different from the open_tick datetime, for example in a 5minutes timeframe, if the first tick has a time of 12:06:03, then the open_at should be 12:05:00.

body: float (property, readonly)

Returns

Type Description
float the absolute difference between open and close of the candle
        |
        |
        ┴  ┐
       | | |
       | | |<-- body
       | | |
        ┬  ┘
        |
        |

close: Union[estrade.tick.Tick, NoneType] (property, readonly)

Returns

Type Description
Union[estrade.tick.Tick, NoneType] When candle is closed, this method send the last tick of candle

color: str (property, readonly)

Returns

Type Description
str This method return the "color" of the candle.
  • if open < close: returns green
  • elif open > close: returns red
  • else (open == close): returns black (doji)

head: float (property, readonly)

Returns

Type Description
float distance between the highest value and the highest from (open/last)
        |  ┐
        |  | <-- head
        ┴  ┘
       | |
       | |
       | |
        ┬
        |
        |

height: float (property, readonly)

Returns

Type Description
float Height of candle (high - low)
        |  ┐
        |  |
        ┴  |
       | | |
       | | |<-- height
       | | |
        ┬  |
        |  |
        |  ┘

high: Tick (property, readonly)

Returns

Type Description
Tick The highest tick in candle

last: Tick (property, readonly)

Returns

Type Description
Tick The last tick of candle

last_tick: Tick (property, readonly)

Returns

Type Description
Tick The last tick in candle

low: Union[estrade.tick.Tick, NoneType] (property, readonly)

Returns

Type Description
Union[estrade.tick.Tick, NoneType] The tick with the lowest value of candle

open: Tick (property, readonly)

Returns

Type Description
Tick The first tick of candle

open_tick: Tick (property, readonly)

Returns

Type Description
Tick The fist tick of candle

tail: float (property, readonly)

Returns

Type Description
float distance between the lowest value and the lowest from (open/last)
        |
        |
        ┴
       | |
       | |
       | |
        ┬  ┐
        |  | <-- tail
        |  ┘

close_candle(self)

Show source code in estrade/candle.py
241
242
243
244
245
246
247
248
249
250
251
    def close_candle(self) -> None:
        """
        This method set the candle as closed.

        A candle is closed when :

         - the max number of tick in candle is reached (max number defined in "parent"
         CandleSet)
         - the candle time range is reached (time ranched defined in "parent" CandleSet)
        """
        self.closed = True

This method set the candle as closed.

A candle is closed when :

  • the max number of tick in candle is reached (max number defined in "parent" CandleSet)
  • the candle time range is reached (time ranched defined in "parent" CandleSet)

on_new_tick(self, tick)

Show source code in estrade/candle.py
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
    def on_new_tick(self, tick: Tick) -> None:
        """
        This method append a new tick to the candle.ticks and update candle low/high.

        Arguments:
            tick: tick to add to candle
        """
        if not isinstance(tick, Tick):
            raise CandleException('Can only add Tick objects to candle')

        self.ticks.append(tick)

        if not self.low_tick or tick.value < self.low_tick.value:
            self.low_tick = tick
        if not self.high_tick or tick.value > self.high_tick.value:
            self.high_tick = tick

This method append a new tick to the candle.ticks and update candle low/high.

Parameters

Name Type Description Default
tick Tick tick to add to candle required