Can an Instrument be instantiated at runtime?

njoan

New member
Joined
Aug 26, 2019
Posts
4
Likes
0
Or have it's symbol changed within the calculate method?
 
Last edited:
Hi Njoan,

Would you be able to provide a little more detail or an example of what it is that you are trying to do?
 
Hi Njoan,

Would you be able to provide a little more detail or an example of what it is that you are trying to do?
Sure:

Say that there is an IntegerDescriptor called "selection", and the user is supposed to enter an int from 1 to 3.
Is it possible then to create an Instrument object based on their input, without them having to explicitly choose an instrument themselves with an InstrumentDescriptor? ie. is there a way to do something similar to the following:
Java:
Integer selection = getSettings().getInteger(Inputs.INPUT);
Instrument s;

switch (selection):
case 1:  s.setSymbol("IBM");
        break;
case 2: s.setSymbol("FB");
        break;
case 3: s.setSymbol("GE");
        break;

Or, if that is not possible, is it possible that an Instrument object's symbol be changed within the calculate method? Ie. something like the following:

Code:
// In the initialize method:
settinggroup.addRow(new InstrumentDescriptor(Inputs.INSTRUMENT, "Selection"));


// In the calculate method:
Instrument i1 = getSettings().getInstrument(Inputs.INSTRUMENT);

if (series.getClose(i1) < 40.0) i1.setSymbol("FB");

Finally if none of these are possible, is there a way to simply set the default symbol for an InstrumentDescriptor?
Thanks for bearing with me
 
This is related to my question about wanting to get the options for the underlying instrument at run-time. If you get an answer, I'd love to hear it.
 
Top