NinjaTrader Support Forum  

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 11-18-2007, 03:31 PM   #1
z32000
Member
 
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
Default basic help on program a strategy

if I just wanted to create a strategy in which,

at a particular time (editable), open 1 position (long or short) with a limit of X and stop of Y...
then close the position if limit has not been reached and position is still in the green (has made a slight gain) by a particular time.


thanks
z32000 is offline  
Reply With Quote
Old 11-18-2007, 04:20 PM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Welcome to the forum.

I suspect you are new to strategy development with NinjaTrader? What I would suggest is starting off with the strategy development tutorials in the Help Guide. There are two in there that will help you get started.

If you are not a programmer and will be using the Strategy Wizard, check out the Help Guide sections on the Strategy Wizard. There are many basic examples along with some video tutorials.

Once you have done this, start off small and create a strategy that has only one condition in it. Then add layer onto layer until you finally reach what you want.
NinjaTrader_Ray is offline  
Reply With Quote
Old 11-18-2007, 05:42 PM   #3
z32000
Member
 
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
Default

thanks for the reply...

I actually went through the help files...

how do I get the condition builder to create a true condition statement at 9:30am go long and then at 4:15 close position...

would that mean... select the time with a value of 9:30am and the symbol "==" to the time with a value of 9:30am
then add the action to go long?

and then do the same for 4:15? I'm a little confused but then go short?
z32000 is offline  
Reply With Quote
Old 11-18-2007, 06:14 PM   #4
z32000
Member
 
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
Default

I'm willing to pay someone to teach me a few basics...
sorta in a hurry to learn...
z32000 is offline  
Reply With Quote
Old 11-18-2007, 10:06 PM   #5
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Hi z32000,

Please check out this reference sample here. http://www.ninjatrader-support.com/v...ead.php?t=3226

It demonstrates a similar concept to what you want that you can copy paste and tweak. What you want to do is apply a time filter to your trades basically.

Code:
if(ToTime(Time[0]) == 93000)
{
     EnterLong();
}
if(ToTime(Time[0]) == 161500)
{
     ExitLong();
}
To create this through the condition builder you would want to select the Time series value on the left hand side and input a Time value on the right hand side. At the moment this will not work because there is a bug with the condition builder, but in the next release it should be fixed.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-19-2007, 06:19 AM   #6
z32000
Member
 
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
Default optimizing

Thanks Josh, actually I figured this out over the weekend. In regards to optimizing this strategy to get the most profit by testing various times to enter and exit a position. How do I go about doing this? Thanks for the help


Quote:
Originally Posted by Josh View Post
Hi z32000,

Please check out this reference sample here. http://www.ninjatrader-support.com/v...ead.php?t=3226

It demonstrates a similar concept to what you want that you can copy paste and tweak. What you want to do is apply a time filter to your trades basically.

Code:
if(ToTime(Time[0]) == 93000)
{
     EnterLong();
}
if(ToTime(Time[0]) == 161500)
{
     ExitLong();
}
To create this through the condition builder you would want to select the Time series value on the left hand side and input a Time value on the right hand side. At the moment this will not work because there is a bug with the condition builder, but in the next release it should be fixed.
z32000 is offline  
Reply With Quote
Old 11-19-2007, 10:22 PM   #7
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Create a user definable parameter for enterTime and exitTime. Then instead of the previous code I pasted try using this:
Code:
if (ToTime(Time[0]) == enterTime)
{
     EnterLong();
}
if (ToTime(Time[0]) == exitTime)
{
     ExitLong();
}
Then use the Strategy Analyzer's optimize on those parameters. I would imagine it would take quite awhile optimize and it might come up with funky results because you are running strictly on time intervals.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-19-2007, 10:55 PM   #8
z32000
Member
 
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
Default

thanks very much Josh

I'm assuming by user definable parameter, you mean something like
int enterTime=930000; //does this go in OnBarUpdate()?

also, I've tried to run backtests on simple code...for some reason, it does not always seem to put in a position on ES futures a few minutes after midnight or where the volume is low. Is there an option to force it to enter that trade even with a low volume. I don't think there is a mistake in the code since the trade would work at hours times except when the volume is low.


Quote:
Originally Posted by Josh View Post
Create a user definable parameter for enterTime and exitTime. Then instead of the previous code I pasted try using this:
Code:
if (ToTime(Time[0]) == enterTime)
{
     EnterLong();
}
if (ToTime(Time[0]) == exitTime)
{
     ExitLong();
}
Then use the Strategy Analyzer's optimize on those parameters. I would imagine it would take quite awhile optimize and it might come up with funky results because you are running strictly on time intervals.
z32000 is offline  
Reply With Quote
Old 11-19-2007, 11:00 PM   #9
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

In the Variables section add:
private int enterTimeFrame = 93000;

in the Properties section near the end add:
[Description("Starting Time for Trading (HHMMSS)")]
[Category("Parameters")]
public int EnterTimeFrame
{
get { return enterTimeFrame; }
set { enterTimeFrame = Math.Max(0, value); }
}

I don't know what your code is exactly. You can check volume by running comparisons against the volume series.
Code:
if (Volume[0] > 10000)
     EnterLong();
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-23-2007, 07:44 PM   #10
z32000
Member
 
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
Default

this sounds like a basic question...

but say if I wanted to get the current date of the first day...

so for example

FirstTradingDay=(ToDay(ToTime[0]));

where do I put this in order for it to only run once (instead of having it update the current day in the OnBarUpdate function all the time)?

Thanks
z32000 is offline  
Reply With Quote
Old 11-23-2007, 07:59 PM   #11
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Add it in the OnBarUpdate() but have a bool variable that prevents it from running multiple times. Or you can also use the CurrentBar variable to check.

Code:
if (firstBar == true)
{
     FirstTradingDay = ToDay(Time[0]);
     firstbar = false;
}
NinjaTrader_Josh 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
Basic Alerts yimbot Miscellaneous Support 9 12-15-2008 12:05 PM
Common Language Runtime detected an invalid program. VagyokC4 Miscellaneous Support 3 10-15-2007 12:25 AM
program not responding JohnG Miscellaneous Support 1 09-13-2007 01:42 PM
Setting EntryHandling || EntriesPerDirection From Program Overridden by BackTest Parameters KBJ Strategy Analyzer 4 05-01-2007 07:24 AM
First program Problem Freddie Indicator Development 5 03-25-2007 09:51 AM


All times are GMT -6. The time now is 06:57 AM.