- ago
I've been running a strategy in the Strategy monitor since Dec. 27th, at 5-minute scale with "Polling" update mode. The strategy placed Market Buys on Dec. 27th and Dec. 28th, but there has been no activity since then. My strategy has a "Sell after 400 bars" design block, so there should have been a market sell by now. How can I further troubleshoot this?

When I run a backtest with the strategy now, I do see market sells that should have taken place in the backtest. My strategy design block looks like this:

[Buy at Market] ...condition...
[Sell after 400 bars]
[Sell at Market] ...condition...
[Sell at Market] ...condition...

0
829
Solved
19 Replies

Reply

Bookmark

Sort
Glitch8
 ( 11.29% )
- ago
#1
How much data have you configured to load in the Strategy monitor?
0
- ago
#2
Is there a way to check without stopping the strategy? I believe I either left it at the default 500 bars, or perhaps increased it to 5000 bars when I originally configured the strategies on Dec. 27th.

None of the design blocks associated with the strategies use more than 400 bars, so I assume the default 500 bars would be sufficient here.
0
- ago
#3
QUOTE:
Is there a way to check without stopping the strategy?

Not really, even if the SM is saved in a Workspace the settings file is not human readable.
1
- ago
#4
Alright, I went ahead and stopped the strategy and confirmed that it was set for the default of 500 bars.
0
- ago
#5
Looks like there's nothing to sell: the Accounts window is empty?
0
Glitch8
 ( 11.29% )
- ago
#6
Eugene, lack of an account position won't prevent the backtester from issuing a sell signals for a theoretical position.
0
Glitch8
 ( 11.29% )
- ago
#7
Depending on the parameters of your indicators it’s possible that the simulated buy signal that generated the backtest position did not have enough data at 500 bars, I would try increasing to 1.000.
1
- ago
#8
Thanks, I will restart the strategy with a larger amount of bars and see if it makes any difference.

This is more or less what the strategy looks like, do you see any reasons that ATRTrail might need more than 500 bars?

0
Glitch8
 ( 11.29% )
- ago
#9
Yes, it’s using a period of 123 bars so after the strategy runs for a while your buy signal is likely dropping off the left end.
1
- ago
#10
Huh, it's possible I'm fundamentally misunderstanding how things work behind the scenes. Are you essentially saying that the when the "Strategy Settings" are configured for the Strategy Monitor, the number of bars in the "Date Range" needs to be calculated like this?

CODE:
[Max possible bars for Buy Blocks] + [Max possible bars for Sell Blocks] = [Min allowable bars for "Data Range"]

So in my above example, I would need to use at least 523 bars for "Data Range"?
0
Glitch8
 ( 11.29% )
- ago
#11
No, but each time the strategy runs it will use a new 500 bars of data. so if there was a buy that occurred at bar number 10, than after 10 runs that bar will no longer be present so that buy will not exist, and thus no corresponding exit.

You could also avoid this by using a fixed date range, with an end date set to some point in the future.
2
Best Answer
- ago
#12
Thanks for your help, I really appreciate it. I will give it a try and see how it goes!
0
- ago
#13
Note that ATR and its descendants are "unstable" progressively calculated indicators so if the seed period wasn't enough, they can change the readings in the beginning with all that it implies. At least 492 bars are required for a 123-period ATR-like indicator to stabilize its value.

We will have a dedicated Help chapter explaining this in B44:

https://www.wealth-lab.com/Discussion/Backtest-ending-date-is-the-same-signals-processed-yesterday-are-missing-7420
1
- ago
#14
I'm revisiting this discussion from a year ago, since I just encountered some strange behavior from "Sell after N bars" that I don't understand. I have a 1-minute strategy running, with one of the exit conditions being "Sell after 131 bars".

In the below image, you can see that the strategy entered into a position for ASM-USD at 20:03. At 23:40, I realized the position had not been exited, and I thought perhaps I had made the mistake described by Glitch above, where the bar "falls off". So I manually exited the position.



Then you'll notice at 08:14 on the next day, the strategy submitted a Sell order - over 10 hours after entering the position. So I have 2 questions:

1) If the entrance bar had "fallen off", would the strategy still generate an Exit like this? (potentially from one of the other Exit conditions?)
2) My strategy is not using ATR (as referenced by Eugene above), so is there any reason that the "Sell after N bars" would not trigger if the strategy is configured to use a bar history > 131 bars?
0
Glitch8
 ( 11.29% )
- ago
#15
ASMUSD is very illiquid, so it must have not been until 8:14 the next day that your 131 bars were obtained.

0
- ago
#16
This must be a misunderstanding on my part, then. I assumed that "Sell after 131" bars would mean that no position is held longer than 131 minutes. Is it actually longer, because of 0 volume bars being omitted?

My fear is that this might introduce a difference in behavior between backtesting and the execution of a live strategy. If the backtest data is including 0-volume bars, but the live strategy is omitting them, then they would end up executing "Sell after N bars" at different times.
0
Glitch8
 ( 11.29% )
- ago
#17
A bar is a bar, not a time unit. If the chart has gaps then 131 bars <> 131 minutes.
1
- ago
#18
Thanks for the clarification. Is there currently a way in WL8 that I could create a strategy that sells after 131 minutes? (assuming it's running at 1-minute scale)
0
Glitch8
 ( 11.29% )
- ago
#19
Here's a minimal example of how to do that.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          rsi14 = RSI.Series(bars.Close, 14);          PlotIndicator(rsi14); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { if (rsi14[idx] < 40)                PlaceTrade(bars, TransactionType.Buy, OrderType.Market); } else {             //code your sell conditions here             Position pos = LastOpenPosition;             DateTime exit = pos.EntryDate.AddMinutes(131);             if (bars.DateTimes[idx] >= exit)                PlaceTrade(bars, TransactionType.Sell, OrderType.Market); } }       //declare private variables below       private RSI rsi14; } }
1

Reply

Bookmark

Sort