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]);
}
}
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
OCO Cant be reused..
Collapse
X
-
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:Last edited by tkaboris; 04-17-2023, 06:46 PM.Tags: None
-
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.
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
80 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
40 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
63 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
63 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
54 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment