NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM 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 10-11-2007, 01:36 PM   #1
Jenny
Member
 
Join Date: Jun 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default How to hold a position for half hour?

I would like to hold a position for half hour at least half hour, how to do that?

Thanks
Last edited by Jenny; 10-11-2007 at 01:53 PM.
Jenny is offline  
Reply With Quote
Old 10-11-2007, 01:51 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

Hi Jenny,

If you are working with the Condition Builder please review the information at the following link regarding time comparisons - http://www.ninjatrader-support.com/H...mparisons.html

If you are coding it in the NinjaScript Editor please see the following reference sample - http://www.ninjatrader-support.com/v...ead.php?t=3226

You can also work with the BarsSinceEntry() method to determine how many bars have elapsed.
NinjaTrader_Ray is offline  
Reply With Quote
Old 10-11-2007, 02:04 PM   #3
Jenny
Member
 
Join Date: Jun 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks for your fast respone.
Take care
Jenny is offline  
Reply With Quote
Old 10-23-2007, 04:49 AM   #4
Jenny
Member
 
Join Date: Jun 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

"BarsSinceEntry()" is a very good, do you have others "BarsSince...." , like
BarsSinceCrossAbove(SMA(
5), SMA(10))?
Thanks
Jenny is offline  
Reply With Quote
Old 10-23-2007, 06:29 AM   #5
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

You could try MRO.

http://www.ninjatrader-support.com/H...urenceMRO.html
NinjaTrader_Ray is offline  
Reply With Quote
Old 10-23-2007, 04:08 PM   #6
Jenny
Member
 
Join Date: Jun 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

MRO is very cool, but the first one works, the second one doesn't work.
LowBar1 =MRO(delegate {return (CrossBelow(SMA(5), SMA(10), 1));},1, 1440) return some number, but
HighBar1 =MRO(delegate {return (CrossBelow(SMA(5), SMA(10), 1));},2, 1440); return nothing, even not a "-1".

Would you please tell me why?

Thanks
Last edited by Jenny; 10-23-2007 at 04:14 PM.
Jenny is offline  
Reply With Quote
Old 10-23-2007, 04:31 PM   #7
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

If you mean that it does not work in that it only returns a value of -1, then likely the condition is never met. You will likely spend some time debugging to understand what is happening.

If it does not work in terms of throwing exception (error message in the log tab of the Control Center window) then let me know.

Here is some information to help you debug. http://www.ninjatrader-support.com/v...ead.php?t=3418
NinjaTrader_Ray is offline  
Reply With Quote
Old 10-23-2007, 04:43 PM   #8
Jenny
Member
 
Join Date: Jun 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

I already use debug, it return nothing, even not "-1". If never met the condition, it should return "-1". And I can see the condition is met by the chart. Within 1440 bar, SMA(5) Cross over SMA(10) hundreds times! Do you think there is a bug some where?

Thanks
Jenny is offline  
Reply With Quote
Old 10-23-2007, 04:47 PM   #9
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Are you getting any errors in your logs?
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-23-2007, 06:26 PM   #10
Jenny
Member
 
Join Date: Jun 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

No error either. Can you do some test in your side?
Thanks
Last edited by Jenny; 10-23-2007 at 08:02 PM.
Jenny is offline  
Reply With Quote
Old 10-23-2007, 08:10 PM   #11
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Sure Jenny.
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-23-2007, 08:18 PM   #12
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

After some tests there is nothing wrong with the MRO. Please check out the reference sample I've attached. Try running it on your end. You should see two plots like how it looks in the attached image.

I suspect it to be a bug in your code somewhere since there seems to be no issue with this simple-as-possible indicator using MRO.

To install the reference sample please follow these steps:
  1. Download the file contained in this thread to your PC desktop
  2. From the Control Center window, select the menu File > Utilities > Import NinjaScript
  3. Select the downloaded file
Attached Images
File Type: jpg ER2 12-07 10_12_2007 (1 Min).jpg (37.1 KB, 23 views)
Attached Files
File Type: zip MROTest.zip (3.1 KB, 17 views)
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-23-2007, 09:14 PM   #13
Jenny
Member
 
Join Date: Jun 2007
Posts: 72
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks for your sample. It looks work in the indicator, but how come when I try to use it in my Strategy, it doesn't work.:
HighBar1 =MRO(delegate {return (CrossBelow(SMA(5), SMA(10), 1));},2, 1440);

Take care
Jenny is offline  
Reply With Quote
Old 10-23-2007, 09:17 PM   #14
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

In the indicator I used your exact line of code. You are going to need to debug your code to see where it is failing. I suspect you probably placed the line within an if statement that is never executed. Thus causing your HighBar1 to never be set.
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
1st Hour High/Low pijamatrader Indicator Development 42 07-16-2007 05:31 PM
OHLC for non-midnight 24 hour market StinkiePhish Indicator Development 1 07-12-2007 11:07 PM
V 5.1.1.1 Beta Problem - hold button reverses buy/sell columns dynosaratoga Installation and Licensing 7 02-17-2006 03:29 AM


All times are GMT -6. The time now is 06:13 PM.