- ago
Hi, I'm developing a 1-min intraday strategy and added the piece of code below (from the Transaction class code examples) to better understand transactions created throughout its execution. The code places buy and sell orders using PlaceTrade() which are executed correctly since I can see them in the Chart. I also have a bunch of other WriteToDebugLog calls which are all working as expected. However, none of the transactions show at the very end of the debug output log... it prints both "***** BACKTEST COMPLETE *****" and "Transactions log:" which I added but then nothing else.

Does this only work for daily strategies and not intraday ones? Or is there a setting I need to change somewhere to make it work?

CODE:
      //write the Signals to the Debug Log       public override void BacktestComplete()       {          WriteToDebugLog("**** BACKTEST COMPLETE ****");          WriteToDebugLog("Transactions log:");          foreach (Transaction t in Backtester.Orders)          {             string s = String.Format("{0,-6}{1,6} {2,-6}{3,8}",                t.TransactionType, t.Quantity, t.Symbol, t.OrderType);             if (t.OrderType == OrderType.Limit || t.OrderType == OrderType.Stop)                s += (" @ " + t.OrderPriceDisplay);             WriteToDebugLog(s);          }       }


Thanks in advance!
0
198
Solved
5 Replies

Reply

Bookmark

Sort
Cone8
 ( 6.25% )
- ago
#1
Like you identified in the title, Backtester.Orders are the "Signals". If the strategy has no signals (orders for a future bar) this loop will be skipped.

In other words, "Signals not being written to the Debug log" is evidence that there are none.
0
- ago
#2
I see, that makes sense and I interpreted it incorrectly then. Thanks for the clarification, Cone!

I guess what I'm looking for then is a list of all trade executions after a 'PlaceTrade' call has been made. So perhaps instead of "Signals" is there a way to push all past executed "Transactions" to the debug log? Or a way to find not only open positions but also closed positions (which would be a confirmation that a place trade call to sell a long position has been executed)?

Thanks again!
0
- ago
#3
QUOTE:
is there a way to push all past executed "Transactions" to the debug log?

Are you saying you don't want to track Stop and Limit orders that never fill?

If so, then use the GetPositionsAllSymbols method to get a List<position> of positions that actually filled and print those stats as you did in your original post.

There's also a "Trade History Strategy" (see "New Strategy" menu) that allows you to import the Positions Visualizer tabulation with this same data. Have you considered that possibility?
0
Cone8
 ( 6.25% )
- ago
#4
For all trades, use GetPositionsAllSymbols() or GetPositionsAllSymbols(true) for NSF positions too.

CODE:
public override void BacktestComplete() {          foreach (Position p in GetPositionsAllSymbols())          {             // string interpolation is more convenient than string.Format             string s = $"{p.EntryDate:yyyy-MM-dd HH:mm}\t{p.EntryTransactionType,-6}{p.Quantity, 6} {p.Symbol, -6}{p.EntryOrderType, 8}";             if (p.EntryOrderType == OrderType.Limit || p.EntryOrderType == OrderType.Stop)                s += (" @ " + p.EntryPriceString);             WriteToDebugLog(s);          } }
0
Best Answer
- ago
#5
Thanks both for the quick reply and help, I appreciate it.

I will play with the GetPositionsAllSymbols() function, it seems that will meet what I'm looking for.

Have a great weekend!
0

Reply

Bookmark

Sort