Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OCO Cant be reused..

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

    OCO Cant be reused..

    Hi i am getting this OCO cant rereused. I dont know where i am making a mistake. Its onBarClose and managed approach. I have two strategies in one and if just one is selected its ok but when two are selected i get OCO cant be reused... error with three alert windows... Connection is Rithmic
    Code:
    if(LongsOn){
                if (EngulfTrade
                && ((Position.MarketPosition == MarketPosition.Flat)
                  && ((Time[1].TimeOfDay >= Start.TimeOfDay) && (Time[1].TimeOfDay <= End.TimeOfDay))
                    && (CandlestickPattern(ChartPattern.BullishEngulfing, 4)[0] == 1 ))
                    && barSize <= IgnoreLargeBar)            
                {
    //                EngulfTrade = true;                
                    EnterLong(PositionSize, "EngLong");
                    if(UseFixedSLTP){
                    SetStopLoss(CalculationMode.Ticks, stopLoss);
                    SetProfitTarget(CalculationMode.Ticks, profitTaker);                                    
                    }
                    else {                    
                    SetStopLoss(CalculationMode.Price,Low[0]-0.5);    
                    SetProfitTarget(CalculationMode.Ticks, ptLong);
                        }
    
                }
    
                else if (BounceTrade
                && ((Position.MarketPosition == MarketPosition.Flat)
                  && ((Time[1].TimeOfDay >= Start.TimeOfDay) && (Time[1].TimeOfDay <= End.TimeOfDay))
                    && (Close[0] > Open[0]) && (Close[0] > Open[1])) && (Low[0] < Low[1])
                    && (Close[0] > EMA(21)[0]) && (Low[0] <= EMA(21)[0]) && (EMA(21)[0] > EMA(89)[0])
                    )                
                {
    //                BounceTrade = true;
                    EnterLong(PositionSize, "RevLong");
                    if(UseFixedSLTP){
                    SetStopLoss(CalculationMode.Ticks, stopLoss);
                    SetProfitTarget(CalculationMode.Ticks, profitTaker);                
                        Print("entering Rev Long" + Time[0]);
                    }
                    else {                    
                    SetStopLoss(CalculationMode.Price,Low[0]-0.5);    
                    SetProfitTarget(CalculationMode.Ticks, ptLong);
                        Print("entering Rev Long" + Time[0]);
                        }
                }
            }
                // Shorts
            if (ShortsOn)    {
            if (EngulfTrade
                && ((Position.MarketPosition == MarketPosition.Flat)
                    && ((Time[1].TimeOfDay >= Start.TimeOfDay) && (Time[1].TimeOfDay <= End.TimeOfDay))
                    &&(CandlestickPattern(ChartPattern.BearishEngulfing, 4)[0] == 1 ))
                    && barSize <= IgnoreLargeBar)    
                {
    //                EngulfTrade = true;
                    EnterShort(PositionSize, "EngShort");            
                    if(UseFixedSLTP){
                    SetStopLoss(CalculationMode.Ticks, stopLoss);    
                    SetProfitTarget(CalculationMode.Ticks, profitTaker);                
                        Print("Entering EngShort" + Time[0]);
                    }
                    else{                    
                    SetStopLoss(CalculationMode.Price,High[0]+0.5);    
                    SetProfitTarget(CalculationMode.Ticks, ptShort);    
                        Print("Entering EngShort" + Time[0]);
                    }
                }
                else if (BounceTrade
                && ((Position.MarketPosition == MarketPosition.Flat)
                  && ((Time[1].TimeOfDay >= Start.TimeOfDay) && (Time[1].TimeOfDay <= End.TimeOfDay))
                    && (Close[0] < Open[0]) && (Close[0] < Open[1])) && (High[0] > High[1])
                    && (Close[0] < EMA(21)[0]) && (High[0] >= EMA(21)[0]) && (EMA(21)[0] < EMA(89)[0]) )            
                {
                    EnterShort(PositionSize, "RevShort");
    
                    if(UseFixedSLTP){
                    SetStopLoss(CalculationMode.Ticks, stopLoss);    
                    SetProfitTarget(CalculationMode.Ticks, profitTaker);                
                        Print("Entering RevShort" + Time[0]);
                    }
                    else{                    
                    SetStopLoss(CalculationMode.Price,High[0]+0.5);    
                    SetProfitTarget(CalculationMode.Ticks, ptShort);    
                        Print("Entering RevShort" + Time[0]);
                    }
                }
    
            }
    
            }​
    Last edited by tkaboris; 04-17-2023, 06:46 PM.

    #2
    Hello tkaboris,

    Thank you for your note.

    I suspect the message has to do with the stop loss and profit target orders, which are submitted using OCO (one cancels other). I see you are submitting an entry order and then calling the SetStopLoss() and SetProfitTarget() methods. These methods are meant to be called prior to submitting an entry order, then as soon as the entry is executed the stop and target orders are submitted. I suggest adjusting your strategy so that it calls SetStopLoss() and SetProfitTarget before calling your EnterLong() or EnterShort() methods and this should resolve the OCO error. For more details on SetStopLoss() and SetProfitTarget() please see the links below:We also have a couple of reference samples that utilize the Set() methods for stops and targets that you may review:Please let us know if we may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    62 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    134 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X