Server-side OCOs/Bracketing?

michaelphines

Member
Joined
Apr 21, 2020
Posts
7
Likes
2
Hey there,

I've got my assisted strategy set up in a really good place such that I can activate it when I see a trade setting up and get my perfect rule-based entry. Now I'm at the point where I just need to have it apply my bracket, but I can't figure out how to execute an OCO. Is it possible? Right now I can attach my bracket to the executed position manually, but that's not ideal, because I'd like to have the SL and TP set based on the strategy as well. Ideally I could set a stop triggers OCO, but I would settle for just the OCO.

If it's not possible, I'm torn between getting a good exit with a limit order (important because it's a scalping strategy) or protecting myself with a stop loss. Obviously I can execute both trades, and wait until one is filled and cancel the other client-side, but my fear is that I'll have an internet outage while I'm in a position and my TP will trigger and then immediately reverse and run out my stop before I can get logged back in, leaving me in the inverse position.

The resources I've been using are: https://www.motivewave.com/sdk/MotiveWave_SDK_Programming_Guide.pdf
the javadoc: https://www.motivewave.com/sdk/javadoc/index.html
and the example projects: https://www.motivewave.com/sdk/MotiveWave_Studies.zip

The sample projects were great for getting started, but some code for a more complex strategy might be helpful. I don't know if the Trade Manager strategy uses OCOs, but it also has some features that I'm struggling to find documentation for, like showing the Risk/Reward in the strategy screen.

Cheers,

Mike
 

michaelphines

Member
Joined
Apr 21, 2020
Posts
7
Likes
2
Ah, I just saw the thread with the com.motivewave.platform.study.general.TradeManager study.

It looks like the orders are canceled manually as I expected. Is there any plan to add OCO capabilities to the SDK?

Java:
  private void trailFilled(OrderContext ctx, Order order)
  {
    var cancelList = new ArrayList<Order>();
    if (isValidOrder(firstOrder) && Util.isEmpty(firstOrder.getReferenceID())) cancelList.add(firstOrder);
    if (isValidOrder(secondOrder) && Util.isEmpty(secondOrder.getReferenceID())) cancelList.add(secondOrder);
    if (isValidOrder(thirdOrder) && Util.isEmpty(thirdOrder.getReferenceID())) cancelList.add(thirdOrder);
    firstOrder = secondOrder = thirdOrder = null;
    ctx.cancelOrders(cancelList);
  }
 

michaelphines

Member
Joined
Apr 21, 2020
Posts
7
Likes
2
Interesting. If I submit 3 orders at once:

Java:
    stopLossOrder =
        context.createStopOrder(instrument, exitAction, TIF.GTC, QUANTITY, getStopLossPrice());
    takeProfitOrder = context.createLimitOrder(instrument, exitAction, TIF.GTC,
        TAKE_PROFIT_QUANTITY, getTakeProfitPrice());
    runnerOrder = context.createLimitOrder(instrument, exitAction, TIF.GTC, RUNNER_QUANTITY,
        getRunnerPrice());

And then when a TP order is filled, I update the stopLoss to the quantity of the runner

Java:
    cancelOrders(takeProfitOrder);
    stopLossOrder.setAdjStopPrice(entryFillPrice);
    stopLossOrder.setAdjQuantity(RUNNER_QUANTITY);
    context.submitOrders(stopLossOrder);

When the stopLossOrder is filled, the runner is canceled automatically—at least in the simulator. Is this happening within the software or is it a feature my broker must support? Is this a behavior that most brokers follow?
 
Top