Translate Total Cyclic Package
Author: soniasrm
Creation Date: 12/21/2011 4:20 AM
profile picture

soniasrm

#1
Hi,

Could you please help me to translate this code, namely the "FindNamedSeries"?

CODE:
Please log in to see this code.


Thanks a lot
profile picture

Eugene

#2
If I didn't know your objective I'd suggest you look up FindNamedSeries and especially HasNamedSeries (also NamedSeries) in the QuickRef, the Bars object section.

However, knowing that you're not interested in NamedSeries but are merely trying to translate Total Cyclic Package, the answer is very different:
CODE:
Please log in to see this code.

As you see, you don't even need no FindNamedSeries.
profile picture

soniasrm

#3
I'm sorry, but could you explain me which code you're translating with these two lines?
profile picture

Eugene

#4
From your script in translation, of course.

Just give it a little thought:
QUOTE:
//-----------------------------------------------------------------------
//- FUNCTION: ForwardFillWithValue
//- This function is used to fill a series with whatever value is desired
//- forward with the input series, 'series'.
//-----------------------------------------------------------------------


The "5" in my code snippet is the "whatever value"
The "DataSeries ds" is the output of the ForwardFillWithValue.

You don't need no ForwardFillWithValue. Just create a new series and fill it with the value ("val" in your terminology). The shortest way to do it is shown above. Hope that helps.
profile picture

soniasrm

#5
Your two lines code translates the function ForwardFillWithValue? With the same names, can I substitute my old code to
CODE:
Please log in to see this code.
? It doesn't specify the startBar...
profile picture

Eugene

#6
Give it a try, and if having the startBar is really required, just create an extra loop by Bars from StartBar to Bars.Count-1 to assign the fixed value to the DataSeries. Just as the original code does.
profile picture

soniasrm

#7
Thanks. With the new explanation I understood better! But for maintain the values for bars before StartBar in Data Series "Series" we need
CODE:
Please log in to see this code.
, right?
profile picture

Eugene

#8
Almost; in the loop it would be ForwardFillWithValue[bar] = Series[bar].
profile picture

soniasrm

#9
ok, thank you. Regarding the code from "Total Cyclic Package", is it right the translation to
CODE:
Please log in to see this code.
from
CODE:
Please log in to see this code.

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

Eugene

#10
The DataSeries should be shifted to the right >> (not to the left <<).
profile picture

soniasrm

#11
Are you sure? I'm asking because in the WL4 QuickRef, we have for the OffSetSeries function: "Offsets the specified Price Series by a certain number of Bars and returns the handle to a new Price Series. Use a negative offset value to shift the Price Series to the right on the chart. Shifting a moving average to the right often leads to cleaner signals. " So I think that DataSeries should be shifted to the left (because (p2-1)/2>0 ). Thank you
profile picture

Eugene

#12
Please note that we are talking Wealth-Lab v6 here, and the QuickRef for the DataSeries Object contains unambiguous instructions on properly shifting a DataSeries.
profile picture

soniasrm

#13
Hello, nobody have the translation from "Total Cyclic Package" referred before from WL4 to WL V6? I've been trying but without sucess yet.

Thanks
profile picture

Eugene

#14
When manually converting a complex script like Total Cyclic Package v3.0 (Centered SMA), a good technique is to break it down into smaller pieces so that you can concentrate on a manageable chunk of code. Start with a DataSeries, or with a segment, verify that it works, then proceed to the next one.

P.S. Just noticed that I left your question regarding Correlation unanswered. Yes, the translation seems right except that I'm not sure about the "+1" part since it's missing in the original code.
profile picture

soniasrm

#15
ok, thank you. Regarding the offset, when I have the following code, what is the lenght of serie ma202: (Lastbar - (p2 - 1) / 2) or (Lastbar - (p20 - 1) / 2)?
CODE:
Please log in to see this code.

profile picture

Eugene

#16
All DataSeries contain the same number of values as bars in the chart. Otherwise please clarify the meaning of "length".
profile picture

soniasrm

#17
So, regarding the last code,

- serie SMA.sERIES(AVG,P2) have "Bars.Count = Lastbar" bars, with the first p2 bars with value 0
- series ma2 have "Lastbar" bars, with the last (p2-1)/2 bars with the value 0, and with the first (p2-1)/2 bars with value 0, and the same for ma202 if p20<p2.

Thank you
profile picture

Eugene

#18
No. Shifting a DataSeries does not affect the number of bars in it -- only the values are being moved.
profile picture

soniasrm

#19
Could you confirm this translation? WL4 Round uses the "Bankers Rounding", is WL6 using it too?

WL6
CODE:
Please log in to see this code.


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

Eugene

#20
QUOTE:
Could you confirm this translation?

As I don't have WL4 installed for quite a time now, I'm leaving the task of comparing results produced by the two scripts up to you.
QUOTE:
WL4 Round uses the "Bankers Rounding", is WL6 using it too?

To find out simply visit the MSDN website and look the Round method. It's answered there.
profile picture

soniasrm

#21
Hi. I need to calculate the serie cor, to obtain cor[ebar], for each j, from sbar to ebar. However, with the code below I obtain allways the same cor[ebar]. How can I clear the values in the serie cor in the end of the "for (j)"? With this problem solved, I have the Cyclic Package completely translated. Thank you.
CODE:
Please log in to see this code.
profile picture

Cone

#22
Ideally, a Value method would be available for this, but the documentation syntax doesn't even correctly specify the Series method either. Anyone who is motivated could work on the Value method for this indicator... it's open source you know!
profile picture

soniasrm

#23
Are you talking about this: public double Correlation(double[] x, double[] y, int n)
?
profile picture

Eugene

#24
Cone is talking about this:

Wealth-Lab Version 6 (.NET) Development Guide > "Create an Indicator Library" > "Providing a Static Value Method"
profile picture

soniasrm

#25
But for find a correlation as a value? Or for all Cycle package? Now, I only need a method for clear the "cor" serie after the code below, for to calculate a new "cor" serie, with another j.

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

Eugene

#26
Out of curiousity, what's the point in adding that +1 even though it's not in the source chartscript and your loops operate with the same start/end values?
CODE:
Please log in to see this code.

QUOTE:
However, with the code below I obtain allways the same cor[ebar].

Substitute the Correlation with a vanilla series like SMA. Does the problem persist? If it does, the problem might be elsewhere.
profile picture

soniasrm

#27
Yes, it does. I know that problem isn't in the calculation of correlation, it is because in the cycle "for j" the serie "cor" is allways the same, for j=sbar, ..., ebar, but it dependes of serie "sine1" that is different for each j. I think a method for clear the "cor" serie in the end of cycle "for j" solve the problem. May be a similar code to RestoreScale, but only for one serie. Coul you help me please? Thanks a lot.
profile picture

Eugene

#28
I'll second Cone's idea and suggest you to calculate Correlation on-the-fly in this part of the code. The easiest way to do it is by adding the CORREL method shared by DartboardTrader in this thread (click) in his post dated 3/30/2009 3:33 PM. So, use it simply as you would use Correlation.Value if it existed.
profile picture

soniasrm

#29
Eugene,
Thanks for the sugestion, I tried that, without sucess, though. However, I obtain good results for this part of the code with the Bars.Cache.Clear(), dispite the long time running.... Is it a good solution, or should I try once again the CORREL method by DartboardTrader? Thanks

CODE:
Please log in to see this code.


About your curiosity, in the original code we have float number from cor:=Correlation( cycle1, sine1, sbar, ebar ), so that the period for calculate the correlation is since sbar until ebar (including, I supposed) which corresponde to ebar - sbar + 1 bars (if sbar = 1 and ebar = 1, we have the correlation of two series with only 1 entrance each).
profile picture

Eugene

#30
I'd do it using the CORREL function but whatever works for you is automatically fine with me. ;)
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).