Files
ATS_Esper/epl/test.epl

112 lines
2.9 KiB
Plaintext

-- test.epl - sample setup
--
-- Statements must be separated by an empty line.
-- The time the trading logic will begin to enter trades.
-- Exiting trades is 24/7.
create constant variable int StartTimeHour = 9
-- The time the trading logic will begin to enter trades.
-- Exiting trades is 24/7.
create constant variable int EndTimeHour = 17
-- The time frame or tickbar count of the data to be analyzed or
-- traded. Examples: 5s, 1m, 1h 30m, 2h, 12h, 1d.
create constant variable string Interval = '2s'
-- Amount to be traded, measured in units.
create constant variable int TradeSize = 100000
-- How many ticks to use for simple moving average calculation
create constant variable int SMASize = 5
-- How many ticks to store for Ref() access
create constant variable int RefSize = 5
--
-- Trading window
--
-- InTradingHours will be set to true when the current time is between
-- StartTime and EndTime.
create variable bool InTradingHours = false
-- Update on each tick
-- NOTE: see "timer:within" pattern for possible alternate formulation
on TickEvent as t set InTradingHours =
(EPLHelpers.getHour(t.time) >= StartTimeHour and
EPLHelpers.getHour(t.time) < EndTimeHour)
--
-- A stream of OHLC values calculated from TickEvents
--
create variant schema OneMinuteOHLCStream as OHLCEvent
insert into OneMinuteOHLCStream
select * from TickEvent#OHLC(Interval, time, midDouble)
--
-- Simple moving average streams
--
-- Average the most recent OHLC close values and create events that
-- contain open, high, low, close and SMA(close). The number of
-- OHLC events used in the SMA calc is set by SMASize.
create schema SMACloseStream as ats.plugin.OHLCValueEvent
insert into SMACloseStream
select new ats.plugin.OHLCValueEvent(time, open, high, low, close, Avg(close))
from OneMinuteOHLCStream#length(SMASize)
--
-- ValueWhen calculations
--
-- A stream that feeds B1 and B2
create schema BStream as (low double)
-- Find a bar with a lower close than its neighbors.
-- Add that low value to the stream.
insert into BStream
select prev(1, low) as low from SMACloseStream#length(RefSize)
where prev(0, value) > prev(1, value)
and prev(1, value) < prev(2, value)
create schema B1 (low double)
insert into B1 select prev(0, low) as low
from BStream#length(RefSize)
create schema B2 (low double)
insert into B2 select prev(1, low) as low
from BStream#length(RefSize)
-- A stream that feeds P1 and P2
create schema PStream as (low double)
-- Find a bar with a higher close than its neighbors.
-- Add that low value to the stream.
insert into PStream
select prev(1, low) as low from SMACloseStream#length(RefSize)
where prev(0, value) < prev(1, value)
and prev(1, value) > prev(2, value)
create schema P1 (low double)
insert into P1 select prev(0, low) as low
from PStream#length(RefSize)
create schema P2 (low double)
insert into P2 select prev(1, low) as low
from PStream#length(RefSize)