I was running the Opening Range Breakout sample strategy today on TDA live 1 minute bars and I was expecting it to close my positions on the last bar of the day and no orders were generated on the last bar, is this code not intended to close any position at the last bar?
CODE:
Position p = LastPosition; var dt = bars.DateTimes[idx].Date; // Exit last bar of day if ((idx == lastChartBar) && (dt.GetTime() >= nextToLastBarTime)) { SetBarColor(bars, idx, WLColor.Orange); ClosePosition(p, OrderType.Market, 0, "Exit at open of last bar"); } else if ((idx != lastChartBar) && bars.IsLastBarOfDay(idx + 1)) { SetBarColor(bars, idx, WLColor.Orange); ClosePosition(p, OrderType.Market, 0, "Exit at open of last bar"); }
Rename
QUOTE:
is this code not intended to close any position at the last bar?
It's intended to close the position at the last bar and it does so in my backtesting.
Ya it does work when backtesting but did not generate any orders when running it live and I was wondering what could possibly be the reason?
Maybe your strategy didn't have any open positions?
It had several open positions. I can paste all my orders in here and positions for the day from my broker but I don’t know how helpful that would be. I’ll run it again tomorrow and see if it creates a closing position at 3:59.
Where's your code for lastChartBar and nextToLastBarTime?
@Cone
It's straight in the Sample Strategies folder, "Opening Range Breakout" - a canned strategy.
It's straight in the Sample Strategies folder, "Opening Range Breakout" - a canned strategy.
Your Response
Post
Edit Post
Login is required