TrackRange object
Track range makes it easy to track information about the most recent number of formed 1 minute bars (i.e. last 20 formed bars). It doesn't include the forming bar.
TrackRange()
Creates the instance.
TrackRange( md, BarsBack, include_empty=False, include_extended=False, today_only=True)
Parameters:
Name | Type | Default | Information |
---|---|---|---|
md | object | required | ktg market data object |
BarsBack | integer | required | number of bars wanted in the range |
include_empty | boolean | False | include empty bars bar range calculation |
include_extended | boolean | False | include extended trading hours in calculation |
today_only | boolean | True | while the wording matches the bar interface, use False if you want to include more than just the current trading days bars in the range |
Attributes:
Name | Type | Default | Information |
---|---|---|---|
BreakAmount | float | 0.0 | break amount above (+) or below (-) the high/low in range. |
CurrentValue | float | 0.0 | the last trade value (md.Last) |
RangeHigh | float | 0.0 | high over the range |
RangeLow | float | 0.0 | low over the range |
MaxAboveRange | float | 0.0 | if the forming bar traded above the range, this would be the most it traded above the range. Positive number. |
MaxBelowRange | float | 0.0 | if the forming bar traded below the range, this would be the most it traded below the range. Negative number. |
Range | float | 0.0 | range between high and low of the range. |
Methods:
Calculate()
Call to update the instance variables. Call method for checking instance variables.
Calculate( md )
Name | Type | Default | Information |
---|---|---|---|
md | object | required | market data object |
Working Example:
Create an instance of TrackRange() for the past 20 minutes. At the beginning of on_trade(), Calculate() is called to update the instance variable.
from cloudquant.interfaces import Strategy, Event
from ktgfunc import TrackRange
class TrackRangeExample(Strategy):
@classmethod
def is_symbol_qualified(cls, symbol, md, service, account):
return symbol == 'TQQQ'
def on_start(self, md, order, service, account):
print 'Test date:\t%s' % service.time_to_string(service.system_time, '%Y-%m-%d')
self.test = TrackRange(md, 20)
print '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s' % ('time', 'rvol', 'r_high', 'r_low', 'range', 'mx_high', 'mn_low', 'break amount')
def on_trade(self, event, md, order, service, account):
self.test.Calculate(md)
if self.test.MaxAboveRange != 0 or self.test.MaxBelowRange != 0 or self.test.BreakAmount != 0:
print '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s' % ( service.time_to_string(service.system_time), md.L1.rvol, self.test.RangeHigh, self.test.RangeLow, self.test.Range, self.test.MaxAboveRange, self.test.MaxBelowRange, self.test.BreakAmount )
Console
Test date: 2016-06-15 time rvol r_high r_low range mx_high mn_low break amount 2016-06-15 10:06:31.126000 1.07127594948 98.8300018311 98.3199996948 0.51000213623 0.00999450683594 0.0 0.00999450683594 2016-06-15 10:06:31.785000 1.07153558731 98.8300018311 98.3199996948 0.51000213623 0.0279006958008 0.0 0.0279006958008 2016-06-15 10:06:33.917000 1.07160043716 98.8300018311 98.3199996948 0.51000213623 0.0279006958008 0.0 0.000198364257812 2016-06-15 10:06:39.544000 1.071860075 98.8300018311 98.3199996948 0.51000213623 0.0279006958008 0.0 0.0 2016-06-15 10:06:52.566000 1.07211971283 98.8300018311 98.3199996948 0.51000213623 0.0279006958008 0.0 0.0 2016-06-15 10:06:52.594000 1.07471585274 98.8300018311 98.3199996948 0.51000213623 0.0279006958008 0.0 0.0 2016-06-15 10:06:59.902000 1.07497549057 98.8300018311 98.3199996948 0.51000213623 0.0279006958008 0.0 0.0