Login Page - Create Account

Support Board


Date/Time: Fri, 03 May 2024 18:02:35 +0000



BackTest an AutoTrade System -- Is BaseData Modified per the 4 Samplings per Bar??

View Count: 1568

[2014-04-29 10:11:04]
Israel Gottlieb - Posts: 14
I understand that during Bar-based BackTest, an Autotrade system is run 4 times per bar -- i.e. at each of OHLC. My question: Consider the first sampling, i.e. which uses the value of the OPEN price; what happens to the BaseData used by e.g. a Stochastic indicator, during that indication. Say the Stochastic specifies LAST price as the basis for its calculation. In real trading, when the price is at OPEN, the LAST price is the same OPEN -- because that's the only price that exists at that point. Is the BaseData LAST price modified to correspond with the OPEN value, when the 1st of 4 iterations is executed on a bar? Or is the value of LAST the same as that given in the historical data, i.e. what turned out to be the CLOSE of the bar? If the latter is true, you can get substantially distorted results from backtesting, since an Autotrader can specify entry on the opening, but will be using indicators that see the completed bar -- i.e. can tell the future!

Please advise what is the correct way to approach this issue. Is there documentation that spells out exactly what the simulator does during backtesting?

I. Gottlieb
[2014-04-29 10:27:23]
Israel Gottlieb - Posts: 14
Just to clarify -- my question is not speculative. I ran an autotrader that uses MACD & Stochastic based on the CLOSE, and logged all indicator values during a backtest. The values were always identical for all 4 samplings of a given bar.

[MACD was based on LAST; Stochastic uses HIGH & LOW (I was mistaken when I wrote that is was base on LAST) but the basic issue is the same -- are these values modified to reflect partial formation of the bar?]
[2014-04-30 01:34:53]
Sierra Chart Engineering - Posts: 104368
We will do some documentation updates.

We see the point you are making. Although the last trade price, bid and ask are updated as the OHLC bar values are iterated through, the actual chart bar values themselves do not change. We will change this in the next release.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2014-04-30 04:55:02]
Sierra Chart Engineering - Posts: 104368
Try version 1129. Bar based back testing should work as you expect.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2017-07-04 10:36:49]
Samuel - Posts: 8
Hi, I have the same query. If I only want bar-based back testing to execute at close price (ie, not open high or low), do I need to insert a condition in my code?

SCFloatArrayRef Last = sc.Close;

if (sc.LastTradePrice<=Last[sc.Index]+1 && sc.LastTradePrice>=Last[sc.Index]-1)
Result = sc.BuyEntry(NewOrder);

Thanks.
Date Time Of Last Edit: 2017-07-04 10:39:23
[2017-07-04 16:15:30]
Sierra Chart Engineering - Posts: 104368
This inherently is difficult to do even for us.

The only thing we can recommend is to look at the code example here to determine when there is a new bar added to the chart:
ACSIL Programming Concepts: Detecting New Bars Added to Chart

When there is, you can then take some action and the trade will be at the open.

But you could do something like you are doing to compare the last trade price, to the bar closing price.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2017-07-04 16:16:00
[2017-07-04 21:10:57]
Samuel - Posts: 8
Thanks for the suggestion, but I think my question is a more simple one, it refers to bar based back testing when sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED, where I understand Sierra will test using each of the OHLC price and I just want the code to execute at Close price. Does detecting new bars only occurred when Sierra is testing the Close price? How do I ensure no action is taken at OHL prices?

Thanks.
[2017-07-06 06:53:28]
Sierra Chart Engineering - Posts: 104368
sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED is not going to do what you want. It is only going to indicate true for a bar if it is no longer the last bar in the chart. Once there is a new bar, the last trade price will be based upon the open price of that bar.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2017-07-06 06:54:34
[2017-07-06 08:12:55]
Samuel - Posts: 8
Let's start over. I want the logic to run on bar close only and use bar based back testing to review the results. However it is undesirable for me that bar based back testing uses OHL prices in testing the condition, I only want the condition to evalute using close price, is there a way to suppress testing using the OHL prices in bar based back testing?

I can accept fills based on either close price of current bar or open price of next bar, but not the OHL prices that I can no longer go back to in a live environment. Thanks.
[2017-07-06 08:21:32]
Sierra Chart Engineering - Posts: 104368
is there a way to suppress testing using the OHL prices in bar based back testing?
No.

I can accept fills based on either close price of current bar or open price of next bar
In this case, then use this:
sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED

This will use the open price of the next bar.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2017-07-06 09:41:08]
Samuel - Posts: 8
Sorry for my elementary question. I am already using sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED in my condition so to make sure the logic is only called once per bar upon bar close. Are you saying then OHL prices will not be used to evaluate the condition?

I am a bit confused as I seem to be getting different results when compared to full replays and all conditions have been surrounded by BHCS_BAR_HAS_CLOSED. What are the possible causes that comes to mind?
[2017-07-06 19:05:55]
Sierra Chart Engineering - Posts: 104368
Sorry for my elementary question. I am already using sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED in my condition so to make sure the logic is only called once per bar upon bar close. Are you saying then OHL prices will not be used to evaluate the condition?
During a bar based back test, the condition would be evaluated during the open of the next bar.

I am a bit confused as I seem to be getting different results when compared to full replays and all conditions have been surrounded by BHCS_BAR_HAS_CLOSED. What are the possible causes that comes to mind?
So you are comparing a bar based back test to a replay back test?
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2017-07-06 19:06:13
[2017-07-06 19:56:58]
Samuel - Posts: 8
What I wanted to do is to evaluate the condition only once per bar and be able to obtain accurate results using bar based back testing method, hence I use BHCS_BAR_HAS_CLOSED in my condition.

Judging from your response, this is simply not possible with Sierra Chart. With bar based back testing, the condition will be evaluted during open of next bar using OHLC price even with BHCS_BAR_HAS_CLOSED in my condition. The only way to see accurate results is to use replay back test where the condition will be evaluated using open price of next bar only.

Is that correct, or is there a way to accomplish what I wanted to do with bar based back testing? Thanks
[2017-07-07 02:17:16]
Sierra Chart Engineering - Posts: 104368
With bar based back testing, the condition will be evaluted during open of next bar using OHLC price even with BHCS_BAR_HAS_CLOSED in my condition

Yes this is the case but the order will be filled at the opening price of that new bar.


The code example you gave in post #5 we think is a reasonable way to accomplish what you want. In that case, you would not use BHCS_BAR_HAS_CLOSED.

This is what we would recommend:
if (sc.LastTradePrice==Close[sc.Index])
Result = sc.BuyEntry(NewOrder);

But you should do the comparison using a formatted evaluate:
sc.FormattedEvaluate()
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account