Use Advance/Decline Line on Daily in a Weekly system
Author: ecorderob
Creation Date: 7/2/2011 7:52 AM
profile picture

ecorderob

#1
Hi,

I have some system which is executed in weekly timeframe. I would like to add some condition involving the advance decline line (which is calculated in daily timeframe), but if I try to setScaleDaily() and then RestoreScale() it throws some exception.

Is there any way to do it? I mean a way without implementing the system in daily timeframe.

Thanks,
-Enrique
profile picture

Eugene

#2
Hi Enrique,

Let's start by providing details on: which exception is thrown, which code have you written, which data providers and data loading ranges are you using.
profile picture

ecorderob

#3
Hi Eugene,

This would be an example of what I am trying to do (executed in Weekly timeframe). I get the following exception: Cannot convert Weekly bars to daily scale.

CODE:
Please log in to see this code.
profile picture

Eugene

#4
You shouldn't be executing a code with SetScaleDaily on a Weekly chart. Furthermore, I don't get the point of that upscaling Daily data to Weekly and then downscaling to Daily and synchronizing it.

Switch the chart to Weekly and the external series automatically gets scaled to your chart's time frame, isn't it?
profile picture

ecorderob

#5
Yep, the problem is that the Advance Decline line when it is calculated in Weekly basis is not calculated properly :(
profile picture

Eugene

#6
How did you determine that?
profile picture

ecorderob

#7
If you look at the AD line in weekly scale, it creates a big divergence with the S&P 500 in March 2009, when it does not really exists in daily scale. (For example)
profile picture

Eugene

#8
Please clarify like you would to a 9-year old, thank you. Do you question Wealth-Lab's native scaling?
profile picture

ecorderob

#9
No, not at all (well, not in general) :)

This is why I think the behaviour is different in daily and weekly scales: When you calculate the AD Line you calculate it like:

CODE:
Please log in to see this code.


If you do that calculation in weekly scale WL takes the status from the last day of the week (I suppose) and calculate the AD with those (but in this case you ignore what has happened during the rest of the week). And that is not right for the AD line.

Let's put an example:

Previous Week: AD = 10
UP / DOWN
Monday: 5 / 5 -> 0
Tuesday: 3 / 7 -> -4
Wednesday: 4 / 6 -> -2
Thursday: 4 / 6 -> -2
Friday: 5 / 5 -> 0

If you calculate it in Daily scale the AD on friday would be: AD = 10 + 0 - 4 -2 -2 + 0 = 2
But if you take the values in Weekly scale you ignore from Monday to Thursday and AD = 10 + 0 = 10

That is why I think AD line in weekly scale can not be trusted.
profile picture

Eugene

#10
Thanks for the clarification/example, now I'm with you as it makes sense.

Since you already obtained the Daily A/D series, will Synchronize'ing it w/o changing scale do the job?

CODE:
Please log in to see this code.
profile picture

ecorderob

#11
It does not make any difference :(

I have created a quick example, so that you can see it

CODE:
Please log in to see this code.
profile picture

Cone

#12
There are at least a couple direct solutions here:

1. Since there's no way you can alter the synchronization of the Daily series when operating in the Weekly scale, just modify/run your weekly strategy in the Daily timeframe, ignoring trade processing except on the last day of the week. Create your Weekly A/D sum manually.

2. The most direct way though is to use Index-Manager to create your A/D line. If you do it this way, when you GetExternalSymbol all values of the OHLC/V will be the same. The important difference, however, is that the Volume Series has its SumOnCollapse property set to true. That means when it is synchronized on a scale higher than the base scale, the values will be summed instead of just choosing the last value in the period to synchronize.

To see it in action, create an A/D line in Index Manager on the S&P 100 DataSet, for example. Run the following script in the Daily and then the Weekly scale. You'll see that in the daily case, the plotted series for ad.Close and ad.Volume are the same. But then look what happens when you run in the Weekly scale. Voila.

CODE:
Please log in to see this code.

In summary, the recommended solution is to:
1. Create your single-value indicator using Index-Lab
2. In a higher time frame script, access the indicator using GetExternalSymbol, but use the .Volume series for the indicator value.
profile picture

ecorderob

#13
Wow, nice workaround :)

I will try it. Thanks a lot!
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).