Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 05:43:41 +0000



Post From: trying to get started programming, problem with simple exampe (own SMA)

[2023-09-11 23:42:30]
User138457 - Posts: 38
I tried to write my own SMA as an exercise (I know it exists as a funtion).
Can anyone tell me what is going wrong with

  double sma;
  int BarIndexSize = sc.Input[0].GetInt();
  sma=0.;

  
  for ( int BarIndex = sc.Index; BarIndex>sc.Index-BarIndexSize; BarIndex--)
  {
    sma=sma+(sc.Close[BarIndex]);
        
  }
sma=sma/(BarIndexSize*1.f)

?

It always return 0. is sth off with the indices? I skipped all the definitions here for brewety, but obv.
happy to provide is necessary.

TIA