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
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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.Emily C.NinjaTrader Customer Service
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by rbeckmann05, Yesterday, 06:48 PM
|
1 response
12 views
0 likes
|
Last Post
by bltdavid
Today, 05:43 AM
|
||
Started by llanqui, Today, 03:53 AM
|
0 responses
6 views
0 likes
|
Last Post
by llanqui
Today, 03:53 AM
|
||
Started by burtoninlondon, Today, 12:38 AM
|
0 responses
10 views
0 likes
|
Last Post Today, 12:38 AM | ||
Started by AaronKoRn, Yesterday, 09:49 PM
|
0 responses
15 views
0 likes
|
Last Post
by AaronKoRn
Yesterday, 09:49 PM
|
||
Started by carnitron, Yesterday, 08:42 PM
|
0 responses
11 views
0 likes
|
Last Post
by carnitron
Yesterday, 08:42 PM
|
Comment