- ago
Hi,

the Pre/Post Filter in the Backtester (and Chart) is nice but what if i wanted to base some condition of Pre/Post vs. RTH in a coded strategy?

How would i check if a certain bar is part of Pre/Post or RTH of that market?
1
423
Solved
3 Replies

Reply

Bookmark

Sort
Glitch8
 ( 10.62% )
- ago
#1
It's impossible. The Strategy has to LOAD the data first before it can execute.

Of course, there's nothing preventing you from filtering data in your Strategy logic to EXCLUDE any pre/post market data that might have been loaded.
0
- ago
#2
Im sorry Glitch, i did not explain my question very well. It is ok that WL loads all bars, Pre, RTH, Post. But i was wondering if there is a way in code to distinguish if a bar is part of Pre/Pos or RTH. Something like (pseudo code):

CODE:
if (bars.IsRTH(idx)) doSomething(); if (bars.IsPreMarket(idx) doSomethingElse();
0
Glitch8
 ( 10.62% )
- ago
#3
Yes here's an example that shades the part of the chart that is pre/post market,

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; 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) {          MarketDetails mkt = bars.Market;          if (!mkt.IsOpenMarketTime(bars.DateTimes[idx]))             SetBackgroundColor(bars, idx, new WLColor(64, 255, 0, 0)); } //declare private variables below } }


2
Best Answer

Reply

Bookmark

Sort