Announcement

Collapse
No announcement yet.

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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    54 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    29 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    40 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    56 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    47 views
    0 likes
    Last Post CarlTrading  
    Working...
    X