Thans a lot
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Problem wiht Breakeven after reach one of two positions
Collapse
X
-
Problem wiht Breakeven after reach one of two positions
Hi i was trying this code, for open one positions, two profits, and one stop, i was trying go to breakeven after reach first position, but when price reach first position the second one is deleted, how can i maintain the second profit after price go to breakeven
Thans a lot
Tags: None
-
I'm not entirely sure...but in your breakeven section I see you have CancelOrder(_stopOrder); Since this is a partial and your first take profit is hit, would that cancel the second target order too? After that I see you have code that resets your Stop Loss with the remaining contracts at your breakeven price. I would add some prints and/or make TraceOrders = true to find out what is happening in that split second. I would comment out the CancelOrder part and see how that affects it, and then go from there.
-
-
Originally posted by NinjaTrader_Jesse View PostHello mjairg,
To place separate targets you will need to use two separate entries with different signal names. That will let you tie targets to part of the position.
Thanks, Signals are separated, this is part of code, the little problem is maintan second order active when i move the price to Breakeven, i try delete CancelOrder(_stopOrder); but dont work
I have an entry signal function with this for test purposes,
Code:_enterLong = Close[0] > Open[0]; _enterLong &= Open[0] > High[1]; _enterShort = Close[0] < Open[0]; _enterShort &= Open[0] < Low[1];
a trade funcion call from onbarupdate
Code:if (Position.MarketPosition == MarketPosition.Flat) //No tenemos una posición larga (long) ni corta (short). { if (_enterLong){ EnterLong(_posSize, LongPos); } else if (_enterShort){ EnterShort(_posSize, ShortPos); } } else if (Position.MarketPosition != MarketPosition.Flat)// Tenemos un tipo de entrada { }
After OnExecutionUpdate i call a SetStopProfit
Code:private void SetStopProfit(Execution execution) { var entryPrice = execution.Order.AverageFillPrice; _pos1 = Math.Round((_posSize * PositionSplitPercent / 100), 0); _pos2 = _posSize - _pos1; if (_currentPosition == CurrentPos.Long) { _stop = entryPrice - StopTicks * TickSize; _profit1 = entryPrice + ProfitOneTicks * TickSize; _profit2 = entryPrice + ProfitTwoTicks * TickSize; _profitOrder1 = ExitLongLimit(0, true, (int)_pos1, _profit1, ProfitLong1, LongPos); _profitOrder2 = ExitLongLimit(0, true, (int)_pos2, _profit2, ProfitLong2, LongPos); _stopOrder = ExitLongStopMarket(0, true, _posSize, _stop, StopLong, LongPos); } else if (_currentPosition == CurrentPos.Short) { _stop = entryPrice + StopTicks * TickSize; _profit1 = entryPrice - ProfitOneTicks * TickSize; _profit2 = entryPrice - ProfitTwoTicks * TickSize; _profitOrder1 = ExitShortLimit(0, true, (int)_pos1, _profit1, ProfitShort1, ShortPos); _profitOrder2 = ExitShortLimit(0, true, (int)_pos2, _profit2, ProfitShort2, ShortPos); _stopOrder = ExitShortStopMarket(0, true, _posSize, _stop, StopShort, ShortPos); } }
Code:private void BreakEven(Execution execution) { CancelOrder(_stopOrder); if (execution.Order.Name == ProfitLong1) { _stopOrder = ExitLongStopMarket(0, true, (int)_pos2, Position.AveragePrice, BreakEvenLong, LongPos); } if (execution.Order.Name == ProfitShort1) { _stopOrder = ExitShortStopMarket(0, true, (int)_pos2, Position.AveragePrice, BreakEvenShort, ShortPos); } }
Comment
-
I think the point is, he is saying that you are using:
_profitOrder1 = ExitLongLimit(0, true, (int)_pos1, _profit1, ProfitLong1, LongPos);
_profitOrder2 = ExitLongLimit(0, true, (int)_pos2, _profit2, ProfitLong2, LongPos);
Both of which use the entry signal LongPos. You may be separating the targets, but they both use the same entry signal. You essentially need to make them two separate entries, so LongPos1 and LongPos2. This happens to be what I had to do for my strategy, which has the same type of logic as yours. I just wasn't sure that it wasn't possible doing it the way you are currently doing.
So instead of EnterLong(_posSize, LongPos);
you need to replace that with
EnterLong((int)_pos1, LongPos1);
EnterLong((int)_pos2, LongPos2);
Comment
-
Thanks a lot for your help, for now i solved it, sending a new order in Breakeven function for testing i put thisOriginally posted by rockmanx00 View PostI think the point is, he is saying that you are using:
_profitOrder1 = ExitLongLimit(0, true, (int)_pos1, _profit1, ProfitLong1, LongPos);
_profitOrder2 = ExitLongLimit(0, true, (int)_pos2, _profit2, ProfitLong2, LongPos);
Both of which use the entry signal LongPos. You may be separating the targets, but they both use the same entry signal. You essentially need to make them two separate entries, so LongPos1 and LongPos2. This happens to be what I had to do for my strategy, which has the same type of logic as yours. I just wasn't sure that it wasn't possible doing it the way you are currently doing.
So instead of EnterLong(_posSize, LongPos);
you need to replace that with
EnterLong((int)_pos1, LongPos1);
EnterLong((int)_pos2, LongPos2);
Code:private void BreakEven(Execution execution) { CancelOrder(_stopOrder); if (execution.Order.Name == ProfitLong1) { _stopOrder = ExitLongStopMarket(0, true, (int)_pos2, Position.AveragePrice, BreakEvenLong, LongPos); ExitLongLimit(0, true,3, 22107, "SignalName", LongPos); // -----------------------------------------------------------------------------> New order } if (execution.Order.Name == ProfitShort1) { _stopOrder = ExitShortStopMarket(0, true, (int)_pos2, Position.AveragePrice, BreakEvenShort, ShortPos); } }
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
20 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
119 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
63 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
41 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
45 views
0 likes
|
Last Post
|

Comment