Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SMA indicator code

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

    SMA indicator code

    Hi,

    I might be very thick this morning, but looking at the SMA indicator code I found that both Math.Min calls are unnecessary.

    Code:
    protected override void OnBarUpdate()
    		{
    			Print("OBU currentbar: "+CurrentBar);
    			if (CurrentBar == 0)
    				Value.Set(Input[0]);
    			else
    			{
    				double last = Value[1] * Math.Min(CurrentBar, Period);
    
    				if (CurrentBar >= Period)
    					Value.Set((last + Input[0] - Input[Period]) / Math.Min(CurrentBar, Period));
    				else
    					Value.Set((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));
    			}
    		}
    Could be:

    Code:
    protected override void OnBarUpdate()
    		{
    			Print("OBU currentbar: "+CurrentBar);
    			if (CurrentBar == 0)
    				Value.Set(Input[0]);
    			else
    			{
    				double last = Value[1] * Math.Min(CurrentBar, Period);
    
    				if (CurrentBar >= Period)
    					Value.Set((last + Input[0] - Input[Period]) / Period);
    				else
    					Value.Set((last + Input[0]) / (CurrentBar + 1));
    			}
    		}
    Am I missing something or we could do this simple optimization?

    PS.- I'm not trying to be critical, I ask this because I need to modify the SMA indicator and this got me confused...
    Last edited by dpicon; 06-04-2012, 02:21 AM. Reason: typo

    #2
    I think you're correct dpicon, shouldn't be needed - we're are looking into further optimizing our system indicators further as well in the future to provide highest efficiency.

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      I think you're correct dpicon, shouldn't be needed - we're are looking into further optimizing our system indicators further as well in the future to provide highest efficiency.
      Actually you could optimize it further by removing too the Math.Min from the "last" variable and calculating "last" into both if cases.

      As SMAs are being used by many many traders we could save a few ticks(*) per trader, and therefore reduce the carbon footprint of the trader community...


      (*) CPU ticks...
      Last edited by dpicon; 06-04-2012, 02:48 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      548 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X