![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#4 |
|
Member
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
|
I'm willing to pay someone to teach me a few basics...
sorta in a hurry to learn... |
|
|
|
|
|
#5 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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();
}
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#6 | |
|
Member
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
|
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:
|
|
|
|
|
|
|
#7 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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();
}
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#8 | |
|
Member
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
|
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:
|
|
|
|
|
|
|
#9 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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();
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Member
Join Date: Nov 2007
Posts: 37
Thanks: 0
Thanked 0 times in 0 posts
|
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
|
|
|
|
|
|
#11 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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;
}
Josh
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |