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

calculation once, available immediately

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

    calculation once, available immediately

    Hello,

    I need to have calculation of doubles one time and then provide these numbers all day long if certain conditons are true (which might be very fast depending of market).

    How is the best way to calculate doubles one time and provide them for other conditions in onbarupdate (cobcfalse) please?

    Would onstartup be a good solution? Are the values then calculated only once (as they do not change the same day then) to save CPU and can be used in onbarupdate for entryconditions whenever needed?

    Thank you!
    Tony

    #2
    Hello tonynt,

    Thanks for opening the thread.

    If you would like to calculate some values and save them for later, you could certainly create private variables within the strategy and either calculate in OnStartUp() or within OnBarUpdate() with a doOnce bool. The calculation will only happen once, and the implementation difference would only be cosmetic.

    For example:
    Code:
    private double myDbl;
    bool doOnce = true;
    protected override void OnBarUpdate()
    {
    	if(doOnce == true)
    	{
    		myDbl = SMA(20)[0];
    		doOnce = false;
    	}
    }
    Keep in mind 20 bars will need to iterate before SMA(20) can be calculated, and this is meant to be a rough example.

    Please let me know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by frankthearm, Today, 09:08 AM
    3 responses
    9 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by yertle, Today, 08:38 AM
    5 responses
    15 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by adeelshahzad, Today, 03:54 AM
    3 responses
    16 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by bill2023, Yesterday, 08:51 AM
    6 responses
    27 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by NinjaTrader_ChelseaB, 01-08-2017, 06:59 PM
    80 responses
    19,667 views
    5 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X