- ago
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 {       TimeSeries spy; //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          if (bars.Scale == HistoryScale.Minute1)          {             spy = TimeSeriesCompressor.ToMinute(bars.Close, 5, bars.Market);             DrawHeaderText("Last Value before sync: " + spy[spy.Count-1]);             DrawHeaderText("Value Before last value before sync: " + spy[spy.Count-2]);             spy = TimeSeriesSynchronizer.Synchronize(spy, bars);             DrawHeaderText("Last Value After sync: " + spy[spy.Count-1]);             PlotTimeSeries(spy, "SPY", "Price", WLColor.Red);          } } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { } //declare private variables below } }


Using SPY and 1-minute interval.
Please run in streaming charts the code and look at the values of last bar. I expected the partial 5-minute bar to not have updated value. But completed 5-minutes last bar should have last compressed value.
I think last bar sync is not calculated correctly.
0
238
Solved
5 Replies

Reply

Bookmark

Sort
Glitch8
 ( 11.81% )
- ago
#1
It looks fine to me.

Here the last value after compressing the 1 minute data to 5 minute is 449.84, which is correct. The last 1 minute bar of the chart closes at 449.75 but it would have been part of the partial 5 minute bar so it's not included.

After synchronizing the 5 minute bars back to 1 minute the last value is still 449.84, which is still correct.

I'm not sure why you're printing the second to last value, I don't think it's relevant here.

What exactly would you expect to see in this case?

0
- ago
#2
I am printing the value before last to show that is duplicated on minute 5. Please look at it exactly at minute 5 (when bar % 5 == 0). example 11:30.

Must try in streaming since it corrects itself after 1-minute.
I added more code to demonstrate it. If you run the code under streaming chart, you will notice it generates a lot of trades, but will not generate any signals since the cross is realized after one minute from the trade instead on time at 5-minute intervals.
I might be doing something else wrong.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript4 {    public class MyStrategy : UserStrategyBase {       TimeSeries spy;       TimeSeries emaFast, emaSlow, twoEmas; //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          if (bars.Scale == HistoryScale.Minute1)          {             spy = TimeSeriesCompressor.ToMinute(bars.Close, 5, bars.Market);             DrawHeaderText("Last Value before sync: " + spy[spy.Count-1], WLColor.Green, 20);             DrawHeaderText("Value Before last value before sync: " + spy[spy.Count-2],WLColor.Black, 20);             PlotTimeSeries(spy, "SPY", "Price", WLColor.Red);             emaFast = new EMA(spy, 3);             emaSlow = new EMA(spy, 6);             twoEmas = 100 * (emaFast - emaSlow) / emaSlow;                          twoEmas = TimeSeriesSynchronizer.Synchronize(twoEmas, bars);             spy = TimeSeriesSynchronizer.Synchronize(spy, bars);             DrawHeaderText("Last Value After sync: " + spy[spy.Count -1], WLColor.Red, 20);             PlotTimeSeriesOscillator(twoEmas, "macd", "macd", 0, 0, WLColor.FromRgb(33, 33, 41), WLColor.FromRgb(41, 47, 187), WLColor.FromRgb(12, 243, 55)); StartIndex = 100;          } } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int bar) {          bool crossUnder = twoEmas.CrossesUnder(0, bar);          bool crossOver = twoEmas.CrossesOver(0, bar);          if (crossOver && LastOpenPosition == null )          {             PlaceTrade(bars, TransactionType.Buy, OrderType.Market);          }          if(crossUnder && LastOpenPosition != null)          {             PlaceTrade(bars, TransactionType.Sell, OrderType.Market);          }     } //declare private variables below } }

0
Cone8
 ( 25.44% )
- ago
#3
I see what you mean and duplicated it.

Here's the summary of the problem.
1. the "Last Value" before sync (compressed bars) is always correct.

2. However, after synchronization and on the sync bar only, the Last Value of the *de-compressed* series returns the previous compressed value.

3. On the *following* bar, all values are correct.
0
- ago
#4
Correct.
The workaround until fixed:
CODE:
if (bars.Scale == HistoryScale.Minute1) { double lastValue = spy[^1]; spy = TimeSeriesSynchronizer.Synchronize(spy, bars); if (bars.DateTimes[^1].Minute % 5 == 0) { spy[^1] = lastValue; } }
0
Glitch8
 ( 11.81% )
- ago
#5
We have it fixed for the next release, Build 61.
0
Best Answer

Reply

Bookmark

Sort