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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    51 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    142 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    160 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    96 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    275 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X