I did not find the ability to see the history of trades, and this can be very useful. At least in some basic form, so that it would not be necessary to get into the broker interface, which is not always convenient.
Rename
As mentioned on the forum days ago by @Glitch, Broker APIs usually do not return a history of trades.
If it's useful for you, what if you export it from Positions tab and import the trade history from file using New strategy > "Trade history strategy"?
If it's useful for you, what if you export it from Positions tab and import the trade history from file using New strategy > "Trade history strategy"?
I think what ww5 is asking is that we cache the live trade fills to disk file. Pretty reasonable idea. In WL6 we did it.
But it's true that about the Trade History backtests. If you have an account with IB, TDA, or similar, you can export the broker trades, point the Trade History backtest to the trade file.
But it's true that about the Trade History backtests. If you have an account with IB, TDA, or similar, you can export the broker trades, point the Trade History backtest to the trade file.
Cone, right, that's what I mean. Save the trades made instead of getting the whole history from the broker.
Maybe until this saving functionality is implemented, there is some hack to catch position closures from the C# code? Broker reports are good if it is a test of 1 strategy, but when there are several of them they are of no use
From a strategy perspective, you could query an account's positions at the end of a bar. You could discover and save changes in symbol's quantity, for example, but not necessarily a fill price.
For example, if at 10:05 you had 100 AAPL, and you found that there was "no AAPL" at 10:15, you only know that the position was exited, but can't tell the price at which it was sold... though you could reasonably assume that it occurred at (or near) the open for a market order, or at the limit price for a limit order.
For example, if at 10:05 you had 100 AAPL, and you found that there was "no AAPL" at 10:15, you only know that the position was exited, but can't tell the price at which it was sold... though you could reasonably assume that it occurred at (or near) the open for a market order, or at the limit price for a limit order.
I like that. Simplifies things for the user. Thumbs up.
I have tried to save information about open trades in AssignAutoStopTargetPrices. Simply I've added "File.AppendAllText(...)" in this function and and it led me to an incomprehensible result. In this file, every time I run the strategy, I get information on all possible trades that could have been in the last 1000 bars, as indicated in my strategy monitor. Although the expected result is that the file will record trades only on real signals.
Also, it turns out I need somehow to know whether the strategy is launched from the strategy monitor or in the backtest, so as not to save the information from the backtest in vain.
Also, it turns out I need somehow to know whether the strategy is launched from the strategy monitor or in the backtest, so as not to save the information from the backtest in vain.
No problem, use code like this:
CODE:
if (Backtester.ExecutionMode == StrategyExecutionMode.Strategy) { }
StrategyExecutionMode.StrategyMonitor helped to get signals only when running in Strategy Monitor, however I still can't understand why the strategy is executed like it was in a backtest.
For example such a strategy
For example such a strategy
CODE:on a 50 symbols dataset and one-time launch via run now gives a file with 151 entries.
using WealthLab.Backtest; using System; using WealthLab.Core; using System.IO; namespace WealthScript12 { public class MyStrategy : UserStrategyBase { public override void Initialize(BarHistory bars){ } public override void Execute(BarHistory bars, int idx) { Position foundPosition0 = FindOpenPosition(0); if (foundPosition0 == null) { PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0, "Buy At Market (1)"); } else { ClosePosition(foundPosition0, OrderType.Limit, foundPosition0.EntryPrice * ((10.00 / 100.0) + 1.0), "Sell at 10% profit target"); ClosePosition(foundPosition0, OrderType.Stop, foundPosition0.EntryPrice * (1.0 - (10.00 / 100.0)), "Sell at 10% stop loss"); } } public override void AssignAutoStopTargetPrices(Transaction t, double basisPrice, double executionPrice) { if (Backtester.ExecutionMode == StrategyExecutionMode.StrategyMonitor) File.AppendAllText(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\trades.txt", t.Symbol + " " + t.ExecutionDate.ToShortDateTimeString() + " " + t.PositionType.ToString() + Environment.NewLine); } } }
You might be misunderstanding how the strategy monitor works. It runs a backtest just like the strategy window, with some optimizations like not processing cosmetic chart methods.
Yeah, I thought it only processes the last bar. How can I change this strategy to record only actual trades in the present time?
This should work, but keep in mind that this method is used for Entries only.
CODE:
public override void AssignAutoStopTargetPrices(Transaction t, double basisPrice, double executionPrice) { if (Backtester.ExecutionMode == StrategyExecutionMode.StrategyMonitor) if (t.EntryDate == t.Bars.DateTimes[t.Bars.Count - 1]) File.AppendAllText(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\trades.txt", t.Symbol + " " + t.ExecutionDate.ToShortDateTimeString() + " " + t.PositionType.ToString() + Environment.NewLine); }
CODE:returns 01/01/0001 00:00 while live in strategy monitor. What can I replace it with?
t.ExecutionDate.ToShortDateTimeString()
Try replacing it with Backtester.CurrentDate.
Your Response
Post
Edit Post
Login is required