Series data conflict while running a strategy on multiple instruments

John A

Active member
Joined
Dec 16, 2024
Posts
25
Likes
2
I have been testing my custom strategy in live simulation mode. I have been testing the same strategy on four instruments simulataneously.

It works correctly most of the time. But out of no where the strategy running on one instrument picks data series from the other instruments' chart.

for example see below code:

@Override
public void onBarClose(OrderContext orderContext) {
var series = orderContext.getDataContext()
.getDataSeries();

var entryPoint = series.getHigh(signalIndex);

}

If I am running the strategy simultaneously on instruments 'ES' and 'CL' then:
In ES strategy run I am getting series data of CL, and wrong entry point gets set. This happens out of the blue.

Anyone has seen this issue before? any solutions?
 
I have never tested this in a strategy, but this is what I use (see the code below) to have multiple instruments in the same study, and it works well. I believe it should be possible to set multipleInstrument = true and strategy = true in your strategy settings and implement something similar.

Java:
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);

}
}
 
@HalTrader Thank you for response. I understand what you are saying. But in my case I don't want to access data from multiple instruments on the same chart.
What I am talking about seems like bug from Motivewave. I'll sum it up here again:
1. I have created a strategy that works on single instrument data
2. I have opened two different charts in Motivewave
3. Then on each of these charts, I added the strategy and activated it.
4. So the ideal behavior should be that, each of these strategy should run without interfering with other chart.
5. But, out of nowhere, strategy running in one chart is accessing data from other chart.

Maybe I should report this as a bug to Motivewave. But as far as I know they dont respond to bug related to SDK bugs on email. SDK support is limited to
this forum.
Still, If anyone is aware of this problem, please provide suggestions about how to fix this.
 
Last edited:
@John A thanks for your clarification. I have never run multiple strategies simultaneously, but based on your experience, it is possible that strategies in MotiveWave may not distinguish instruments across different charts, as the SDK might interpret everything as occurring under the same account and Strategy, even when the strategy names and IDs are different.

If that is happening in your case, I would definitely contact MotiveWave and include screenshots or a short video illustrating the issue you encountered.

Also, adding the following instance identifier to each strategy may help check whether the same Java object is being used across different charts or instruments.

Java:
import java.util.UUID;


private final UUID instanceId = UUID.randomUUID();


debug("Strategy name/ID: " + "Strategy instance: " + instanceId);[
 
Otherwise, it would have been great if each strategy instance could have a unique identifier that is assigned to each trade or position, similar to the Magic Number in MetaTrader, so that users could run multiple strategies simultaneously on a single account without interference. So far, unless I missed something, I don’t see anything like this in the current Java SDK.
 
@HalTrader Thanks a lot for this. I can surely try assigning instance identifier to each strategy. That might help to identify the issue.

I will certainly reach out to Motivewave support on this but as per past experience, their usual response is: SDK support is limited to the forum.

Still will give it a try.

Thank you for the help.
 
Good luck. I hope this issue will be resolved. It would be better to contact MotiveWave Support to ask whether they could add a MetaTrader Magic Number equivalent to their Java SDK. This would fix the whole problem. However, it might take a long time for this to be implemented.
 
Top