I'm trying to implement a simplified version of the logic behind this strategy, but I'm having trouble. Below is the code I've written so far. The code is a mess, I know - I can't figure out the order in which to assign the variables because each line requires another variable.
The idea is to trace trends. We are in an uptrend until we cross below the open of the bar 4 bars before the latest high... whereupon we switch to a downtrend, and remain so for as long as we make lower lows from this point... until we cross back above the open 4 bars before the latest low... etc.
Anyone have any suggestions?
The idea is to trace trends. We are in an uptrend until we cross below the open of the bar 4 bars before the latest high... whereupon we switch to a downtrend, and remain so for as long as we make lower lows from this point... until we cross back above the open 4 bars before the latest low... etc.
Code:
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def firstBarOfDay = if (beforeStart[5] == 1 and beforeStart[4] == 0) or (isRollover[4] and beforeStart[4] == 0) then 1 else 0;
def hi = if firstBarOfDay then if close > open[4] then close else open[4] else
if dir[1] == -1 and close > brk or dir[1] == 11 and close > hi[1] then close else hi[1];
def lo = if firstBarOfDay then if close < open[4] then close else open[4] else
if dir[1] == 1 and close < brk or dir[1] == -1 and close < lo[1] then close else lo[1];
def dir = if firstBarOfDay then (if close < open[4] then -1 else if close > open[4] then 1 else 0) else
if close>brk then 1 else if close<brk then -1 else dir[1];
def inc = if firstBarOfDay then 4 else
if brk==brk[1] then inc[1]+1 else 4;
def brk = if firstBarOfDay then open[4] else
if close>hi[1] or close<lo[1] then open[4] else GetValue(close,inc);
Anyone have any suggestions?