I love using the Building Blocks for strategy design, but I need my strategies to close all positions by the end of market hours. For now, this means I have to convert all strategies to coded strategies so that I can include that logic, but this could be avoided if there was a building block that allowed entering/exiting a position based on the current Market Hours.
Rename
There are building blocks which aid to help this. You can find them after installing the PowerPack extension and restarting WL7. Quoting the extension's change log:
https://www.wealth-lab.com/extension/detail/PowerPack#changeLog
https://www.wealth-lab.com/extension/detail/PowerPack#changeLog
QUOTE:
Build 8 - 9/3/2021
Added First/Last Bar of Day Condition Building Block.
Added Time of Day Condition Building Block.
Added Price Compare to Price at Entry Bar Condition Building Block.
Thank you for the hint. I don't suppose these building blocks will take into account market holidays or early closing hours, but they're still quite useful.
QUOTE:
I don't suppose these building blocks will take into account market holidays or early closing hours,
"Bar of Day" takes them into account.
I just set up a design block strategy that only enters or exits a position if "Bar of Day" is greater than the first, and less than the last. But when I optimize and view backtest results, I see positions created far outside of the "09:30 to 16:00" hours associated with the "US Stocks" market. Perhaps I am misunderstanding how it's intended to work?
Are you not filtering out pre/post intraday market data in Preferences or in Strategy Settings?
No, because I'd like for my strategies to take pre/post market data into account when evaluating indicators during normal market hours. But please let me know if I'm confused about how this works.
I tried creating my own Design Block to accomplish this, but I'm hesitant to use it in my strategies in case it's flawed. Perhaps you can tell?
CODE:
class MyMarketHoursConditionBuildingBlock : ConditionBuildingBlock { public override string Name => "IsMarketHours"; public override void Initialize () { RegisterVariable("_market", "MarketDetails"); } public override void GenerateInitCode () { InitCode.Add(" <_market> = MarketManager.FindMarket(\"US Stocks\");"); } public override void GenerateConditionCode () { MainCode.Add("if (_market.IsOpenMarketTime(bars.DateTimes[index]))"); } }
Looks good on the surface but I'd use bars.Market.IsOpenMarketTime to avoid hardcoding the U.S. market - there are cryptos, international markets etc.
Added option "Market hours only" to our building block for PowerPack build 9.
Attention!
Some conditions featured here will not work with Qualifiers due to a bug. Affected conditions include:
+ Bar Of Day
+ Day Of Week
+ Position Profit/Loss
+ Consecutive Peaks/Troughs
To fix it, update to PowerPack B13 and WL7 B29 once they're ready.
Some conditions featured here will not work with Qualifiers due to a bug. Affected conditions include:
+ Bar Of Day
+ Day Of Week
+ Position Profit/Loss
+ Consecutive Peaks/Troughs
To fix it, update to PowerPack B13 and WL7 B29 once they're ready.
Your Response
Post
Edit Post
Login is required