NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 03-12-2012, 08:35 PM   #1
ds1111
Member
 
Join Date: Sep 2011
Posts: 49
Thanks: 2
Thanked 5 times in 5 posts
Default Last Tick of Range Bar

I'm building an indicator that needs to know when we reached the 'last tick' of the current Range bar. I can not use FirstTickOfBar, because at that point price has changed. I really need the calculation of my formula at the last tick of each bar (I also need CalculateOnBarClose = false).

This was the tentative code I came up with, but it does not work. Has someone come up with such a code? Seems that it would be quite useful, and should be included in the library.

Code:
int tickValue = (int) Math.Abs((High[0] - Low[0]) / TickSize);
if (BarsPeriod.Value == tickValue ) 
{ 
isLastTickOfBar = true;

}
else isLastTickOfBar = false; 
Any help?

Thanks!
ds1111 is offline  
Reply With Quote
Old 03-13-2012, 03:24 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

ds1111, in NT's event based framework the open tick of a bar would also the one that closed the prior one - so if you're in FirstTickOfBar couldn't you just reference a bar back further to work with the price values you need?
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 03-13-2012, 07:16 AM   #3
ds1111
Member
 
Join Date: Sep 2011
Posts: 49
Thanks: 2
Thanked 5 times in 5 posts
Default

Thanks Bertrand. That was what I first tried to do, but by them I missed my precious entry, because of timing (I would be already at the opening of the current bar), and my signal would be late (I was putting the 'entry' arrow in the previous bar, which would be late for my entry).


No, I need a code to tell me the last tick of the current bar. I feel I'm very close with the snipet above, it seems the problem to be something related to type casting. Someone with experience should be able to spot (i haven't programmed for a while).

Also, if you could let me know the code for painting range bars, I could derive my code from that I think.
ds1111 is offline  
Reply With Quote
Old 03-13-2012, 07:27 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

The code you presented would compile fine, but the main issue you face is this - in an event based framework the tick you seek to identify servers two functions, it close the bar and opens the next one, so once you determine the tick is seen to close the bar > you are already on the next bar. One potential way would be working with a lower series added here as an multi series script for looking inside the bigger Range bar you would work in.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 03-13-2012, 09:11 AM   #5
ds1111
Member
 
Join Date: Sep 2011
Posts: 49
Thanks: 2
Thanked 5 times in 5 posts
Default

But I realized there are 2 calls into OnBarUpdate... when before the bar closes, and the other with the firt tick of the next bar. What would be a simple code to recognize the bar will close I guess is my question?
ds1111 is offline  
Reply With Quote
Old 03-13-2012, 09:16 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

ds1111, the tick that closes the bar is seen and processed when the FirstTickOfBar is triggered - it's the same tick.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 03-13-2012, 10:15 AM   #7
ds1111
Member
 
Join Date: Sep 2011
Posts: 49
Thanks: 2
Thanked 5 times in 5 posts
Default

wow... didn't seem like that to me. I've been testing this, and I have print statements in my code, it seemed to me that it would print at, for example, on CL at 106.50 close (OnBarUpdate call), and 106.51 at if FirstTickOfBar at the next call of OnBarUpdate .
I will recheck that and come back to you.

Thanks again...!
ds1111 is offline  
Reply With Quote
Old 03-13-2012, 01:07 PM   #8
ds1111
Member
 
Join Date: Sep 2011
Posts: 49
Thanks: 2
Thanked 5 times in 5 posts
Default

ok... did some more testing... you are absolutely right....

In my code above, the fact that we achieved the range (e.g. 6 tick range) doesn't mean that it's the last tick of a bar, the last tick will be only when an extremity is reached and a new price beyond the 6 tick (FirstTickOfBar) in my example is reached.

So, I guess what i can do is to print an arrow yellow once the range has been achieved (as a pre-alert), and once the new bar opens I will change it's color to red (or green) for short (long).
ds1111 is offline  
Reply With Quote
The following user says thank you to ds1111 for this post:
Old 03-13-2012, 06:14 PM   #9
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,199
Thanks: 24
Thanked 1,225 times in 996 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by ds1111 View Post
Thanks Bertrand. That was what I first tried to do, but by them I missed my precious entry, because of timing (I would be already at the opening of the current bar), and my signal would be late (I was putting the 'entry' arrow in the previous bar, which would be late for my entry).


No, I need a code to tell me the last tick of the current bar. I feel I'm very close with the snipet above, it seems the problem to be something related to type casting. Someone with experience should be able to spot (i haven't programmed for a while).

Also, if you could let me know the code for painting range bars, I could derive my code from that I think.
If you look properly into the nature of Range Bars, because they are independent of time elapsed, you will see that the next bar always starts at least one tick beyond the confines of the previous bar. Therefore, you really only have 2 choices:
  1. Use FirstTickofBar, and reference the Close[1], which means that the signal will always be 1 tick from the entry one way or another;
  2. As the range of a Range Bar is exactly known, use High[0] - Low[0] = BarsPeriod.Value. Of course, this has the disadvantage that the bar may not tick beyond its range, so that your entry can be the last tick before reversal, putting you in at the very worst price.
Not exactly a Hobson;s choice, but pretty much what it is, is what it is.
koganam is offline  
Reply With Quote
The following user says thank you to koganam for this post:
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
Mixed 5-min/3-tick range bar dead space zstheorist Charting 7 01-13-2011 04:58 AM
what controls the start of the initial bar in a range bar chart tulanch Charting 1 09-28-2010 10:35 PM
Volume, range, tick bar jamesaq Version 7 Beta General Questions & Bug Reports 9 09-13-2010 09:06 AM
range bar tick counter upsndowns Indicator Development 3 08-01-2010 08:20 AM
How to tell the last tick of the Range Bar xewoox Strategy Development 3 02-24-2009 08:09 AM


All times are GMT -6. The time now is 08:52 AM.