Back

Backtesting with specific time zone daily bar closes

Hello,

I'd like to know if it's possible (and how) to backtest a strategy I have found that requires:

1) To set the daily bar close to a certain GMT+NN time zone. NN is a number that is not any of NY close, London open and so on. It's just a very custom number.

2) Create buy/sell stop orders 3 pips above a certain bar pattern depending on the daily bar close price (point 1).

Thanks in advance
Update Backtest








Hello Dario, its not possible to reset the timezones of the data. But if you have specific times in mind you wish to operate you can add the offset yourself. E.g.

int desiredZone = 0;
var myTime = Time.AddHours(desiredZone + 5);
if (myTime.TimeOfDay.TotalHours > 14.5) // 13:30 is market open in GMT.


Your second question yes its possible; the stop orders can be issued with StopMarketOrder(string symbol, int quantity, decimal stopPrice, string tag = "")
0

Thank you, Damien!

I tell you what's involved: I need to backtest a Forex strategy that depends on the close of the previous day daily bar. Something like: "if (price_daily_bar_close > current_hourly_bar_close) ...".
The issue is the daily bar close must be based on this weird custom timezone.

My current idea is to try and bypass the whole difficulty by:

1) Not taking that daily close price (which by what you say, looks impossible to do).
2) Using the hourly chart instead. Take the price of the close of the [QuantConnect bars time zone (I suppose it's NY close) + 4/5 hours (daylight savings) + GMT custom offset] bar.
This close price, if I am not wrong, should be the same of the GMT + custom offset daily bar, thus circumventing the inability to shift the timezones.

Do you think this reasoning is sound and would work with this platform?

Thanks again!
0

Yes data here is in EST. Perhaps it easiest to make your own consolidator? i.e. Build daily bars which start and end at certain times and emit an event when it passes. Then you can control everything in a tidy fashion. You could use the Consolidator classes provided in some of the QC University code.

class CustomConsolidator : DataConsolidator
{
private TradeBar _consolidatedBar;

public override Type OutputType
{
get { return typeof (TradeBar); }
}

public override void Update(TradeBar data)
{
if (data.Time.TimeOfDay.TotalHours > 14)
{
OnDataConsolidated(_consolidatedBar);
_consolidatedBar = new TradeBar()
{
Time = data.Time
};
}
else
{
_consolidatedBar.Update(_consolidatedBar.Close, _consolidatedBar.Close, _consolidatedBar.Close, _consolidatedBar.Volume);
}
}
}
var custom = new CustomConsolidator();

custom.DataConsolidated += (sender, consolidated) =>
{
// Handle your bar.
};

SubscriptionManager.AddConsolidator("EURUSD", custom);
1

Thank you so muuuuch!
0

No worries, there's a bug in it actually --should be:
_consolidatedBar.Update(data.Close, data.Close, data.Close, data.Volume);
0

Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed