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!
See more
See less

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 gravdigaz6, Today, 11:40 PM
        0 responses
        4 views
        0 likes
        Last Post gravdigaz6  
        Started by MarianApalaghiei, Today, 10:49 PM
        3 responses
        9 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by XXtrader, Today, 11:30 PM
        0 responses
        4 views
        0 likes
        Last Post XXtrader  
        Started by love2code2trade, Yesterday, 01:45 PM
        4 responses
        28 views
        0 likes
        Last Post love2code2trade  
        Started by funk10101, Today, 09:43 PM
        0 responses
        9 views
        0 likes
        Last Post funk10101  
        Working...
        X