Replace OHLCValueEvent

This commit is contained in:
2018-11-14 20:53:09 -08:00
parent 92c3636d8f
commit 8cf12a27fb
3 changed files with 14 additions and 57 deletions

View File

@ -108,18 +108,21 @@ insert into TBHKStream
-- Simple moving average streams
--
-- SMACloseStream contains OHLCValueEvents. These are like
-- OHLCEvents, but add an extra field for an arbitrary value. In this
-- stream, that extra value will contain the average of OHLC close
-- values.
create schema SMACloseStream as ats.plugin.OHLCValueEvent
-- SMACloseStream bundles a simple moving average of the close values
-- with the values of the OHLCStream.
create schema SMACloseStream as (time DateTime,
open double,
high double,
low double,
close double,
averageClose double)
-- Average the most recent OHLC close values from OHLCStream and
-- post an event that contains open, high, low, close, and
-- SMA(close). The number of OHLC events used in the SMA calc is set
-- by the SMASize variable.
insert into SMACloseStream
select new ats.plugin.OHLCValueEvent(time, open, high, low, close, Avg(close))
select time, open, high, low, close, Avg(close) as averageClose
from OHLCStream#length(SMASize)
@ -134,13 +137,11 @@ create schema BStream as (low double, time DateTime)
-- Listen to the last "RefSize" number of SMACloseStream events. Look
-- for an OHLC bar with a lower average close than its neighbors. Add
-- that bar's low value and its timestamp to the stream. As described
-- in SMACloseStream, "value" in the query below represents
-- SMA(close).
-- that bar's low value and its timestamp to the stream.
insert into BStream
select prev(1, low) as low, prev(1, time) as time from SMACloseStream#length(RefSize)
where prev(0, value) > prev(1, value)
and prev(1, value) < prev(2, value)
where prev(0, averageClose) > prev(1, averageClose)
and prev(1, averageClose) < prev(2, averageClose)
-- Define B1 to contain the same fields as BStream
@ -168,8 +169,8 @@ create schema PStream as (low double, time DateTime)
-- Add that low value and its timestamp to the stream.
insert into PStream
select prev(1, low) as low, prev(1, time) as time from SMACloseStream#length(RefSize)
where prev(0, value) < prev(1, value)
and prev(1, value) > prev(2, value)
where prev(0, averageClose) < prev(1, averageClose)
and prev(1, averageClose) > prev(2, averageClose)
-- P1 contains the most recent low value and time from PStream.
-- This is the last time an average close was higher