Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Moving multiple stop Loss Orders
Collapse
X
-
Moving multiple stop Loss Orders
Hi there. Trying to move multiple stop losses in a strategy (effectively using them as a trailing stop). The problem is I seem to get looping. Moving the first one to breakeven works ok but then the next ones are looping so basically in the log you see the stops being moved continuously as orders. So I modified the example here with just a single order and the same thing happens. The first one to BE works when the market moves up 30 ticks but when the market moves up 40 or 60 ticks the stop moves but in a continuous loop. Any ideas what is causing this would be appreciated. ThanksLast edited by djkiwi; 11-23-2020, 07:43 PM.Tags: None
-
Here is the example code for the multiple orders. Both behave in this looping fashion.
{
EnterLongLimit(Convert.ToInt32(DefaultQuantity), GetCurrentBid(), @"Long1");
EnterLongLimit(Convert.ToInt32(DefaultQuantity), GetCurrentBid(), @"Long2");
EnterLongLimit(Convert.ToInt32(DefaultQuantity), GetCurrentBid(), @"Long3");
}
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, Stoploss1);
SetStopLoss(CalculationMode.Ticks, Stoploss2);
SetStopLoss(CalculationMode.Ticks, Stoploss3);
}
else if
((Position.MarketPosition == MarketPosition.Long)
&& (Close[0] > Position.AveragePrice+10 * TickSize))
{
SetStopLoss(@"Long1",CalculationMode.Price, Position.AveragePrice,false);
SetStopLoss(@"Long2",CalculationMode.Price, Position.AveragePrice,false);
SetStopLoss(@"Long3",CalculationMode.Price, Position.AveragePrice,false);
Print(Time[0].ToString() + " not first tick of bar Long");
}
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, Stoploss1);
SetStopLoss(CalculationMode.Ticks, Stoploss2);
SetStopLoss(CalculationMode.Ticks, Stoploss3);
}
else if ((Position.MarketPosition == MarketPosition.Long)
&& (Close[0] > Position.AveragePrice+30 * TickSize))
{
//SetTrailStop(@"Long1", CalculationMode.Ticks, 12,false);
//SetTrailStop(@"Long1", CalculationMode.Ticks, 12,false);
//SetTrailStop(@"Long1", CalculationMode.Ticks, 12,false);
SetStopLoss(@"Long1",CalculationMode.Price, Position.AveragePrice+10*TickSize,false);
SetStopLoss(@"Long2",CalculationMode.Price, Position.AveragePrice+10*TickSize,false);
SetStopLoss(@"Long3",CalculationMode.Price, Position.AveragePrice+10*TickSize,false);
Print(Time[0].ToString() + " second");
}
// If a long position is open, allow for stop loss modification to breakeven
//2. Shorts
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(@"Long1", CalculationMode.Ticks, Stoploss1, false);
SetStopLoss(@"Long2", CalculationMode.Ticks, Stoploss2, false);
SetStopLoss(@"Long3", CalculationMode.Ticks, Stoploss3, false);
SetStopLoss(@"Short1", CalculationMode.Ticks, Stoploss1, false);
SetStopLoss(@"Short2", CalculationMode.Ticks, Stoploss2, false);
SetStopLoss(@"Short3", CalculationMode.Ticks, Stoploss3, false);
}
-
Hello djkiwi,
Thank you for the post.
When you say that the stop moves in a loop what do you mean? Are you seeing that its moved multiple times? Are you expecting that it only happens one time?
The code as you have it should all happen at once when the price increases, you are not using any else statements with your if conditions. If the price is + 60 * TickSize you will also be setting the stop for the 40 and 60 because those are true as well at that point.
You do have one else statement but its only going to apply to a single one of the if statements below it, you are not using any curly braces to contain the code you want the else to apply to. If and else statements will only apply to the following 1 line if you don't use { }
I look forward to being of further assistance.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
51 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
128 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
69 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment