- ago
I kept running into a problem when backtesting where sometimes the chart would show just one bar. I finally figured out that it has to do with date range changes.

Initial Settings:
Dataset using symbols CLSK and MARA
Obtain data from selected DataSet only checked
Data Range: Most Recent N Days
Number of days: 10
Filter Pre/Post Market data - unchecked
Benchmark: CLSK

Position sizing...
Starting capital: 100000
Position size: Shares/Contracts
Shares: 1000
Margin Factor: 2.00
Rest are defaults

Run the following strategy with the above settings. Trades will be produced at bar 100 when there are more than 2000 bars to use.

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) { } //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)) {             //code your buy conditions here             if (bars.Count > 2000 && idx == 100)             {                PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, "Buy");             } } else {             //code your sell conditions here             var position = FindOpenPosition(-1);             if (position != null && idx == position.EntryBar + 5)             {                ClosePosition(position, OrderType.Market, 0, "Sell");             } } } //declare private variables below } }


As expected, the strategy produces two positions (one for each symbol).
Go to the backtest resujlts and then the positions tab and double-click a position. The chart shows up with the position - no problem.

Next, do the following on the Strategy Settings tab: change only the number of days to 2.
Run the strategy.
No positions are produced as expected.
Go to the chart. There is one bar on the far right. Down in the lower left corner it indicates 1264 bars. Of course the number of bars indicated will vary depending on when you run it.



This occurs in build 82 and build 81.
0
97
Solved
2 Replies

Reply

Bookmark

Sort
Glitch8
 ( 10.13% )
- ago
#1
You can still scroll the chart to get to the rest of the bars right? Is it a bug? I guess we could argue but we’ll just call it non-critical.
1
Best Answer
- ago
#2
Me being a dufus, I didn't notice the scroll bar. Thanks!
0

Reply

Bookmark

Sort