Custom VWAP - usage example of Schedule class


Hidden Redirect Link
Loading...

We recently released an update to Indie Language 4.4, which now includes new types for managing time periods: indie.schedule.ScheduleRule, indie.schedule.Schedule and indie.TradingSession.

The “Custom VWAP” indicator demonstrates the usage of the Schedule class. If we don’t want to reset VWAP at the start of each new default trading day (using the ‘Session’ option of anchor parameter), we can create a custom schedule to define the reset time. For example, by default, the VWAP reset time for ‘BTC/USDT’ is at 00:00 UTC. However, we want to change this reset time to 00:00 in our chosen timezone ('America/New_York' in this indicator).

Key points:

  • We define the custom schedule in the __init__ function because creating it on each bar in the calc function is resource-inefficient. Alternatively, we could use the pre_calc function for schedule definition if we need to access data from self.info or self.trading_session.
  • We use is_same_period method (for both Schedule and Session options) to detect whether two timestamps belong to the same schedule period or fall on different days.
© Licensed under MIT

Comments

loading