Help with own enum's of options in a study.

xel_arjona

Member
Joined
Oct 15, 2024
Posts
7
Likes
1
Good Day guys, Im learning MW's SDK and in the run trying to port one of my more used studies from TradingView, but Im some kind slowed down with the correct method to define own enumerators with Strings to be used as "Options" by my study. This is what I want to be done, my base "template" was the BollingerBands and other indicators as the FRAMA from the Source Code Studies published in this forum from 2019:

First Im declaring the contents in the enumerator as Strings:

final static String COMPOSITE = "RangeVolumeComposite", RANGE = "Range", VOLUME = "Volume";

Then the enumerator:
enum CoeffType { COMPOSITE, RANGE, VOLUME }

At the initialize section, Im using the enum as follow, please correct me if this is wrong or I must use other inputDescriptor method:
inputs.addRow(new InputDescriptor(COEFF_MODE, "Weighing Factor Mode:", CoeffType.COMPOSITE));

Then at the calculate section, Im trying to call my "selection" with:
var coeffType = getSettings().getEnum(COEFF_MODE, CoeffType.COMPOSITE);

Then, "ant" returns me their angry as:
error: method getEnum in class Settings cannot be applied to given types;
[javac] var coeffType = getSettings().getEnum(COEFF_MODE, CoeffType.COMPOSITE);
[javac] ^
[javac] required: String
[javac] found: String,CoeffType
[javac] reason: cannot infer type-variable(s) T
[javac] (actual and formal argument lists differ in length)
[javac] where T is a type-variable:
[javac] T extends Object declared in method <T>getEnum(String)

My Code is MIT open at TradingView, so feel free to see my attempt at the original attached source for MotiveWave:

Hope you can help me guys, I want to port other things to this wonderfull platform!

Cheers!
 

Attachments

Perhaps the following will guide you some:

List<String>tradeList = new ArrayList<String>();
tradeList.add(new String("Long", Inputs.LONGS_ONLY));
tradeList.add(new String("Short", Inputs.SHORTS_ONLY));
tradeList.add(new String("Longs & Shorts", Inputs.LONGS_AND_SHORTS));
inputs.addRow(new DiscreteDescriptor(Inputs.TRADE_DIRECTION, get("Study"), Inputs.LONGS_ONLY, tradeList));

This creates a dropdown list with the default set to *Longs_Only*. Let me know if you need help when you *calculate*
 
Last edited:
Thank you very much @Volt71, Im currently finishing the calculation and path's logic to do the thing I want to do in the correct way, currently using Int inputs to define the "modes" as 1 = COMPOSITE, 2 = RANGE and 3 = VOLUME until I find the "correct" way of show drop-down list descriptor. Almost done there but currently trying to find a way to declare a recursive way of declaring a function that replicate(replace) the DataSeries.stdev() one to be used for the BANDS section. Do you know guys an example in other study to see how it can work ?
 
Thank you very much for your help @Volt71, as I do not use exactly your method, it gave me light to research more in deepth and found this method using the NVP common class as follow:
Java:
private static final List<NVP> coeffTypeList = List.of(
            new NVP("COMPOSITE", "COMPOISTE"),
            new NVP("RANGE", "RANGE"),
            new NVP("VOLUME", "VOLUME")
      );

Then call the list at the DiscreteDescriptor as you mention:
Java:
inputs.addRow(new DiscreteDescriptor(COEFF_MODE, "Weighing Factor Model", "COMPOSITE", coeffTypeList));

And finally pass the selector to the calculation logic:

Java:
var coeffType     = getSettings().getString(COEFF_MODE);
... then...
Java:
double iirCoeff = 1.0;  // Default to "equal weight"
        if (coeffType == "VOLUME") {
          iirCoeff = volumeBar / totalVolume;
        }
        else if (coeffType == "RANGE") {
          iirCoeff = trueRangeBar / trueRangeN;
        }
        else if (coeffType == "COMPOSITE") {
          iirCoeff = (trueRangeBar * volumeBar) / (trueRangeN * totalVolume);
        }

VOALA !
Screenshot 2024-11-04 at 10.34.10 a.m..png
 
Top