My backtesting works as expected until I try to close my postions at the end of the day. I am using the east coast time template.
I am trying to close my positions at the end of the day for the close price. When I add the following code, the backtest will only take trades on the first day of the chart. None of the rest of the days show up. How do you close at the close price for the current day and keep processing the other days?
Thanks
nEOD = close(-1);
/*
if (hour(0) > hour(1)){
if (Strategy.isLong()){
Strategy.doSell("End of Day", Strategy.STOP, Strategy.THISBAR, Strategy.ALL,nEOD);
}
if (Strategy.isShort()){
Strategy.doCover("End of Day", Strategy.STOP, Strategy.THISBAR,Strategy.ALL, nEOD);
}
}
*/
if (day(0)!=day(1)) {
if (Strategy.isLong()){
Strategy.doSell("End of Day", Strategy.STOP, Strategy.THISBAR, Strategy.ALL,nEOD);
}
if (Strategy.isShort()){
Strategy.doCover("End of Day", Strategy.STOP, Strategy.THISBAR,Strategy.ALL, nEOD);
}
}
I am trying to close my positions at the end of the day for the close price. When I add the following code, the backtest will only take trades on the first day of the chart. None of the rest of the days show up. How do you close at the close price for the current day and keep processing the other days?
Thanks
nEOD = close(-1);
/*
if (hour(0) > hour(1)){
if (Strategy.isLong()){
Strategy.doSell("End of Day", Strategy.STOP, Strategy.THISBAR, Strategy.ALL,nEOD);
}
if (Strategy.isShort()){
Strategy.doCover("End of Day", Strategy.STOP, Strategy.THISBAR,Strategy.ALL, nEOD);
}
}
*/
if (day(0)!=day(1)) {
if (Strategy.isLong()){
Strategy.doSell("End of Day", Strategy.STOP, Strategy.THISBAR, Strategy.ALL,nEOD);
}
if (Strategy.isShort()){
Strategy.doCover("End of Day", Strategy.STOP, Strategy.THISBAR,Strategy.ALL, nEOD);
}
}
Comment