- ago
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");             }
0
596
6 Replies

Reply

Bookmark

Sort
- ago
#1
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.
0
- ago
#2
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?
0
- ago
#3
Maybe your strategy didn't have any open positions?
0
- ago
#4
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.
0
Cone8
 ( 24.57% )
- ago
#5
Where's your code for lastChartBar and nextToLastBarTime?
0
- ago
#6
@Cone
It's straight in the Sample Strategies folder, "Opening Range Breakout" - a canned strategy.
0

Reply

Bookmark

Sort