- ago
I think, "simulating" is the better word for this, but I can not edit topic name).

It looks like I can’t open short if there is an open long position. And I think it’s by design, isn’t it?

Anyway, could you please help with this task (any ideas or something):

There are stocks, that are not allowed for short trading. But I can emulate short trades: for example I open 10K shares long position and that’s the emulated zero, if I close 5K of this position – it’s like 5K short, and when I buy 5K again (10K in total) it’s like closing short.

When backtesting short part of it you do not need all this “emulating” you just can use short trades. But in real life you will get results like: short strategy results + constant long result. So the most obvious for me was to open long position in the beginning and do all that normal short trades on short signals. But as it turned out WL7 do not allow that. So maybe there are any other ways to do that?
0
76
Solved
5 Answers

Reply

Bookmark

Sort
- ago
#1
Why do you think you cannot maintain an open short and long position at the same time? Here is a minimal code sample that does it.

CODE:
using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //Initialize public override void Initialize(BarHistory bars) { } //Execute public override void Execute(BarHistory bars, int idx) {          if (idx == bars.Count - 50)             PlaceTrade(bars, TransactionType.Buy, OrderType.Market);          if (idx == bars.Count - 40)             PlaceTrade(bars, TransactionType.Short, OrderType.Market);     if (idx == bars.Count - 30)             PlaceTrade(bars, TransactionType.Cover, OrderType.Market);          if (idx == bars.Count - 20)             PlaceTrade(bars, TransactionType.Sell, OrderType.Market); } } }


0
Best Answer
- ago
#2
Great!

So, maybe it's a bug.

If i start with two long position at the begining, I get only these two positions with no shorts. But if I start with only one long, it works as expected.

Backtesting params:

0
- ago
#3
Yes, it's likely a bug in your Strategy code. Here is the minimal example extended to open 2 long positions, then 1 short, then close them one by one.

CODE:
using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript1 {    public class MyStrategy : UserStrategyBase    {       //Initialize       public override void Initialize(BarHistory bars)       {       }       //Execute       public override void Execute(BarHistory bars, int idx)       {          if (idx == bars.Count - 50)             PlaceTrade(bars, TransactionType.Buy, OrderType.Market);          if (idx == bars.Count - 45)             PlaceTrade(bars, TransactionType.Buy, OrderType.Market);          if (idx == bars.Count - 40)             PlaceTrade(bars, TransactionType.Short, OrderType.Market);          if (idx == bars.Count - 30)             PlaceTrade(bars, TransactionType.Cover, OrderType.Market);          if (idx == bars.Count - 20)             PlaceTrade(bars, TransactionType.Sell, OrderType.Market);          if (idx == bars.Count - 10)             PlaceTrade(bars, TransactionType.Sell, OrderType.Market);       }    } }


1
- ago
#4
I insist there is a bug out there)).



If I run with this settings (MaxOpenLong = 2) – I get only 2 long positions, 0 short (1 short NSF).
If I run with the same settings, but MaxOpenLong = 3 (this must not effect, but it is - looks like a bug), I get the same results what you get.
1
- ago
#5
QUOTE:
I insist there is a bug out there)).

And your guess is spot on. There is a bug to be fixed in Build 12. Thanks.
1

Reply

Bookmark

Sort