- ago


Please, have a look at these positions. The strategy opens positions somehow and that checks if there are open positions if so - closes with PlaceTrade(bars, TransactionType.Sell, OrderType.MarketClose);

So the Bars Held must always be 2. But it is not. You can see that this happens when entry dates of the trades with erroneous Bars Held are next to each other (as it's Daily that means bars are next to each other). Looks like when calculating trades the system swaps closing trades of this two positions or simething like this.
0
576
Solved
6 Replies

Reply

Bookmark

Sort
- ago
#1
The Bars Held per se is correct with regard to the dates and according to holidays.

As for the 1- or 3-day time spans I think you're better off posting some code to demonstrate the anomaly? Maybe something is not quite right with the strategy.
0
Glitch8
 ( 9.28% )
- ago
#2
We would need to see some minimal code to reproduce this to diagnose. without seeing this, i’d recommend using ClosePosition instead of PlaceTrade to ensure specific open positions get closed.
0
- ago
#3
Time runs, I use my wrapper over WL7 strategy, my code will look strange to you).

Maybe the point is i get the position opening moment wrong.
Here is a simple example, that works just the same:

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; 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 (true) {             //code your buy conditions here             PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, bars.Close[idx] * 0.995); } if (HasOpenPosition(bars, PositionType.Long)) {             PlaceTrade(bars, TransactionType.Sell, OrderType.MarketClose); } } //declare private variables below } }
0
- ago
#4
I expect this code to have 2 Bars Held for every position, but it's not).
0
Glitch8
 ( 9.28% )
- ago
#5
if you just call PlaceTrade you cannot be guaranteed which open position might be closed. use ClosePosition instead.
1
Best Answer
- ago
#6
Ok, thanks.
0

Reply

Bookmark

Sort