NexusFi: Find Your Edge


Home Menu

 





CalculateOnBarClose - true & CalculateOnBarClose = false


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one ratfink with 2 posts (5 thanks)
    2. looks_two victorg20013 with 2 posts (0 thanks)
    3. looks_3 sam028 with 1 posts (1 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 2,729 views
    2. thumb_up 6 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

CalculateOnBarClose - true & CalculateOnBarClose = false

  #1 (permalink)
victorg20013
Los Angeles
 
Posts: 11 since Feb 2017
Thanks Given: 3
Thanks Received: 0

Has anyone got their code to have the 2 different settings of CalculateOnBarClose working on some part of their indicator?

I have a code that HAS to have CalculateOnBarClase = true.

I now have decided to add to the code.

However, the new additions to code, would need it to run CalculateOnBarClose = false, while the rest of the code needs to
run CalculateOnBarClose = true.

How do I get to have only a certain section of code to run on CalculateOnBarClose = false, while the other is on CalculateOnBarClose = true?

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Quant vue
Trading Reviews and Vendors
MC PL editor upgrade
MultiCharts
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
  #3 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,426



victorg20013 View Post
Has anyone got their code to have the 2 different settings of CalculateOnBarClose working on some part of their indicator?

I have a code that HAS to have CalculateOnBarClase = true.

I now have decided to add to the code.

However, the new additions to code, would need it to run CalculateOnBarClose = false, while the rest of the code needs to
run CalculateOnBarClose = true.

How do I get to have only a certain section of code to run on CalculateOnBarClose = false, while the other is on CalculateOnBarClose = true?

Use the 'FirstTickOfBar' variable (NT7). ('IsFirstTickOfBar' in NT8)

When it's true you then know that the previous bar just closed and the new bar is just opening (i.e effectively the same as running code with CalculateOnBarClose = true), otherwise it's any old tick in a forming bar. But do also check that the barsAgo subscript [e.g. 0/1] is then appropriate depending on what you want to do, (i.e. [0] for the new bar, [1] for the just closed bar.)

[and use CalculateOnBarClose = false so you then have the choice, and NB this is no use in backtesting, which always runs on COBC = true anyway]

Cheers

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


victorg20013 View Post
Has anyone got their code to have the 2 different settings of CalculateOnBarClose working on some part of their indicator?

I have a code that HAS to have CalculateOnBarClase = true.

I now have decided to add to the code.

However, the new additions to code, would need it to run CalculateOnBarClose = false, while the rest of the code needs to
run CalculateOnBarClose = true.

How do I get to have only a certain section of code to run on CalculateOnBarClose = false, while the other is on CalculateOnBarClose = true?

It has to be True or False but not both.
Hard to say more with more details but you may have a logic error somewhere.

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
Thanked by:
  #5 (permalink)
victorg20013
Los Angeles
 
Posts: 11 since Feb 2017
Thanks Given: 3
Thanks Received: 0


ratfink View Post
Use the 'FirstTickOfBar' variable (NT7). ('IsFirstTickOfBar' in NT8)

When it's true you then know that the previous bar just closed and the new bar is just opening (i.e effectively the same as running code with CalculateOnBarClose = true), otherwise it's any old tick in a forming bar. But do also check that the barsAgo subscript [e.g. 0/1] is then appropriate depending on what you want to do, (i.e. [0] for the new bar, [1] for the just closed bar.)

[and use CalculateOnBarClose = false so you then have the choice, and NB this is no use in backtesting, which always runs on COBC = true anyway]

Cheers

I tried the firsttickofbar bool and I get logic errors.
Thanks tho.

I wonder if anyone has ever been able to effectively do it.

Reply With Quote
  #6 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,426


victorg20013 View Post
I tried the firsttickofbar bool and I get logic errors.
Thanks tho.

I wonder if anyone has ever been able to effectively do it.

Saying 'logic errors' doesn't help much, it's used often and works fine, e.g with CalculateOnBarClose set to false, then in OnBarUpdate:

 
Code
if (FirstTickOfBar)
{
    // here we get only the first tick of every bar
    // so process e.g. Close[1] or whatever you want from the previous closed bar
}
else
{
    // here we get all other remaining ticks in each bar
    // so process Close[0] or whatever you want to do in the still forming bar
}

// here we get every tick in the bar, first and subsequent

However, like I said, it's no use in backtesting, and of course you can get logic errors from a gazillion things, it's usually us that puts them in. It is worth spending time learning C#, using the NT help guide and looking at running code in the download section or on the Ninja support forum, remember NT7 v NT8 differences if appropriate.

Don't ever underestimate the value of a simple 'Print' statement either. Very little software can't have a bug shown up with one of those.


Cheers

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on February 28, 2017


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts