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 Hwop38, 05-04-2026, 07:02 PM
      0 responses
      154 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      306 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      244 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      345 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      176 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X