Login Page - Create Account

Support Board


Date/Time: Sun, 08 Sep 2024 00:21:59 +0000



sc.IsSwingLow not working in Replay Backtest

View Count: 253

[2024-07-25 19:39:13]
User725043 - Posts: 33
Hi,
sc.AutoLoop = 1;

sc.IsSwingHigh detects fine in both Bar and Replay backtest.

sc.IsSwingLow detects in Bar but not in Replay backtest. Once the Replay backtest is stopped, it does then send a flurry of detect messages, but not during "real-time".

Have tried:
int SwingHigh = sc.IsSwingHigh(sc.BaseData[SC_HIGH], Input_Length.GetInt());
int SwingLow = sc.IsSwingLow(sc.BaseData[SC_LOW], Input_Length.GetInt());
and
int SwingHigh = sc.IsSwingHigh(sc.High, Input_Length.GetInt());
int SwingLow = sc.IsSwingLow(sc.Low, Input_Length.GetInt());

Neither works for sc.IsSwingLow. Other than high/low is there any difference between them for a Replay backtest or anything else needs to be set?
[2024-07-25 20:28:16]
User719512 - Posts: 244
Instead of calling:
int IsSwingLow(SCFloatArrayRef In, int Length)
Have your tried calling:
int IsSwingLow(SCFloatArrayRef In, int Index, int Length)
to see if that make a difference?

works fine for me on v2661 as does the inbox study to which there is also source code to in the sierra folder.
[2024-07-25 21:48:06]
User725043 - Posts: 33
Yes, tried calling it with sc.Index and v2661. Also tried pulling from the study
sc.GetStudyArrayUsingID(Input_SwingStudy.GetInt(), 1, Array_C_L);

Same problem, sc.IsSwingHigh fine, but sc.IsSwingLow in Replay backtest does not seem to detect in "real-time".
[2024-07-26 07:13:27]
User431178 - Posts: 495
Yes, tried calling it with sc.Index and v2661. Also tried pulling from the study

Calling with sc.Index directly is not going to work at all for swing low (or correctly for swing high).

Both functions look backwards and forwards by the specified length, checking for lower low / higher high.

sc.IsSwingLow and sc.IsSwingHigh without the index parameter seem incorrect, as they start at the current bar.

User719512 mentioned the source code, suggest looking at that (\ACS_Source\Studies6.cpp "Swing High And Low"), you will then see how to use the functions (with the index parameter) correctly.
[2024-07-27 01:12:54]
User725043 - Posts: 33
Appreciate the comments, and yes have tried the IndexToEvaluate method in Studies6.cpp. Trying to understand the at current bar method, or perhaps this has been deprecated by SC?

The documentation shows 2 types of calls:
int IsSwingLow(SCFloatArrayRef FloatArrayIn, int Index, int Length);

int IsSwingLow(SCFloatArrayRef FloatArrayIn, int Length); Auto-looping only.

My study is set in sc.SetDefaults to:
  sc.AutoLoop = 1;

In the Replay backtest, after the initial calculation, sc.IsSwingLow just remains at 0. This makes results of the Bar(which works) vs Replay backtests significantly divergent.
[2024-07-27 07:50:04]
User431178 - Posts: 495
yes have tried the IndexToEvaluate method in Studies6.cpp.
If you did, and it still does not work, then something is wrong in your study somewhere.

Trying to understand the at current bar method
It cannot work correctly at the current bar that is all there is to it.
Nor can this work correctly, as it automatically passes the current bar as the index parameter to 3 parameter function.


int IsSwingLow(SCFloatArrayRef FloatArrayIn, int Length); Auto-looping only.

In the Replay backtest, after the initial calculation, sc.IsSwingLow just remains at 0. This makes results of the Bar(which works) vs Replay backtests significantly divergent.
Yes, because at the initial calculation all the bars exist, so when you start from the beginning of the chart there are bars before and after every bar, until you get to the last.
When you run a replay there are no bars after, it is as simple as that.

As I said before both functions look backwards and forwards by the specified length, checking for lower low / higher high.

What happens when you are at the last bar in the chart (when running a replay for example) and you check the value of the bar at index + 1?
It returns zero, which explains why:
sc.IsSwingHigh works - 0 is generally going to be lower than the value of the previous high.
but
sc.IsSwingLow does not - 0 is not generally going to be higher than the value of the previous low.

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

Login

Login Page - Create Account