#### Spin

##### Well-known member

- Joined
- May 22, 2019

- Posts
- 221

- Likes
- 46

For my newest study I need to compare the values of the HMA against other MA's. So I downloaded the HMA code that the friendly MotiveWave-people were so kind to share.

This HMA uses CalculateValues and OnBarUpdate. I then added a 'Calculate' section where I calculate & draw 4 other MA's:

Code:

```
@Override
protected void calculate(int index, DataContext ctx)
{
debug("Inside calculate " );
DataSeries series = ctx.getDataSeries();
int EMA21HiPeriod=getSettings().getInteger(EMA_21_Hi_Period);
//debug ("testing: Periods = " + EMA21HiPeriod + " index " + index);
int EMA21LoPeriod=getSettings().getInteger(EMA_21_Lo_Period);
int EMA144Period=getSettings().getInteger(EMA_144_Period);
int EMA544Period=getSettings().getInteger(EMA_544_Period);
// EMA's
Double Hi21=series.ma(getSettings().getMAMethod(EMA_21_Hi_Method), index, EMA21HiPeriod, getSettings().getInput(EMA_21_Hi_Input));
Double Lo21=series.ma(getSettings().getMAMethod(EMA_21_Lo_Method), index, EMA21LoPeriod, getSettings().getInput(EMA_21_Lo_Input));
Double E144=series.ma(getSettings().getMAMethod(EMA_144_Method), index, EMA144Period, getSettings().getInput(EMA_144_Input));
Double E544=series.ma(getSettings().getMAMethod(EMA_544_Method), index, EMA544Period, getSettings().getInput(EMA_544_Input));
//Double HMA=series.ma(getSettings().getMAMethod(HMA_METHOD), index, HMAPeriod, getSettings().getInput(HMA_INPUT));
// 'safety check' to see if values exist already
if (Hi21 == null) return;
if (Lo21 == null) return;
if (E144 == null) return;
if (E544 == null) return;
debug ("Hi21 == " + Hi21);
//set values for current bar
series.setDouble(index, Values.EMA_21_Hi, Hi21);
series.setDouble(index, Values.EMA_21_Lo, Lo21);
series.setDouble(index, Values.EMA_144, E144);
series.setDouble(index, Values.EMA_544, E544);
series.setComplete(index);
}
```

In the study log I only see the debug-statement "Hi21=" printed once. So it seems the Calculate function is only run once (or for one bar).

What do I need to change / add to have both the 4 MA's and the HMA drawn ??

All help welcome !