View Full Version : How to hold a position for half hour?
Jenny
10-11-2007, 01:36 PM
I would like to hold a position for half hour at least half hour, how to do that?
Thanks
NinjaTrader_Ray
10-11-2007, 01:51 PM
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/HelpGuideV6/ConditionBuilder-TimeComparisons.html
If you are coding it in the NinjaScript Editor please see the following reference sample - http://www.ninjatrader-support.com/vb/showthread.php?t=3226
You can also work with the BarsSinceEntry() method to determine how many bars have elapsed.
Jenny
10-11-2007, 02:04 PM
Thanks for your fast respone.
Take care
Jenny
10-23-2007, 04:49 AM
"BarsSinceEntry()" is a very good, do you have others "BarsSince...." , like
BarsSinceCrossAbove(SMA(5), SMA(10))?
Thanks
NinjaTrader_Ray
10-23-2007, 06:29 AM
You could try MRO.
http://www.ninjatrader-support.com/HelpGuideV6/MostRecentOccurenceMRO.html
Jenny
10-23-2007, 04:08 PM
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
NinjaTrader_Ray
10-23-2007, 04:31 PM
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/vb/showthread.php?t=3418
Jenny
10-23-2007, 04:43 PM
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
NinjaTrader_Josh
10-23-2007, 04:47 PM
Are you getting any errors in your logs?
Jenny
10-23-2007, 06:26 PM
No error either. Can you do some test in your side?
Thanks
NinjaTrader_Josh
10-23-2007, 08:10 PM
Sure Jenny.
NinjaTrader_Josh
10-23-2007, 08:18 PM
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:
Download the file contained in this thread to your PC desktop
From the Control Center window, select the menu File > Utilities > Import NinjaScript
Select the downloaded file
Jenny
10-23-2007, 09:14 PM
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
NinjaTrader_Josh
10-23-2007, 09:17 PM
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.