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 sjsj2732, 03-23-2026, 04:31 AM
      0 responses
      69 views
      0 likes
      Last Post sjsj2732  
      Started by NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      312 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      306 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      146 views
      1 like
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      105 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Working...
      X