- ago
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.
1
1,411
Solved
10 Replies

Reply

Bookmark

Sort
- ago
#1
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
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.
1
- ago
#2
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.
0
- ago
#3
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.
0
- ago
#4
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?
0
- ago
#5
Are you not filtering out pre/post intraday market data in Preferences or in Strategy Settings?
1
- ago
#6
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.
0
- ago
#7
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]))"); } }
0
- ago
#8
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.
1
- ago
#9
Added option "Market hours only" to our building block for PowerPack build 9.
1
Best Answer
- ago
#10
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.
1

Reply

Bookmark

Sort