import com.motivewave.platform.sdk.common.*;
import com.motivewave.platform.sdk.common.desc.*;
import com.motivewave.platform.sdk.study.RuntimeDescriptor;
import com.motivewave.platform.sdk.study.Study;
import com.motivewave.platform.sdk.study.StudyHeader;
import com.motivewave.platform.sdk.common.DataContext;
import com.motivewave.platform.sdk.common.Defaults;
import com.motivewave.platform.sdk.common.Enums;
import com.motivewave.platform.sdk.common.desc.ValueDescriptor;
@StudyHeader(
namespace="com.mycompany",
id="MI",
rb="com.motivewave.platform.study.nls.strings",
name="Multiple Instruments",
label="Multiple Instruments",
desc="Multiple Instruments",
menu="My new studies",
overlay=true,
studyOverlay=true,
signals=true,
underlayByDefault = true,
barUpdatesByDefault = false,
supportsBarUpdates = true,
multipleInstrument = true
)
public class MultipleInstruments extends Study {
enum Values {
ES_O, ES_H, ES_L, ES_C,
NQ_O, NQ_H, NQ_L, NQ_C,
}
protected final static String inst_1 = "@ES";
protected final static String inst_2 = "@NQ";
// other code
@Override
public void initialize(Defaults defaults) {
SettingsDescriptor sd = createSD();
SettingTab tab = sd.addTab("Get Instruments");
SettingGroup group1 = tab.addGroup("Instruments");
group1.addRow(new InstrumentDescriptor(inst_1, inst_1, true, false));
group1.addRow(new InstrumentDescriptor(inst_2, inst_2, true, false));
RuntimeDescriptor desc = createRD();
desc.exportValue(new ValueDescriptor(Values.ES_O, Enums.ValueType.DOUBLE,
"ES OPEN", null));
desc.exportValue(new ValueDescriptor(Values.ES_H, Enums.ValueType.DOUBLE,
"ES HIGH", null));
desc.exportValue(new ValueDescriptor(Values.ES_L, Enums.ValueType.DOUBLE,
"ES LOW", null));
desc.exportValue(new ValueDescriptor(Values.ES_C, Enums.ValueType.DOUBLE,
"ES CLOSE", null));
desc.exportValue(new ValueDescriptor(Values.NQ_O, Enums.ValueType.DOUBLE,
"NQ OPEN", null));
desc.exportValue(new ValueDescriptor(Values.NQ_H, Enums.ValueType.DOUBLE,
"NQ HIGH", null));
desc.exportValue(new ValueDescriptor(Values.NQ_L, Enums.ValueType.DOUBLE,
"NQ LOW", null));
desc.exportValue(new ValueDescriptor(Values.NQ_C, Enums.ValueType.DOUBLE,
"NQ CLOSE", null));
// other code
}
@Override
protected void calculate(int index, DataContext ctx) {
if (index < 1) return; // not enough data
Instrument ins1 = getSettings().getInstrument(inst_1); //ES
Instrument ins2 = getSettings().getInstrument(inst_2); //NQ
DataSeries series = ctx.getDataSeries();
// ES (main chart)
double ES_open = series.getOpen(index, ins1);
series.setDouble(index, Values.ES_O, ES_open);
double ES_high = series.getHigh(index, ins1);
series.setDouble(index, Values.ES_H, ES_high);
double ES_low = series.getLow(index, ins1);
series.setDouble(index, Values.ES_L, ES_low);
double ES_close = series.getClose(index, ins1);
series.setDouble(index, Values.ES_C, ES_close);
// NQ (get data)
double NQ_open = series.getOpen(index, ins2);
series.setDouble(index, Values.NQ_O, NQ_open);
double NQ_high = series.getHigh(index, ins2);
series.setDouble(index, Values.NQ_H, NQ_high);
double NQ_low = series.getLow(index, ins2);
series.setDouble(index, Values.NQ_L, NQ_low);
double NQ_close = series.getClose(index, ins2);
series.setDouble(index, Values.NQ_C, NQ_close);
}
}