Login Page - Create Account

Support Board


Date/Time: Mon, 20 Jan 2025 14:04:38 +0000



[Programming Help] - Please Help: Study Overlay not working correctly in Live Trading

View Count: 1304

[2018-06-19 01:36:14]
rahul - Posts: 167
Hello, I am currently using Study Overlay to do a Moving Average Crossover. The source chart is a 60 minute chart and destination chart is a 10 minute chart. What I want is that when the moving average crosses over on 60 minute chart, I should trade based on 10 minute chart.

The logic is as soon as the moving average crossover happens on the 60 minute chart, I should be able to trade on the 10 minute chart on the bar close of the 10 minute chart.

The code works fine when I back-test the data. However on live trading the trade is only automatically executed when 60 minute bar closes. So if the crossover happens at 10:13 AM for example, the trade should execute on 10 minute bar close at 10:20 AM. This works fine in back-testing. However in live trading the trade executed at 11:00 AM instead, which is the 60 minute bar close. Not sure why this is happening.

The chart order:
Chart 1: 60 minute chart
Chart 2: 10 minute chart

Study Overlay Study on 10 minute chart referencing 60 minute chart. Then I am referencing the moving averages through my code from the Study Overlay.

The following code has been added to my coded study:
sc.CalculationPrecedence = LOW_PREC_LEVEL

sc.GetStudyArrayUsingID(Input_ID1.GetStudyID(), Input_ID1.GetSubgraphIndex(), Arr_ID1);
sc.GetStudyArrayUsingID(Input_ID2.GetStudyID(), Input_ID2.GetSubgraphIndex(), Arr_ID2);

Output_ID1[cB] = Arr_ID1[cB];
Output_ID2[cB] = Arr_ID2[cB];

An example of Buy Entry Condition on the 10 minute chart: (Output_ID1 => Moving Average 1 and Output_ID2 => Moving Average 2)

if ((Output_ID1[sc.Index - 1] < Output_ID2[sc.Index - 1]) && (Output_ID1[sc.Index] > Output_ID2[sc.Index]) && (sc.GetBarHasClosedStatus(sc.Index) == BHCS_BAR_HAS_CLOSED))
BuyToOpen = 1;

s_SCPositionData PositionData;
sc.GetTradePosition(PositionData);
if ((BuyToOpen == 1) && (PositionData.PositionQuantity == 0))
sc.BuyEntry(NewOrder);

Not sure why the behavior in back-testing is done correctly and not working in Live Trading (CQG WebAPI).

Please help!
Date Time Of Last Edit: 2018-06-22 12:14:41
[2018-06-20 04:20:43]
Sierra Chart Engineering - Posts: 104368
The first thing you should do is study carefully the Study/Price Overlay study and its Inputs:
Study/Price Overlay Study

Make sure the Inputs are set as you require.

And when a chart is updating live, make sure the Study/Price Overlay is displaying the data that is needed, at the last chart bar. Is that the case? If so, we would not expect a problem like this.
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: 2018-06-22 12:32:21
[2018-06-22 12:14:26]
rahul - Posts: 167
Thank you for your reply. I think I figured out the problem and now hope you can help with a solution.

Problem: The crossover of moving averages happens at the end of the 60 minute bar (reference chart: 60min), even though I am trading on the 10 minute bar. When I overlay the 60 minute moving averages on the 10 minute chart, it looks like the crossover happens around the 30 minute mark in the 60 minute bar. However by doing a complete chartbook replay, I notice that only after the 60 minute bar is complete does the crossover reflect on the 10 minute charts 30 minutes into the bar (instead of at 60 minutes).

What I want to do is calculate this true crossover on the 10 minute chart i.e. at the 30 minute mark.

Is there anyway I can do that? Hope this makes sense.
[2018-06-22 17:56:56]
Sierra Chart Engineering - Posts: 104368
It is hard for us to fully understand this from our perspective because we do not have your charts and studies, but check these two inputs:
Study/Price Overlay Study: Data Copy Mode

Study/Price Overlay Study: Bar Time Matching Method
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
[2018-06-22 18:12:30]
rahul - Posts: 167
Is it possible for someone from Sierra Chart work with me directly on this? I will pay for the support.
[2018-06-22 18:21:27]
rahul - Posts: 167
I am attaching an example of a 30 minute chart crossover on a 3 minute chart. After the crossover on the 30 minute bar is done at 10:00 AM, it shows up on the 3 minute chart at 9:45 AM. Is there anyway to calculate the 30 minute bar value on the 3 minute chart to reflect crossover at 9:45 AM in real-time instead of waiting for 30 minute bar close?

I am attaching the Study Overlay settings and snapshot of the example
imageSettings.png / V - Attached On 2018-06-22 18:20:11 UTC - Size: 70.19 KB - 308 views
[2018-06-23 19:44:42]
Sierra Chart Engineering - Posts: 104368
Set Data Copy Mode to Containing Match:

Study/Price Overlay Study: Data Copy Mode
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
[2018-06-23 19:50:25]
rahul - Posts: 167
Thank you. Setting to containing match worked.

I noticed another issue though... I get different results when I replay all charts (source and destination charts) as compared to only destination chart (the traded chart) when I do automated backtesting. Do you know why? I would assume after changing to "containing match" the results shouldn't be different anymore.

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

Login

Login Page - Create Account