From bf691207539f8de957a6cd85b08c2dd3d01547ea Mon Sep 17 00:00:00 2001 From: Seth Ladygo Date: Tue, 12 Feb 2019 10:12:29 -0800 Subject: [PATCH] trading_system_1.epl: deprecate use of CurrentTick --- epl/trading_system_1.epl | 65 +++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/epl/trading_system_1.epl b/epl/trading_system_1.epl index fc74e2b..0f720b0 100644 --- a/epl/trading_system_1.epl +++ b/epl/trading_system_1.epl @@ -41,11 +41,11 @@ create constant variable int RefSize = 5 -- Define the window as length 1, using the structure of the TickEvent -- java class to describe what the window contains. -create window CurrentTick#length(1) as TickEvent +-- create window CurrentTick#length(1) as TickEvent -- Describe how events get added to the window. This runs every time -- a new TickEvent is posted. -insert into CurrentTick select * from TickEvent +-- insert into CurrentTick select * from TickEvent -- @@ -226,7 +226,7 @@ create schema LongEntryStream as (current BigDecimal, time DateTime, instrument insert into LongEntryStream select C.mid as current, C.time as time, C.instrument as instrument - from CurrentTick as C, + from TickEvent#lastevent as C, MaxHigh3Window as T, B1#lastevent, B2#lastevent, P1#lastevent, P2#lastevent @@ -328,19 +328,56 @@ create schema LongExitStream -- or -- (LESBC>60 and C<(EntryPrice + 2 pips) -insert into LongExitStream - select C.mid as current, - C.time as time, - C.instrument as instrument, - 0 - TradeSize as units -- negative for "sell" - from CurrentTick as C, - LongEntryPreEntryBarPrevLow#lastevent as L - where ((LongEntryStopBarCount <= 60 and C.mid < min(L.low, LongEntryPrice - (10 * PipSize))) or - (LongEntryStopBarCount > 60 and C.mid < LongEntryPrice + (2 * PipSize))) - and InLongEntry +-- insert into LongExitStream +-- select C.mid as current, +-- C.time as time, +-- C.instrument as instrument, +-- 0 - TradeSize as units -- negative for "sell" +-- from CurrentTick as C +-- where LongEntryStopBarCount = 2 +-- and InLongEntry + + -- where ((LongEntryStopBarCount <= 60 and C.mid < min(L.low, LongEntryPrice - (10 * PipSize))) or + -- (LongEntryStopBarCount > 60 and C.mid < LongEntryPrice + (2 * PipSize))) -- Register the long position as closed -on LongExitStream as lx set InLongEntry = false +-- on LongExitStream as lx set InLongEntry = false + +-- Long exit event definition +create schema LongExitStream + as (id string) + +-- Send an event whenever we should close an order. +-- Received and acted upon in EsperProcessor. +on TickEvent as C +insert into LongExitStream + select ot.id as id + from OrderTable ot + where ot.stopBarCount > 1 and ot.open is true + and ot.id is not 'dummy' + + + +create schema OpenOrderStream + as (id string, + instrument String, + price BigDecimal, + units BigDecimal) + +-- Add an order to the order table. +-- OpenOrderStream events are sent from Java TradingManagers. +on OpenOrderStream as oos + insert into OrderTable(id, time, instrument, price, units, open, stopBarCount) + select oos.id, EPLHelpers.makeTime(current_timestamp()), oos.instrument, oos.price, oos.units, true, 0 + +create schema CloseOrderStream + as (id string) + +-- Add an order to the order table. +-- CloseOrderStream events are sent from Java TradingManagers. +on CloseOrderStream + update OrderTable + set OrderTable.open = false where OrderTable.id = CloseOrderStream.id --