- ago
with this strategy:
CODE:
namespace WealthScript1 { public class MyStrategy : UserStrategyBase { public override void Execute(BarHistory bars, int idx) {          foreach (var pos in OpenPositions)          {             if (idx - pos.EntryBar > 2)             {                // ClosePosition(pos, OrderType.Market, 0.0, "Timeout"); // works                ClosePosition(pos, OrderType.MarketClose, 0.0, "MarketClose"); // nope                // ClosePosition(pos, OrderType.LimitClose, bars.Low[idx], "LimitClose"); // works             }          }     double limit = bars.Close[idx] * 0.98;                   Transaction tr = PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, limit, "Limit"); } } }

running on daily S&P 100 I have trouble with OrderType.MarketClose while OrderType.Market and OrderType.LimitClose work as expected.
0
195
Solved
11 Replies

Reply

Bookmark

Sort
- ago
#1
DrKoch, is that you or is your account hijacked? 😃

What kind of "problems" or "trouble" are you having and/or what is not "expected"? At least some details are appreciated.
0
Glitch8
 ( 8.38% )
- ago
#2
Eugene, did you run the strategy code, and were unable to detect an issue?
0
- ago
#3
With the MarketClose exit enabled I get a bogus metrics report, no equity curve but a long list of positions which look roughly correct.
1
- ago
#4
here is the "Bogus Metrics Report":
1
- ago
#5
Here is the "Empty Equity Curve":

please also note the bogus footer text "Profit: NaN 0.00%"
1
Cone8
 ( 26.65% )
- ago
#6
It's hit and miss, but I'm seeing it. Just keep running the strategy again and again, and it will occur. If it matters, I'm using the W-D S&P 100 for most recent 2 years with 10% sizing.
0
Cone8
 ( 26.65% )
- ago
#7
Something happens here -



.. which happens to be the data that this set of Index changes occurred for the S&P 100. So that's probably the first place to look, although I don't see an issue with the data for any of these symbols.

CODE:
    <IndexChange> <Date>2021-03-19T00:00:00</Date> <Added>AVGO TMUS LIN</Added> <Removed>ALL KMI SLB</Removed>
1
Cone8
 ( 26.65% )
- ago
#8
Almost there...



It's probably something incompatible with the MarketClose exit logic combined with the auto exit logic from the symbol being removed from the S&P 100.
0
Cone8
 ( 26.65% )
- ago
#9
yah, the backtester is using the bar index for the MarketClose trade on 3/22, but SLB last day in the index is 3/19 - so the closing price for the trade is NaN. It's all downhill from there.
0
Glitch8
 ( 8.38% )
- ago
#10
I have a fix for this in place for Build 24.
0
Best Answer
- ago
#11
This was fast...
0

Reply

Bookmark

Sort