How can I fix this code to buy if first 5 minute or x minute candle of the day closes higher than yesterdays daily close, and short if the opposite?
Here is what i have. It kinda works, but something is too processor intensive and the floating profit and loss in Ondemand fails to calculate anything about 50% of the time. I am using a 5 minute chart.
Here is what i have. It kinda works, but something is too processor intensive and the floating profit and loss in Ondemand fails to calculate anything about 50% of the time. I am using a 5 minute chart.
Rich (BB code):
#simply buys if first candle is higher than last day close, or shorts if lower than last close, close all eod
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD());
def firstBar = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
def yesterdayclose = close(period = AggregationPeriod.DAY)[1];
def golong = close >= yesterdayclose;
def isopen=if secondsFromTime(0930)>=0 and secondstillTime(1600)>=0 then 1 else 0;
plot closedaily = close(period = AggregationPeriod.DAY)[1];
AddOrder(OrderType.BUY_to_OPEN, isopen and golong and firstbar, name = "long gap up", tickcolor = GetColor(0), arrowcolor = GetColor(0));
AddOrder(OrderType.sell_to_open, isopen and !golong and firstbar, name = "short gap down", tickcolor = GetColor(1), arrowcolor = GetColor(1));
input barsFromEnd = 1;
def EOD = RegularTradingEnd(GetYYYYMMDD()) - GetTime() <= GetAggregationPeriod() * barsFromEnd - 1;
#mod note: changed to: open[-1] previous code was set up to repaint & give false results.
AddOrder(OrderType.SELL_TO_CLOSE, EOD[-1], open[-1], 0, Color.ORANGE, Color.ORANGE, "EOD LX");
AddOrder(OrderType.BUY_TO_CLOSE, EOD[-1], open[-1], 0, Color.ORANGE, Color.ORANGE, "EOD SX");
Last edited by a moderator: