Value of variable from previous bar

Spenquatch

New member
Joined
Dec 19, 2022
Posts
2
Likes
0
Hello! I am coming from EasyLanguage and have an issue translating my indicators over to MW. This seems extremely basic, but I am new to Java so please bear with me! For the life of me, I cannot get the value of a variable I have set up from the previous bar (I can get the previous bar OHLC using series.getClose(index), but not custom variables). I have looked at a bunch of the other indicators to see how they do it, but it just doesn't seem to work for me. This is what I believe should work, but does not:

Java:
      double prevHP = series.getDouble(index-1, Values.HP); 
      double _HP = 0.5 * (1 + alpha1) * (currentClose - prevClose) + alpha1 * prevHP;
      series.setDouble(index,  Values.HP, _HP);

Eclipse compiles fine, but all plot values disappear from MW when this code is added, but the study stays active on the chart.

Any help would be greatly appreciated!

I am translating Ehlers Even Better Sinewave Indicator. I will share once I get it completed!
 

Attachments

  • EvenBetterSineWave.zip
    2 KB · Views: 8

Spenquatch

New member
Joined
Dec 19, 2022
Posts
2
Likes
0
The error MW is giving me in the study log is: java.lang.NullPointerException: Cannot invoke "java.lang.Double.doubleValue()" because the return value of "com.motivewave.platform.sdk.common.DataSeries.getDouble(int, Object)" is null
 

Spin

Well-known member
Joined
May 22, 2019
Posts
480
Likes
192
Make sure you write the values to EVERY bar in the DataSeries (e.g. in your 'CalculateValues'-method), before you try to retrieve them from elsewhere in your code.

try adding 'debug'-statements to 'look behind the curtain' (when writing to a value AND retrieve from a value) and see what's going on :)
 
Top