defparam flatbefore=080000
defparam flatafter=220000
// --- Inputs
emaLen = 9
tpPts = 20
slPts = 20
LunchTime = opentime >= 120000 AND opentime < 140000
// =======================
// --- EMA
// =======================
ema = average[emaLen,1](close)
// =======================
// D calculation
// =======================
IF Close > ( MAX(MAX(high, high[1]), MAX(high[1], high[1]) ))[1] THEN
D = MIN(MIN(low, low[1]), MIN(low[1], low[1]))
ELSIF Close < ( MIN(MIN(low, low[1]), MIN(low[1], low[1])) )[1] THEN
D = MAX(MAX(high, high[1]), MAX(high[1], high[1]))
ELSE
D = D[1]
ENDIF
// =======================
// Setup Long
// =======================
IF NOT LongOnMarket AND not LunchTime AND close > ema AND close CROSSES OVER D THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// =======================
// Setup Short
// =======================
IF NOT ShortOnMarket AND not LunchTime AND close < ema AND close CROSSES UNDER D THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// =======================
// Set Target and Stop Loss
// =======================
SET TARGET pPROFIT tpPts
SET STOP pLOSS slPts
// =======================
// Plot on Price
// =======================
GraphOnPrice D as "Signal" coloured("fuchsia")
GraphOnPrice ema AS "EMA" coloured("blue")