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 DJ888, 04-16-2024, 06:09 PM
    4 responses
    12 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by terofs, Today, 04:18 PM
    0 responses
    5 views
    0 likes
    Last Post terofs
    by terofs
     
    Started by nandhumca, Today, 03:41 PM
    0 responses
    5 views
    0 likes
    Last Post nandhumca  
    Started by The_Sec, Today, 03:37 PM
    0 responses
    3 views
    0 likes
    Last Post The_Sec
    by The_Sec
     
    Started by GwFutures1988, Today, 02:48 PM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Working...
    X