From 7680ed81a278ab1b8ba2059f98c70f820b3db07b Mon Sep 17 00:00:00 2001 From: Seth Ladygo Date: Wed, 14 Nov 2018 21:08:36 -0800 Subject: [PATCH] Add LE derived values --- epl/trading_system_1.epl | 51 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/epl/trading_system_1.epl b/epl/trading_system_1.epl index d455a3d..f64aa54 100644 --- a/epl/trading_system_1.epl +++ b/epl/trading_system_1.epl @@ -244,8 +244,11 @@ insert into LongEntryStream -- -- LongEntryDistinct filters out duplicate LongEntryStream events, -- leaving a maximum of one event per tick. -create schema LongEntryDistinct as (current BigDecimal, time DateTime, - instrument String, units int) +create schema LongEntryDistinct + as (current BigDecimal, + time DateTime, + instrument String, + units int) insert into LongEntryDistinct select le.current as current, le.time as time, @@ -254,13 +257,55 @@ insert into LongEntryDistinct -- --- Long entry derived variables +-- Long entry derived values -- -- Register if We're in a long entry when we get the LongEntryDistinct -- event. (InLongEntry is declared near top of file) on LongEntryDistinct as le set InLongEntry = true +-- LongEntryTime contains the timestamp of the last long entry, +-- or null if none has happened yet. +create variable DateTime LongEntryTime = null + +on LongEntryDistinct as le set LongEntryTime = le.time + +-- LongEntryStopBarCount contains the number of OHLCStream bars that +-- have occurred since the most recent long entry. +create variable int LongEntryStopBarCount = 0 + +-- Reset LongEntryStopBarCount when we get a new LE. +on LongEntryDistinct as le set LongEntryStopBarCount = 0 + +-- Increment LongEntryStopBarCount on every bar. +on OHLCStream as ohlc set LongEntryStopBarCount = LongEntryStopBarCount + 1 + +-- LongEntryPrice contains the price of the last long entry, +-- or null if none has happened yet. +create variable BigDecimal LongEntryPrice = null + +on LongEntryDistinct as le set LongEntryPrice = le.current + +-- LongEntryPreEntryBar is a stream that keeps bars just prior to the +-- last long entry +create schema LongEntryPreEntryBar + as (time DateTime, + open double, + high double, + low double, + close double) + +-- Add bars so long as we're not in a long position +insert into LongEntryPreEntryBar + select time, open, high, low, close from OHLCStream + where InLongEntry is false + +-- Contains the second-most-recent LongEntryPreEntryBar's "low" value +create schema LongEntryPreEntryBarPrevLow (low double) + +insert into LongEntryPreEntryBarPrevLow select prev(1, low) as low + from LongEntryPreEntryBar#length(2) + -- -- Event logging --