![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Aug 2009
Location: Chicago
Posts: 213
Thanks: 39
Thanked 4 times in 4 posts
|
Howdy,
This is something I've been trying to get to work for some time within one of my automated strategies. It works ok the way I've done it, but I've noticed a bug as of late when running live. My goal is to take two times, and return the highest value into a variable using the MIN() or MAX() function. What I have done previously, is find the highest value, and say when time equals that value, look back x number of bars to return the highest value. So if time equals 14:00, and I want to return the highest and lowest values say in between 13:30-14:00 on a 5 minute chart I have done the following: Code:
if (ToTime(Time[0])== ToTime(14, 00, 0)) //gets the HH and LL between 13:30 and 14:00
{
HH1 = MAX(High,6)[0];
LL1 = MIN(Low,6)[0];
}
Now this works, but it is also limited. In that it's confusing when I want to adjust for various times cause I have to count bars, and it also does not work if I backtest with a different time frame because I would have to factor in the new time with the proper amount of bars. I think this can be done by using, "IDataSeries?" If not, is there a simple way to accomplish what I want to do w/o doing it the goofy/cumbersome way I have done it? Thanks, Forrest |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 90 times in 82 posts
|
Hi Forrest, there is a sample that demonstrates how to get an indicator's value for a certain time. The same concept would apply for just getting a bar's price data. The sample can be found here.
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Senior Member
Join Date: Aug 2009
Location: Chicago
Posts: 213
Thanks: 39
Thanked 4 times in 4 posts
|
Quote:
But I dont think this is what I want? What I want to do is return the highest value in between two times of the day. Not get the highest value at a certain time. I almost tried writing a loop for this, but I am hoping there is a simpler way to do it? |
|
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
I wouldn't write a loop either, Forrest. I would collect the data as the time progresses. And note, I used two TimeSpan variables to define the start- and stop-time. This way, you could implement these values as properties, just in case you think about optimizing these values too.
Regards Ralph Code:
double maxVal = Double.MinValue;
double minVal = Double.MaxValue;
TimeSpan startTime = new TimeSpan(13, 30, 0);
TimeSpan stopTime = new TimeSpan(14, 00, 0);
...
if (Time[0].TimeOfDay >= startTime && Time[0].TimeOfDay <= stopTime)
{
HH1 = Math.Max(maxVal, High[0]);
LL1 = Math.Min(minVal, Low[0]);
}
|
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
Ben
NinjaTrader Customer Service |
|
|
|
|
|
#6 | |
|
Senior Member
Join Date: Aug 2009
Location: Chicago
Posts: 213
Thanks: 39
Thanked 4 times in 4 posts
|
Quote:
|
|
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
Thanks Forrest. Here is one more thought which is of interest only if you are looking to tune the performance of your strategy. Time[0].TimeOfDay creates an anonymous object of type TimeSpan. This finally is compared with startTime/stopTime. In your case this instantiation happens twice. You could save a little time if you instantiate this object one time explicitely and then use it twice:
TimeSpan timeOfDay = Time[0].TimeOfDay; if (timeOfDay >= startTime && timeOfDay <= endTime) ... Regards Ralph |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Mar 2010
Posts: 321
Thanks: 88
Thanked 5 times in 5 posts
|
Hi guys, trying to work out the volume between 6 am and 7 am and struggling to convert it to a string. This is what I have so far but won't compile no matter what I do to it:
DrawText("Up1", true, (ToTime(Time[0])>= 70000 (Vol[0]- ToTime(Time[0])<= 80000 (Vol[0].ToString("N2")), -2, High[0] +80 * TickSize ,10, Color.Yellow, largeFont, StringAlignment.Near, Color.Red, Color.Red, 10); Any ideas on this one? Thanks DJ |
|
|
|
|
|
#9 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,566
Thanks: 261
Thanked 1,015 times in 996 posts
|
DJ, first I would take the time condition out of the DrawText statement. Next you seem to miss a few braces in the condition and Vol would be VOL() as NinjaScript is case sensitive. I would suggest you simplify the code line until it compiles for you and only then add more complexity....
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Mar 2010
Posts: 321
Thanks: 88
Thanked 5 times in 5 posts
|
Thanks Bertrand, well the problem is really stemming from how to calculate the total volume between a certain timeframe, and I can't find any reference on this. Ok so I have summed the volume for the last 20 periods only between the timeframe 6.30 am to 11 am. The problem is if I change the period to say 9 .30 am to 1100 am it stays the same because it's between those times. So it appears I need to have the Time in the string somehow. I have put the time in the string as per point 2 below but says I'm missing brackets no matter where I put the brackets doesn't compile. Am I on the right track with point 2 as there is nowhere around I can find how to do this.....
Cheers DJ Point 1. if (ToTime(Time[0]) >= 63000 && ToTime(Time[0]) <= 110000) { DrawText("Up1", true, SUM(Volume,20)[0].ToString("N0"), -15, High[0] +80 * TickSize ,10, Color.Yellow, largeFont, StringAlignment.Far, Color.Green, Color.Lime, 10); } Point 2. DrawText("Up5", true, SUM(Volume,20[0](ToTime(Time[0]&& SUM(Volume,20)[0].ToString("N0") <= 110000.ToString("N0"), -15, High[0] +30 * TickSize ,10, Color.Yellow, largeFont, StringAlignment.Far, Color.Green, Color.Lime, 10);
Last edited by djkiwi; 03-14-2011 at 01:54 PM.
|
|
|
|
|
|
#11 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,566
Thanks: 261
Thanked 1,015 times in 996 posts
|
DJ, I'm not sure what you're trying to express with this string -
SUM(Volume,20[0](ToTime(Time[0]&& SUM(Volume,20)[0].ToString("N0") <= 110000.ToString("N0") The Sum of Volume you calculate is not limited to a certain time range here, it's just calculating over the last 20 bars. You could for example run a custom calculation to add the volume to a double / dataseries for each bar for the time range you like to see, so that at the end of it you have the total for the period.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#12 |
|
Senior Member
Join Date: Mar 2010
Posts: 321
Thanks: 88
Thanked 5 times in 5 posts
|
Thanks Bertrand, yes I this is what I want to do:
"You could for example run a custom calculation to add the volume to a double / dataseries for each bar for the time range you like to see, so that at the end of it you have the total for the period" I am not sure how to do it, any references on it? Thanks DJ |
|
|
|
|
|
#13 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,566
Thanks: 261
Thanked 1,015 times in 996 posts
|
DJ, while I would unfortunately not have a full working sample - you can use something like the below - at the session begin it resets the tracking data series and then start to sum up the bar's volume:
if (Bars.SessionBreak) volSum.Set(0); else volSum.Set(volSum[1] + VOL()[0]);
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#14 |
|
Senior Member
Join Date: Mar 2010
Posts: 321
Thanks: 88
Thanked 5 times in 5 posts
|
Thanks Bertrand I am still working on this. As a related issue (I think it's related) I want to start an EMA calculation/plot from the start of the session not overlap with the previous day. Please have a look at the attached chart you can see the EMA is screwed up because the session finishes and then in the morning the start number is much less screwing up the EMA taking it awhile to catch up.
Thanks DJ |
|
|
|
|
|
#15 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,499
Thanks: 109
Thanked 291 times in 280 posts
|
Hello,
This gets a little more complex in how you would need to set this up. Quick question how many bars back is this EMA your running? I look forward to assisting you further.
Brett
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Previous session Max/Min | mdm72 | Strategy Development | 1 | 05-05-2009 05:38 AM |
| Min Max Values of Y-axis | roonius | Indicator Development | 1 | 02-14-2009 02:08 AM |
| Max/Min List | nfeldberg | General Programming | 2 | 07-16-2008 01:22 PM |
| MAX/MIN limits | Richard Von | Indicator Development | 3 | 07-30-2007 08:29 AM |
| Min / Max | mydet | Indicator Development | 1 | 05-31-2007 04:47 AM |