- ago
Hi,
i try a bit more complicated rotation strategy. In the PreExecute method, I, first, filter all assets for a certain criteria. Then, 2nd, there is second criteria which depends on the individual asset. After a while I solved this with a call to another function, like this:
QUOTE:
participants.RemoveAll(p => !rsiLevelCheck(p.Symbol, ((Asset)p.UserData).rsi));

ok, then i had a "buys"-List.
Now I am coming to the Execute method. This is a monthly rotation, which rebalances, as usual, at month-end. Due to the unfortunate fact, that MarketClose orders will only be excuted on the following bar (why is that anyway, can't you add a method which does this on the same bar?). So to overcome this, you basically operate on idx+1, e.g.
CODE:
// Execution only end-of-month          if (idx + 1 < bars.Count - 1 && bars.DateTimes[idx+1].Month != bars.DateTimes[idx+2].Month)

Now comes my problem, the buys list operates on idx, meaning you get the wrong selection (like the one for idx), but as I said, I have to operate on idx+1, otherwise I cannot get end-of-month executions.
Any idea how to solve this aka bring the buys-List in accordance with the rest of the code in the Execution method?
0
49
4 Replies

Reply

Bookmark

Sort
Cone8
 ( 5.57% )
- ago
#1
All trades occur on the next bar. It's no different for trading on the close because you can't use the Close data and then execute a trade on that Closing price.

If the problem is that you have to peek 2 bars into the future to know where the end of the month is, then you can use bars.TradingDaysRemaining(idx, Frequency.Monthly); When that returns 0, the idx passed to the function represents the last trading day of the month.
0
- ago
#2
Hello,
thank you for the quick answer.

I would say that is a rather weak argument. Obviously it is true that you cannot use the closing for getting a signal and simultaneously trade on that. But in reality, you just take the price a short period before closing (15min-1h) for your calculations and then trade on it with a MOC-order. I know many people including myself who do it exactly like that. And it works well enough.. Also, I think WL8 is the very only Backtesting-Software which handles MarketClose-orders like that... (also your old version WL4 and WL6 did it neither)

Your suggestion does not solve my problem. My rotation selection relies on idx. But to trade on end of month closing, I have to execute the MarketClose order on idx-1, since the order is executed idx+1, thereby excuting it in the end on idx. but since i have to do it like that, act on idx-1, the rotation selection from PreExecute relies on idx-1 also, and therefore giving me wrong signals...
I guess my question is, is it possible to somehow forward the generated buys-List from PreExeccute by one or take the value from it with idx+1? Then everything would be in-line.
0
Cone8
 ( 5.57% )
- ago
#3
QUOTE:
take the price a short period before closing (15min-1h) for your calculations and then trade on it.
You'll be happy to know that we even have trading option for that in the Strategy Monitor for Daily strategies:



You just need to adjust the strategy to use the next index. Probably, you'll be able to figure it all out by watching this video that introduced the At-Close Signaling method a few months ago - https://youtu.be/Z39A55OEudM
0
Cone8
 ( 5.57% )
- ago
#4
PreExecute() passes the current date, and from that you need to GetCurrentIndex(). It should work if you just add 1 to that result for the next index. Just keep in mind that you need GetCurrentIndex() for each BarHistory in PreExecute(). These values may not be the same number.
0

Reply

Bookmark

Sort