Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Programmatically dealing with Calculate

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Programmatically dealing with Calculate

    I know I have seen this info somewhere, but I cannot seem to locate it...so I will just ask if anyone has the answer, or knows where it was answered.

    I need to ensure a user cannot set the Calculate to OnBarClose. I read something to the effect that it is bad to code this anywhere else except in the State.SetDefaults. What I read is something about checking what Calculate is set to, and if it is set to OnBarClose, then trigger a Log alert, and terminating the indicator. I found how to do the alert, but have not been able to find how to terminate the indicator.
    This is what I have so far--
    Code:
    if(Calculate == Calculate.OnBarClose) 
    {
    Log("Calculate may NOT be set to OnBarClose",LogLevel.Alert);
    //terminate indicator code goes here
    }
    And, I had put this in State.DataLoaded.

    #2
    Hello Antny,
    Thanks for your post.

    Setting the Calculate property in State.Historical is the recommended way of approaching this situation. This will not only prevent the property from being changed by the user, but will also ensure that any parent scripts also inherit this properties setting.
    Code:
    else if (State == State.Historical)
    {	
    	Calculate = Calculate.OnEachTick;
    }
    Please let me know if you have any questions.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Awesome! That is exactly the info I needed. I am guessing I saw the other info in response to a NT7 post instead of NT8. Since the two are so different, what would the process to do this same thing be for NT7?

      Comment


        #4
        Hello Antny,

        The equivalent in NT7 would be setting CalculateOnBarClose = false inside OnStartUp().
        Code:
        protected override void OnStartUp()
        {
        	CalculateOnBarClose = false;
        }
        OnStartUp()
        https://ninjatrader.com/support/help...?onstartup.htm

        Please let me know if you have any questions.
        Josh G.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        81 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        42 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        64 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        68 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        55 views
        0 likes
        Last Post CarlTrading  
        Working...
        X