- ago
WL7 is undercounting Bars Held by 1 for Market Exits. This can be verified in countless strategies, here's one I created:
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 (!HasOpenPosition(bars, PositionType.Long)) {             if (idx == bars.Count - 3)             {                PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, "Market");                PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, bars.Close[idx] * 10, "Limit");             } } else { PlaceTrade(bars, TransactionType.Sell, OrderType.Market, 0, "Market");             PlaceTrade(bars, TransactionType.Sell, OrderType.Limit, 0.01, "Limit"); } } //declare private variables below } }


And here's the result:
Pic1 - Entry@Market, Exit@Market


Pic2 - Entry@Limit, Exit@Market


Notice that it's the Exit @Market that results in the undercount, the Entry could be of any type.

This undercount has wide-ranging implications. Please fix.
0
812
Solved
16 Replies

Reply

Bookmark

Sort
Glitch8
 ( 12.10% )
- ago
#1
This is intentional. If the position is filled at the open of the market, you're not really holding it during that bar, so it's not counted.
0
Best Answer
- ago
#2
I deliberately created Limit orders that were essentially equivalent to Market orders. They are counted for both bars.
-----------------------------

If two positions have identical Entry & Exit Dates it follows they both must have identical values for Bars Held.
0
Glitch8
 ( 12.10% )
- ago
#3
It does make sense that limit/stop orders that exit right at market open should be counted the same, will log this issue.
0
Glitch8
 ( 12.10% )
- ago
#4
OK, the subtle tweak is completed for Build 23. If you'd like, submit a #FeatureRequest for a new option that will always count trades that exit at market open as a full additional bar held.

0
- ago
#5
Feature request created.
-----------------------------

I am puzzled by the graphic you posted... for the highlighted trade with an Entry Date of 11/6/20 and Exit Date of 11/9/20 it should show Bars Held as 2 as its 2 separate dates (as long as the trade is filled it doesn't matter where the market opened).
0
Glitch8
 ( 12.10% )
- ago
#6
Since that position was sold right at market open, that exit bar is not counted in the Bars Held calculation.
0
- ago
#7
The logic of that argument escapes me.
If a position is closed on a particular bar that bar *should* be counted, the time that position gets closed during the day is irrelevant. The broker considers your position open at the beginning of the day - and so should WL7. The settlement of the position, and the consequent release of funds in non-margin accounts, will be T+2 where T is the trade date. And what if a stock is halted for days, sometimes weeks, for a variety of reasons (news pending, allegations of fraud, etc.)? WL7 will consider the position closed as of signal bar whereas in real life you are stuck with the position, and your funds locked up, until the stock resumes trading days/weeks later. This is real, not hypothetical.
-------------------------------------

Getting the Bars Held number correct has significant implications in other aspects of the program, such as Performance Metrics (Exposure, Average Bars Held, Profit/bar, etc. - to name just a few).

Anyway, since you've indicated in the corresponding Feature Request thread you'll add that as a Backtesting option that should work; I assume, of course, that the corrected value of Bars Held will correspondingly be applied program-wide, as applicable.
0
Glitch8
 ( 12.10% )
- ago
#8
The logic is dead simple. If my position exits at the start of the trading day, i’m not really “holding” it during that bar, now am I? Any way we could argue back and forth about whether or not it makes sense. Obviously it does not to you, but it makes perfect sense to me. So, let’s just leave it at the feature request and bask in the diversity of opinions here 🙂
0
Cone8
 ( 6.32% )
- ago
#9
What's up this week with the demanding tone for requests by multiple customers? (Did I say that out loud?)

Obviously we know how it affects metrics,. and that's why it was decided not to count the bar on which the trade isn't held. If you hold a trade for less than 24 hours or less for a daily bar, that's 1 bar in our book. We're open to other opinions, and that's what feature requests are for.
2
Glitch8
 ( 12.10% )
- ago
#10
Thanks Cone. I’ve been called “a machine” before, so obviously the customers have forgotten we are human beings too 🤣
0
- ago
#11
Sorry, I get over-enthusiastic sometimes. :(

@Cone:
QUOTE:
...not to count the bar on which the trade isn't held

You carry the open position into that day so that trade is held. This is an irrevocable fact.
Check your brokerage statements, the execution date will be the date the trade was closed - and this doesn't change with the time stamp of the trade. For their account cash balances, margin requirements, and so forth that is what they go by.

QUOTE:
...If you hold a trade for less than 24 hours or less...

And who is to say the trade was held less than 24 hours just b/c it was a Market exit? A Limit Buy & Sell could theoretically have been held for even less yet both Trade Entry & Exit days are counted for Bars Held (as they should be).

BTW, Bars Held counting the exit bar for Market exits also goes back multiple versions of Wealth-Lab (and rightfully so).
0
Glitch8
 ( 12.10% )
- ago
#12
It's good to see this level of passion one way or another :D
0
- ago
#13
I am a very long-term AND passionate user of Wealth-Lab.
I only wish the best.
And that's an irrefutable fact!
-------------

Anyway, any discussion of whether the position was held 24 hours or less is totally off-track; in end-of-day trading we deal with bars (i.e. dates), not hours.
0
Glitch8
 ( 12.10% )
- ago
#14
Hey, if you want to count an entire bar as being held even if you only hold the position for a split second that bar, we aim to please! We'll get the option implemented in due course! ;)
0
- ago
#15
Using Build 23, where the Change Log states:
For the purposes of calculating Bars Held, limit/stops that execute above the limit/stop price are not counted as being held for that bar (same as market exit orders).

This would be the exact *opposite* of what this thread was about.

Anyway, for users with a different point of view hope you'll provide an option under Preferences\Backtest that counts the Exit Bar (for all trade types) for purposes of calculating Bars Held.
0
Glitch8
 ( 12.10% )
- ago
#16
It's the opposite of what you were looking for, I know, but we needed to do this to keep consistency, thanks for bringing it to light!

We'll eventually get to the enhancement that lets it work "your way". It's already in the Wish List.
0

Reply

Bookmark

Sort