improve long entry calculation

This commit is contained in:
2018-07-23 01:26:42 -07:00
parent a795e7552f
commit 648b14eda9
2 changed files with 43 additions and 10 deletions

View File

@ -123,17 +123,14 @@ insert into P2 select prev(1, low) as low, prev(1, time) as time
-- Long entry -- Long entry
-- --
create schema LongEntryStream as (low double) -- keep track of the highest OHLC high value from the most recent three
create window MaxHigh3Window#length(1) as (high double)
insert into LongEntryStream insert into MaxHigh3Window
select B1.low as low select max(high) as high from OHLCStream#length(3)
from B1#lastevent, B2#lastevent, P1#lastevent, P2#lastevent
where B1.low < B2.low
and P1.low < P2.low
and EPLHelpers.laterThan(B1.time, P1.time)
and EPLHelpers.laterThan(B2.time, P2.time)
and EPLHelpers.laterThan(P1.time, B2.time)
-- LE calc below is translated from:
--
-- LE = C > HHV(High,3) -- LE = C > HHV(High,3)
-- and B1 < B2 -- and B1 < B2
-- and P1 < P2 -- and P1 < P2
@ -141,11 +138,35 @@ insert into LongEntryStream
-- and BT2 > PT2 -- and BT2 > PT2
-- and PT1 > BT2 -- and PT1 > BT2
create schema LongEntryStream as (current BigDecimal, time org.joda.time.DateTime)
insert into LongEntryStream
select C.mid as current, C.time as time
from CurrentTickWindow as C,
MaxHigh3Window as T,
B1#lastevent, B2#lastevent,
P1#lastevent, P2#lastevent
where C.mid > T.high
and B1.low < B2.low
and P1.low < P2.low
and EPLHelpers.laterThan(B1.time, P1.time)
and EPLHelpers.laterThan(B2.time, P2.time)
and EPLHelpers.laterThan(P1.time, B2.time)
create schema LongEntryDistinct as (current BigDecimal, time org.joda.time.DateTime)
insert into LongEntryDistinct
select le.current as current, le.time as time
from pattern [every-distinct(le.time) le=LongEntryStream]
-- --
-- Event logging -- Event logging
-- --
-- TODO: look into LogSink http://esper.espertech.com/release-7.1.0/esper-reference/html/dataflow.html#dataflow-reference-logsink
create schema LogStream as (stream string, event string) create schema LogStream as (stream string, event string)
-- Enable logging specific stream events by uncommenting individual -- Enable logging specific stream events by uncommenting individual
@ -167,4 +188,8 @@ insert into LogStream select 'P1' as stream, EPLHelpers.str(*) as event from P1
insert into LogStream select 'P2' as stream, EPLHelpers.str(*) as event from P2 insert into LogStream select 'P2' as stream, EPLHelpers.str(*) as event from P2
insert into LogStream select 'LongEntryStream' as stream, EPLHelpers.str(*) as event from LongEntryStream -- insert into LogStream select 'MaxHigh3Window' as stream, EPLHelpers.str(*) as event from MaxHigh3Window
-- insert into LogStream select 'LongEntryStream' as stream, EPLHelpers.str(*) as event from LongEntryStream
-- insert into LogStream select 'LongEntryDistinct' as stream, EPLHelpers.str(*) as event from LongEntryDistinct

View File

@ -59,6 +59,14 @@ public class EsperProcessor implements TickProcessor {
// addLogStatement("LogStream"); // addLogStatement("LogStream");
addLogStreamHandler(); addLogStreamHandler();
// respond to long entry events
addStatement("select * from LongEntryDistinct",
(newData, oldData) -> {
log.debug("Long entry triggered: {} at {}",
newData[0].get("current"),
newData[0].get("time"));
});
} }
/** /**