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 Felix Reichert, 04-26-2024, 02:12 PM
    6 responses
    41 views
    0 likes
    Last Post Felix Reichert  
    Started by MrForgetful, Today, 01:28 AM
    3 responses
    21 views
    0 likes
    Last Post NinjaTrader_Zachary  
    Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
    16 responses
    49 views
    0 likes
    Last Post cmtjoancolmenero  
    Started by ETFVoyageur, Yesterday, 06:05 PM
    6 responses
    39 views
    0 likes
    Last Post ETFVoyageur  
    Started by rbeckmann05, Today, 02:35 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Working...
    X