![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Jun 2010
Location: gold coast australia
Posts: 92
Thanks: 15
Thanked 6 times in 5 posts
|
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); |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,184
Thanks: 178
Thanked 301 times in 259 posts
|
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 |
|
|
|
|
The following 2 users say thank you to sledge for this post: |
|
|
|
#3 |
|
Member
Join Date: Jun 2010
Location: gold coast australia
Posts: 92
Thanks: 15
Thanked 6 times in 5 posts
|
thanks that looks better I will view those sites as well.
Thanks |
|
|
|
|
|
#4 | |
|
Senior Member
|
At first glance that seems correct except for your cast to string.
Quote:
That should be Code:
Time[0].DayOfWeek.ToString() != (Zdow); (notice the brackets, in red). |
|
|
|
|
|
The following user says thank you to koganam for this post: |
|
|
|
#5 | |
|
Senior Member
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 1,184
Thanks: 178
Thanked 301 times in 259 posts
|
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:
|
|
|
|
|
|
The following user says thank you to sledge for this post: |
|
|
|
#6 |
|
Member
Join Date: Jun 2010
Location: gold coast australia
Posts: 92
Thanks: 15
Thanked 6 times in 5 posts
|
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.
|
|
|
|
|
|
#7 |
|
Member
Join Date: Jun 2010
Location: gold coast australia
Posts: 92
Thanks: 15
Thanked 6 times in 5 posts
|
if (CrossAbove(EMA(Emafast), EMA(Emaslow), 1)
&& Time[0].DayOfWeek == DayOfWeek.ToString != (DayA) ![]() |
|
|
|
|
|
#8 |
|
Member
Join Date: Jun 2010
Location: gold coast australia
Posts: 92
Thanks: 15
Thanked 6 times in 5 posts
|
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.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |