Different results issue when using inDaily and TimeFrameExpand

We are calculating a proprietary score based on daily data (derived from hourly data,) yet tested on the hourly data. So I am using something like this (reduced for simplicity here):

TimeFrameSet( inDaily );
ScoreInDaily = MA(Close, 200);
RestorePriceArrays();
myHourlyScore = TimeFrameExpand( ScoreInDaily, inDaily, expandLast);

The problem is that when we run a test using this as our entry:

EntrySetup = close > ref(close, -20)
AND Ref(myHourlyScore, -1) >= -99999999999999
;

we get completely different results than if we run this:

EntrySetup = close > ref(close, -20)
//AND Ref(myHourlyScore, -1) >= -99999999999999
;

How can this be? If the score never goes below zero, and I am saying it needs to be above an extremely large negative number, then why would the results be different?

The point you are trying to make is unclear. AFAIK in AFL we can compress a faster timeframe to a slower one. An Hourly chart can be compressed to Daily not vice-versa. Also read How does it work internally in Multiple Time Frame support in AFL.

IMO a score cannot be declared as an array unless we store multiple scores in an array in order to sort or to perform any other procedure. As you mentioned that the scoring methodology is proprietary, it depends which school of mathematics has been applied to calculate the score.

The example and the problem that you have mentioned above are unrelated and extremely hard to decipher due to lack of clarity.

@Lennon, than you for taking the time to help.
Let me clarify. My database is constructed using hourly bars. I switch to daily using:

TimeFrameSet( inDaily );

Then I create a score with a complex formula, but for example's sake here, I have simply used this instead:

ScoreInDaily = MA(Close, 200);

(The problem persists using our complex score, and with this over simplified one too.)

I then switch back to hourly bars using this:

RestorePriceArrays();

I then expand the daily score created above into hourly bars, so that I can plot it, use it in the hourly strategy, etc. like this:

myHourlyScore = TimeFrameExpand( ScoreInDaily, inDaily, expandLast);

Maybe the fact that I called this "myHourlyScore" has confused you. It could easily be just called "myScore." It is simply the daily score, but on hourly bars. Sorry for the confusion here.

I realize that "scores" are then often used for "ranking", which we do too in other parts of the code, but we are analyzing things like, "what if score is above/below zero on a given day?" So, while the ranking component is used later, I have stripped it out in this example because even before we get there, we are simply analyzing filtering trades using the score alone.

So the question remains, how can it be that simply commenting out the requirement for score to be above a large negative number, which should be the same as not having the condition in there at all, give us totally different results than if the requirement was not in there at all.

IE:

The problem is that when we run a test using this as our entry:

EntrySetup = close > ref(close, -20)
AND Ref(myHourlyScore, -1) >= -99999999999999
;

we get completely different results than if we run this:

EntrySetup = close > ref(close, -20)
//AND Ref(myHourlyScore, -1) >= -99999999999999
;

i would suggest using _Trace() to figure out the actual value of Ref(myHourlyScore, -1) or whatever you are comparing that to -99999999999999 before running the filters. Then probably you will know why the difference in the result occurs upon considering or commenting it out.

One more thing, generally, these scores are probability based, so are most often percentages, thus, even if the output is shown as 100 but the calculated result of the score might be 1. So, please ensure whether the value is negative decimal or a negative real number.

You might have nulls, try this

myHourlyScore = Nz(myHourlyScore);
2 Likes

@awilson BINGO!!!!!!!!!

Thank you so much!

Hi @vjsworld
I know this is an old posting however I was reading through the forum as I am experiencing a similar problem to that which you have described, however I when I look at the problem you reported and the solution provided, it does not make sense.
In your code you refer to the RestorePriceArrays() for a timeFrameSet() command however (based on my understanding) you should be using TimeFrameRestore() command in place of RestorePriceArrays() function.

Note that the RestorePriceArrays restores original price and volume arrays after the call to SetForeign , which is not the case here.

So did the solution in this posting actually work?

Thanks

Technically (i.e. according to the documentation) you are correct about the use of those two functions, but they actually do the same thing and are thus interchangeable.