Add LE derived values
This commit is contained in:
@ -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
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user