How To Declare an Array?
Author: Assenzio
Creation Date: 1/25/2011 5:09 PM
profile picture

Assenzio

#1
I need to fill an array with some dates by opening a txt file. How to declare an array and matrix in C# and how to move inside it with WLD ?

This, i.e., declare an array of 30 issues that contain only dates in the yyyymmgg format ?

CODE:
Please log in to see this code.


I should access always as events[1] for element one ? What form matrix ?
profile picture

Cone

#2
profile picture

Eugene

#3
Just like in C#. WealthScript == C#.

I'm a Wealth-Lab 3/4 user, how to learn C# ?
C# Array Overview
C# File Overview

And take a look in Community.Components, search on the forums first - chances are, an example of filling an array with dates have already been coded.
profile picture

Assenzio

#4
Oh, fine. Thank You.
profile picture

Assenzio

#5
One more hint, please. I wrote the code below. It should (when finished) fill an array with dates that are contained, in the yyyymmaa, one after another in the txt file. I found the TryParse to convert the strings coming from the file to int ... but ... in this manner it will be in the correct date format so that, when I'll try, in a future loop, to look for equal dates (such as Date[bar] = Events[counter]), it works ? Is there a better way to convert that strings dates into the txt files into real dates prepared to be accessed easily in WLD ?

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

Eugene

#6
Let's ask the other way.

First, why would you want to convert dates to Int32 (integer) when there's more convenient DateTime?

And what's the point of storing dates in an array? There are helpful generic collections in .NET, maybe we could suggest a more efficient way of doing that something?
profile picture

Assenzio

#7
QUOTE:
First, why would you want to convert dates to Int32 (integer) when there's more convenient DateTime?


Because I am still trying to figure out how the language changed from V.4 to V.6 :) Okay I have initialized the array as follow:

CODE:
Please log in to see this code.


QUOTE:
And what's the point of storing dates in an array? There are helpful generic collections in .NET, maybe we could suggest a more efficient way of doing that something?


This is because I need to make buy decision based on date events after some macro releases. As you know macro data are always stored as "end of month", but the effective release date is different. Since I do not maintain a file with macro effectve dates of release (I'll catch them up manually when I need and store the information for future uses) I need to buy after some events based on a group of specific dates stored into a txt file. My txt file comes as follow:

19980115
19990217
20030516
...
profile picture

Eugene

#8
If you could modify the source text file to contain just an extra column, then the task could be simplified by using this method from Community.Components:

FillSeriesFromFile
profile picture

Assenzio

#9
Sorry Eugene, but my purpose is not to fill a series ... but an array. Filling a series will not help me (correct me if I am wrong) in what I have written before (buying at only specific dates). So what I need, and I still do not understand how to do it, is to convert that STRING date yyyymmgg (coming from the file) into a DateTime format. The TryParse does not work in the way I am using it. Any suggestion ?
profile picture

Eugene

#10
QUOTE:
Filling a series will not help me (correct me if I am wrong) in what I have written before (buying at only specific dates).

Let me expand on my idea a bit. On a macro release date, you save both the date and a value e.g. 19980115,1. That becomes your "binary wave" DataSeries: a "1" means there was a release on this date, and "0" will be automatically added to all dates in between when WL performs series synchronization.

So the idea is to enter when the DataSeries value changes. If you decide that it's not helpful then we'll move on to fixing your code.
profile picture

Assenzio

#11
Nice workaround, think could work on it for the moment.

But, anyway, I am interested to understand how to convert a date into a string. In WLD4 was so easy: DateToStr or StrToDate ...
profile picture

Eugene

#12
1 - There's a standard method .ToString() supported by any object in .NET.

2 - Convert.ToDateTime(), DateTime.TryParse, DateTime.ParseExact.
profile picture

Assenzio

#13
Using the FillSeries I have this error:

CODE:
Please log in to see this code.


The type or namespace name SeriesHelper could not be found (?!?) ... is inside the protected override void Execute() and I am using the up to date community components.
profile picture

Eugene

#14
Missing reference to Community.Components.
CODE:
Please log in to see this code.
profile picture

Assenzio

#15
Thank you. I little more help, now I have stored the data in this way:

CODE:
Please log in to see this code.


Now in the buy loop how I can tell the script to buy when Events close is 1 ?

I have written:

CODE:
Please log in to see this code.


But does not work: the dates exists and no buy signal appeared... Events series and primary series should be synch so I do not have to check also for equal dates, right ? Just if the "close" of Events is 1 ...
profile picture

Assenzio

#16
Sorry, my mistake, as always :) Everything fine now ... nice method, I like it !
profile picture

Eugene

#17
Will this work?
CODE:
Please log in to see this code.

CODE:
Please log in to see this code.

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

Assenzio

#18
Everything's fine. Next step now is exporting every single trade life (%), average them all, create a new series starting from the last buy signal date (that runs in the future) and ... plot it on the chart ! A sort of an average forecast based on previous market behaviour. More help maybe needed, talk to ya this evening or tomorrow.

Thank you very much.
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).