![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Sep 2011
Posts: 49
Thanks: 2
Thanked 5 times in 5 posts
|
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;
Thanks! |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Sep 2011
Posts: 49
Thanks: 2
Thanked 5 times in 5 posts
|
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. |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Sep 2011
Posts: 49
Thanks: 2
Thanked 5 times in 5 posts
|
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?
|
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
ds1111, the tick that closes the bar is seen and processed when the FirstTickOfBar is triggered - it's the same tick.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Member
Join Date: Sep 2011
Posts: 49
Thanks: 2
Thanked 5 times in 5 posts
|
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...! |
|
|
|
|
|
#8 |
|
Member
Join Date: Sep 2011
Posts: 49
Thanks: 2
Thanked 5 times in 5 posts
|
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). |
|
|
|
|
The following user says thank you to ds1111 for this post: |
|
|
|
#9 | |
|
Senior Member
|
Quote:
|
|
|
|
|
|
The following user says thank you to koganam for this post: |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |