Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OCO Errors after sucessful trade

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    OCO Errors after sucessful trade

    I'm getting the errors attached when I place trades or adjust stop losses and they happen very regularly (at least once a day but usually more than that). The stops the strategy adds don't appear to work when I get the error, and even when the stops are changed in the next bar by the strategy they still don't appear.

    I can see the errors are telling me I'm trying to put my stop above the market but that's not the case. I have written a custom stop chasing strategy but I don't see how it could cause this.

    What's confusing is that the prices the error references seem to be from the previous trade (See chart image - the error references 3310.00 & 3310.15 yet the new order is at 3326)

    Here is my entry code
    Code:
    if (goodToTradeLong == true && Position.MarketPosition == MarketPosition.Flat){ // if I have no active trades and I'm ready to go Long
    EnterLong(contracts,"MACD Oppourtunity Long "+ Time[0]);
    SetStopLoss(CalculationMode.Ticks, InitialStopLoss);
    SetProfitTarget(CalculationMode.Ticks, InitialTakeProfit);
    } else if (goodToTradeShort == true && Position.MarketPosition == MarketPosition.Flat){ // if I have no active trades and I'm ready to go Short
    EnterShort(contracts,"MACD Oppourtunity Short "+ Time[0]);
    SetStopLoss(CalculationMode.Ticks, InitialStopLoss);
    SetProfitTarget(CalculationMode.Ticks, InitialTakeProfit);
    }
    and here is my stop chase code which is positioned above the entry code to prevent the chase from happening before the first bar has a chance to form:

    Code:
     if (Position.MarketPosition == MarketPosition.Short && Ask < High[0]){ //If we're short & it's been a bar since entry
    
    if (goodToTradeLong == true){ //if price is higher than where the stop will be, exit trade
    ExitShort();
    } else if (Ask - High[0] >= 0.5){ // If price is going to be within half a point to the stop, allow more room
    SetStopLoss(CalculationMode.Price, (High[0] + 1));
    } else {
    SetStopLoss(CalculationMode.Price, High[0]);//Otherwise move the stop to the previous high
    SetProfitTarget(CalculationMode.Ticks, CrazyTakeProfit);
    NinjaTrader.Code.Output.Process("Moving Stop Down", PrintTo.OutputTab1);
    }
    }
    
    /* Auto Stop Loss Long */
    if(Position.MarketPosition == MarketPosition.Long && Ask > Low[0]){
    
    if (goodToTradeShort == true){ //if price is lower than where the stop will be, exit trade
    ExitLong();
    } else if (Ask - Low[0] <= 0.5){ // If price is going to be within half a point to the stop, allow more room
    SetStopLoss(CalculationMode.Price, (Low[0] - 1));
    } else {
    SetStopLoss(CalculationMode.Price, Low[0]); //Otherwise move the stop to the previous low and add 1 to Moved
    SetProfitTarget(CalculationMode.Ticks, CrazyTakeProfit);
    NinjaTrader.Code.Output.Process("Moving Stop Up", PrintTo.OutputTab1);
    }
    }

    I don't need OCO as I check I'm flat before entry so if there's a way I can disable it that would be ideal but any ideas are appreciated.

    Many Thanks
    Last edited by Coopero; 10-10-2020, 11:29 AM.

    #2
    Hello Coopero,

    The error:
    "Buy stop or buy stop limit orders can't be placed below the market"

    This error means that a buy stop order (or buy stop limit) order was submitted with the stop price below the current ask. A broker will reject this as this is an invalid price for a buy stop order, which must be above the current ask price.

    You will need to calculate a stop price that is above the current ask before calling the set method. Further, the set method must be set to a valid price before placing a new entry order (as set methods cannot be unset).

    myStopPrice = High[0] + 1;
    if (myStopPrice > GetCurrentAsk())
    {
    SetStopLoss(CalculationMode.Price, myStopPrice);
    }
    else
    {
    SetStopLoss(CalculationMode.Price, GetCurrentAsk() + 1 * TickSize);
    }

    The OCO error occurs because there was an accompanying profit target using the same OCO to group with the stop loss. If one is filled or cancelled, the other is cancelled. If one is rejected, the other is also rejected due to being in the same OCO group.

    Set methods automatically use OCO. If you do not want orders using OCO, use Exit methods like ExitLongStopMarket() instead of using Set methods like SetStopLoss().

    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by inanazsocial, Today, 01:15 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by rocketman7, Today, 02:12 AM
    0 responses
    10 views
    0 likes
    Last Post rocketman7  
    Started by dustydbayer, Today, 01:59 AM
    0 responses
    2 views
    0 likes
    Last Post dustydbayer  
    Started by trilliantrader, 04-18-2024, 08:16 AM
    5 responses
    23 views
    0 likes
    Last Post trilliantrader  
    Started by Davidtowleii, Today, 12:15 AM
    0 responses
    3 views
    0 likes
    Last Post Davidtowleii  
    Working...
    X