NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 01-01-2012, 05:48 PM   #1
raefon72
Member
 
Join Date: Jun 2010
Location: gold coast australia
Posts: 92
Thanks: 15
Thanked 6 times in 5 posts
Default Day of week variable

Hi Guys,

I have got a copy of C# 2010 for dummies and am making an effort to do this myself. But I am short of time so am asking for some help to improve a strategy. I want to define a day of the week from a variable entry. I have set a variable int as zdaynot ( day not to trade ) numbered 1 to 6 and am trying to convert it to a string zdow
that has been set as a default of "na". But I am unsure on my if statement and conversion of the string.

Thanks Raef


&& (Zdaynot == 1)
{Zdow =
"Monday"};
&& (Zdaynot ==
2)
{Zdow =
"Tuesday"};
&& (Zdaynot ==
3)
{Zdow =
"Wednesday"};
&& (Zdaynot ==
4)
{Zdow =
"Thursday"};
&& (Zdaynot ==
5)
{Zdow =
"Friday"};
&& (Zdaynot ==
6)
{Zdow =
"Saturday"};

Time[
0].DayOfWeek.ToString != (Zdow);
raefon72 is offline  
Reply With Quote
Old 01-01-2012, 07:34 PM   #2
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,184
Thanks: 178
Thanked 301 times in 259 posts
Default

I don't think this is valid:

{Zdow = "Monday"};

I think you need something like:

{Zdow = new String ("Monday")};


I haven't tested this out. But I think it is your issue.
I can't find any examples of assignment like that.

http://www.techotopia.com/index.php/...ngs_in_C_Sharp

This might help some more:

http://stackoverflow.com/questions/6...ent-in-c-sharp
sledge is offline  
Reply With Quote
The following 2 users say thank you to sledge for this post:
Old 01-01-2012, 08:34 PM   #3
raefon72
Member
 
Join Date: Jun 2010
Location: gold coast australia
Posts: 92
Thanks: 15
Thanked 6 times in 5 posts
Default

thanks that looks better I will view those sites as well.


Thanks
raefon72 is offline  
Reply With Quote
Old 01-02-2012, 09:04 AM   #4
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,201
Thanks: 24
Thanked 1,226 times in 997 posts
Send a message via Skype™ to koganam
Default

At first glance that seems correct except for your cast to string.
Quote:
Time[0].DayOfWeek.ToString != (Zdow);


That should be
Code:
Time[0].DayOfWeek.ToString() != (Zdow);


(notice the brackets, in red).
koganam is online now  
Reply With Quote
The following user says thank you to koganam for this post:
Old 01-02-2012, 11:09 AM   #5
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,184
Thanks: 178
Thanked 301 times in 259 posts
Default

DayOfWeek in ninja help also has some information that could help you to shortcut


DayOfWeek



Definition
The day of the week of the current bar accessed through the Time property.

Property Value
A DayOfWeek type such as:
DayOfWeek.Monday
DayOfWeek.Tuesday
DayOfWeek.Wednesday
DayOfWeek.Thursday
DayOfWeek.Friday
DayOfWeek.Saturday
DayOfWeek.Sunday

Syntax
Time[int barsAgo].DayOfWeek


Examples

protected override void OnBarUpdate()
{
// If it's Monday, do not trade.
if (Time[0].DayOfWeek == DayOfWeek.Monday)
return;
}




Quote:
Originally Posted by raefon72 View Post
Hi Guys,

I have got a copy of C# 2010 for dummies and am making an effort to do this myself. But I am short of time so am asking for some help to improve a strategy. I want to define a day of the week from a variable entry. I have set a variable int as zdaynot ( day not to trade ) numbered 1 to 6 and am trying to convert it to a string zdow
that has been set as a default of "na". But I am unsure on my if statement and conversion of the string.

Thanks Raef


&& (Zdaynot == 1)
{Zdow =
"Monday"};
&& (Zdaynot ==
2)
{Zdow =
"Tuesday"};
&& (Zdaynot ==
3)
{Zdow =
"Wednesday"};
&& (Zdaynot ==
4)
{Zdow =
"Thursday"};
&& (Zdaynot ==
5)
{Zdow =
"Friday"};
&& (Zdaynot ==
6)
{Zdow =
"Saturday"};

c
.ToString != (Zdow);
sledge is offline  
Reply With Quote
The following user says thank you to sledge for this post:
Old 01-02-2012, 02:23 PM   #6
raefon72
Member
 
Join Date: Jun 2010
Location: gold coast australia
Posts: 92
Thanks: 15
Thanked 6 times in 5 posts
Default

I may have used an incorrect string or somthing I am unsure where I have gone wrong. I had to delete and start from the beginning because the compiler stopped me from working on other stuff.

Thanks Raef

// Condition set 1
if (Notrade1 == 1)
{
string DayA = new String("Monday");
}
if (Notrade1 == 2)
{
string DayA = new String("Tuesday");
}

if (CrossAbove(EMA(Emafast), EMA(Emaslow), 1)
&& Time[
0].DayOfWeek.ToString() != (DayA))
{
EnterLong(DefaultQuantity,
"");
}

{
EnterLong(DefaultQuantity,
"");
}
Last edited by raefon72; 01-02-2012 at 02:52 PM.
raefon72 is offline  
Reply With Quote
Old 01-02-2012, 03:04 PM   #7
raefon72
Member
 
Join Date: Jun 2010
Location: gold coast australia
Posts: 92
Thanks: 15
Thanked 6 times in 5 posts
Default I tried this also

if (CrossAbove(EMA(Emafast), EMA(Emaslow), 1)
&& Time[
0].DayOfWeek == DayOfWeek.ToString != (DayA)

raefon72 is offline  
Reply With Quote
Old 04-15-2012, 07:13 PM   #8
raefon72
Member
 
Join Date: Jun 2010
Location: gold coast australia
Posts: 92
Thanks: 15
Thanked 6 times in 5 posts
Default Got a final result for variable Day of week.

I have cut the parts out of the script I believe its all here.
Full strategy here http://www.raefontrading.com/strateg...-day-strategy/

Code:
 
private string dayOWstring = "Monday"; // Set day of week.
private bool dayOWon = false; // Have DayOW filter off by default.
private int dayOW = 1; // Sets a variable for Day of week 1 is Monday
 
 
protected override void OnBarUpdate()
 
{
if (dayOW == 1){dayOWstring = "Monday";}
if (dayOW == 2){dayOWstring = "Tuesday";}
if (dayOW == 3){dayOWstring = "Wednesday";}
if (dayOW == 4){dayOWstring = "Thursday";}
if (dayOW == 5){dayOWstring = "Friday";}
if (dayOW == 6){dayOWstring = "Saturday";}
if (dayOW == 7){dayOWstring = "Sunday";}
if (dayOW > 7){dayOWstring = "Sunday";}
 
 
if(dayOWon == true
&& Time[0].DayOfWeek.ToString() == (dayOWstring)
)
{
 
}
}
 
[Description("")]
[GridCategory("Parameters")]
public int DayOW
{
get { return dayOW; }
set { dayOW = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public bool DayOWon
{
get { return dayOWon; }
set { dayOWon = value; }
}
Last edited by raefon72; 04-15-2012 at 07:49 PM.
raefon72 is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
exit on friday or last day of week verge Strategy Development 18 05-09-2012 05:53 AM
Day of Week Color zweistein Indicator Development 2 02-10-2011 11:37 PM
Day of the Week highlight bars joshuas7 Indicator Development 4 02-10-2011 11:27 PM
Displaying the Day of the Week (DOW) NWT27 Indicator Development 4 11-09-2010 03:37 PM
Parsing trades per day of week gsmaster Strategy Development 3 07-24-2007 04:41 AM


All times are GMT -6. The time now is 11:45 AM.