Finding and comparing Dates in C#
Author: tedclimo
Creation Date: 8/7/2010 6:23 PM
profile picture

tedclimo

#1
This is very embarassing to ask, but it's so simple in 4.5 & I am pulling my hair out with 5.6. I've tried a dozen different 5.6 approaches but cannot get the syntax right.
Here's the importance of it, as well as the 4.5 code.
"Tsunami Days"(days when dip models generate oodles of trades) generally require different Entry / Exit rules than "Quiet Days" when only a very few trades present.
So I prefer to use alternate Entry/Exit rules for each.

For historical study purposes in 4.5, it's very easy:.... code for a few of the dates I have identified are below:

Am sure is just as easy to code in 5.6, but I have yet to figure out the syntax req'd to find an equivalant.
Here is an example of three known Tsunami days in 4.5: Altogether, I count 80ish TSU days since 2/25/07. Would gladly provide entire list in this thread upon request. Just saving space at the moment, to get 5.6 solution to my 4.5 approach.
Code below isolates a few Tsunami dates..... which can then be easily converted into "if not" in order to examine performance on 'non-TSU' dates. After that, you make your own determination, whether or not to vary Entry/Exit rules.
CODE:
Please log in to see this code.

Thanx in advance,
Ted!
profile picture

Eugene

#2
Check this out: Wealth-Lab Wiki FAQ | "Missing" features > "An equivalent WealthScript function can't be found". A tutorial link there will explain how to work with Dates in C#. Actually, there are tons of examples on the net e.g. C# DateTime Overview on dotnetperls.com.

This defines a new DateTime variable and specifies the date i.e. 2/27/2007:
CODE:
Please log in to see this code.

And this is the comparison:
CODE:
Please log in to see this code.
profile picture

tedclimo

#3
Eugene,
Perfect! And Thank You!!!
The 5.6 equivalant to my 4.5 code above works perfectly.
Variable(s) here
CODE:
Please log in to see this code.

Comparison below:
CODE:
Please log in to see this code.


Now all I have to do is add the other 77 dates!

Thanks again

Ted!
profile picture

Eugene

#4
QUOTE:
Now all I have to do is add the other 77 dates!

I didn't realize there are so many dates. Here's how to make your code more sane by entering all of them on one line (for example):
CODE:
Please log in to see this code.
profile picture

tedclimo

#5
You rock! I have almost finished coding it the "insane way'.... , but will program both methods (just for the experience). Be fun!
I have no formal training in either Pascal, nor C#. My trading success has come from building models by cutting/Pasting existing published code, then applying my own theories/experience to make them more profitable.

So forgive me when I seem to ask ignorant C# questions,... it's always b/c I could not find previously published code to accomplish what I set out to do. I am self-taught in Pascal using this same process over my past 10+ yrs using WLD 3.x/4.x.

The new method you just taught me is fantastic!!!
Thanks!!!!!

Never expected to hear from you/or anyone over the weekend.
DOUBLE THANKS!!!!!!!!
profile picture

tedclimo

#6
Eugene,
I inserted your revised method into a basic dip script.
Works perfectly when trading only dates I want it to.

But my code for telling not to trade those same dates is flawed somehow. i.e. To compare the Tsunami dates with non Tsunami dates:

Tsunami Date code that works perfectly is here:
CODE:
Please log in to see this code.


Non-TSU code that does not work is here:
CODE:
Please log in to see this code.


Entire script is here:
CODE:
Please log in to see this code.


Can you point out what I'm doing wrong with the "if not these dates, then trade" code?
profile picture

Eugene

#7
The foreach loop that adds the tsunami dates isn't closed properly. As a result, the main loop is incorrectly placed inside this loop:
CODE:
Please log in to see this code.

Close the foreach loop, then remove an extra closing brace "}" below and the code should work then.
profile picture

tedclimo

#8
Perfecto!
Thank you for the wisdom!!

All the best to you & yours!!!
Ted
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).