Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
current intra bar. how to code it
Collapse
X
-
current intra bar. how to code it
there is something i see time in time again. but, i can only take advantage of it if i can program the present bar. is there a way to do that? i don't want to look at [0], or farther back. just the present intra bar. high above a line and price below a line..enter.Tags: None
-
Hello SteveReiza,
Thank you for your post.
To process your script on the currently forming bar, you would reference 0 barsAgo but the script needs to be set to calculate either OnPriceChange or OnEachTick rather than OnBarClose. For more information regarding the Calculate property:
Please let us know if we may be of further assistance.Emily C.NinjaTrader Customer Service
-
thanks for the reply. i thought 0 bars ago was the most recently closed bar? that was just told to me. in fact i just re-did all my code because of that. i did think that [0] is the current bar that's active.
i just received explanation that on bars close. that when a determination is made. the execution happens at the start of the next bar not immediately. this conversation led to hearing that 0 bars ago is the most recently closed bar. and [1] is 1 bar ago behind that, etc.
Comment
-
Originally posted by SteveReiza View Postthanks for the reply. i thought 0 bars ago was the most recently closed bar? that was just told to me. in fact i just re-did all my code because of that. i did think that [0] is the current bar that's active.
i just received explanation that on bars close. that when a determination is made. the execution happens at the start of the next bar not immediately. this conversation led to hearing that 0 bars ago is the most recently closed bar. and [1] is 1 bar ago behind that, etc.
Thank you for your reply.
0 bars ago refers to different bars when calculating OnBarClose vs. OnPriceChange/OnEachTick. This is because the calculation determines how frequently OnBarUpdate() is called. When it is only called on bar close, 0 bars ago (the "current bar") is the most recently closed bar. When it is called for every change in price or every tick, it gets called even after the last bar closes and will continue to be called during the currently forming bar which is 0 bars ago (the "current bar").
For a visual example, you could add an indicator to your chart such as the SMA. Set the indicator to calculate On Bar Close, and you will notice that the indicator only updates once per bar. If you were to print the indicator's value for 0 bars ago, you would get one print on each bar as it closes. Now, change calculate to On Price Change or On Each Tick; the indicator plot will continue to update as the price changes on the currently forming bar. If you were to print the indicator's value for 0 bars ago, there would be a print for each price change or each tick as the current bar (0 bars ago) is continuously forming.
Thank you for your time and patience.Emily C.NinjaTrader Customer Service
Comment
-
thanks for the reply. okay, i'm tracking. the clarification helps. and, that makes sense.
i did have if low is within so many of bollinger line [2] and then [1] as the candle in respect to the previous. i respects to the previous candle: high greater than high, close greater than close, low greater than open. but on bar close. it wouldn't enter until the next candle so that doesn't make sense. it would be way too late. so i now have it as [1] within so many of the bollinger line. and, [0] as comparison to the candle. will that make sense though? i'm comparing low to previous open and high to previous high and close to previous close on the current bar - that moves and calculates intra bar. its not complete yet, so the low technically could be lower then the previous open at some time during the bar - right? or is it going to wait until the bar is finished since its asking for low, high and close? that's not technically there until after completion of the bar right?
Comment
-
Hello SteveReiza,
Thank you for your reply.
It will not wait for the bar to finish if you are calculating On Price Change or On Each Tick and accessing the Open, High, Low, or Close price. I suggest using prints to get a deeper understanding of how the prices are updated as the bar is forming. You are correct that, since the bar is not complete yet, at some point intrabar the low could become lower than the previous open at some point during the bar.
If you need to separate some of your logic so that it is calculating intrabar on the price change or on each tick and other logic so that it is calculating on bar close, you could utilize IsFirstTickOfBar in your condition:
In the Strategy Builder, you can find IsFirstTickOfBar in the Miscellaneous folder and you can check if Misc > IsFirstTickOfBar Equals Misc > True:
Any set that contains this condition would be processed on the close of a bar instead of continuously calculating intrabar.
Please let us know if we may be of further assistance.Emily C.NinjaTrader Customer Service
Comment
-
thanks for the reply. that might make sense. i'm trying to have [1] and [2] be on bar close. then [0] intra bar. i don't want it to calculate anymore on [1] and [2] after the bar closes. where would i put isfirsttickofbar in that scenario?
Comment
-
Hello SteveReiza,
Thank you for your reply.
I'm not sure exactly what you are referring to. Are you using numbers in brackets as barsAgo indexes? IsFirstTickOfBar would be used for any condition that you only want to be executed on the close of a bar. For example, you could add a print statement that only prints to the NinjaScript Output window once per bar. Here are some prints you could use in a script that updates On Price Change and see the difference between prints on bar close vs. on price change:
Code:// print once on the close of each bar if (IsFirstTickOfBar) Print(Time[0] + " This print shows once per bar."); // print once on each update of the price Print(Time[0] + " Price updated. Close[0]: " Close[0]);
Emily C.NinjaTrader Customer Service
Comment
-
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by ZeroKuhl, Today, 04:31 PM
|
0 responses
7 views
0 likes
|
Last Post
by ZeroKuhl
Today, 04:31 PM
|
||
Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
|
54 responses
5,336 views
0 likes
|
Last Post
by Gaterz
Today, 04:29 PM
|
||
Started by ETFVoyageur, 05-07-2024, 07:05 PM
|
11 responses
73 views
0 likes
|
Last Post
by -=Edge=-
Today, 04:27 PM
|
||
Started by _Zero_, 04-10-2020, 03:21 PM
|
145 responses
7,899 views
6 likes
|
Last Post
by johng2
Today, 04:19 PM
|
||
Started by TheTradingMantis, 01-19-2023, 02:05 AM
|
43 responses
921 views
0 likes
|
Last Post
by jmagaia
Today, 04:13 PM
|
Comment