NexusFi: Find Your Edge


Home Menu

 





Intense frustration moving to breakeven+1 in NinjaTrader strategy


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one DavidBodhi with 4 posts (0 thanks)
    2. looks_two rleplae with 2 posts (1 thanks)
    3. looks_3 Bartw with 2 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 3,989 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 9 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
DavidBodhi's Avatar
 DavidBodhi 
Milwaukee, WI, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Equities
Posts: 209 since Oct 2014
Thanks Given: 23
Thanks Received: 209

Hello, All.

I have been working on the following for untold hours, with overly vague feedback from NinjaTrader support and am intensely frustrated.

I have a strategy with a stoploss set in the Initialize() region. The entirety of that region is as follows:

protected override void Initialize()
{
SetStopLoss("", CalculationMode.Ticks, 10, false);
Add(SMA(21));
Add(ADX(14));
CalculateOnBarClose = false;
}

After positions are taken, I am monitoring maximum unrealized P/L in a variable called HighestUPnL. When that amount tops $40 (5 ticks in a $10/tick instrument, less transaction fee), I am TRYING to reset the stop to breakeven-1 tick.

The code intended to do so is as follows (I am just showing for short, though have another condition for long):

// Condition set 3
if (Position.MarketPosition == MarketPosition.Short
&& (HighestUPnL >= 40))
{
SetStopLoss("", CalculationMode.Price, Position.AvgPrice - 1 * TickSize, false);
}

Per NinjaTrader support, the code to move/set the stoploss is correct. However, when I run the strategy, I get errors, upon trying to take a position, that I can't place orders above (or below, depending whether short or long) the market.

If I comment out the line SetStopLoss("", CalculationMode.Price, Position.AvgPrice - 1 * TickSize, false); I get no errors. This, despite the fact that that code SHOULD only run when the position is open and unrealized P/L is above 40.

When the line is not commented out, the strategy will try to place an order (don't know if for entry or for the stop) MANY points away from the current price.

NT support is telling me it's due to a fast moving market, but no market consistently has transient orders at prices dozens of points away from current market value. They recommended I add, above the line to move the stop to breakeven+1, a line so I have:

// Condition set 3
if (Position.MarketPosition == MarketPosition.Short
&& (HighestUPnL >= 40))
{
if (Position.AvgPrice - 1 * TickSize < GetCurrentBid())
{
SetStopLoss("", CalculationMode.Price, Position.AvgPrice - 1 * TickSize, false);
}
}

When I do so, my strategy never places an order. (I did try to incorporate the GetCurrentBid() check incorporated into the one 'if', but never got that to even compile correctly.)

Despite all my emailing, the tech I am working with insists that the way I am trying to do this screws up because the market is moving too fast and my strategy is trying to place orders above/below inappropriately. However, when telling an ATM strategy to move my stop to breakeven+1, there's never any issue, so I think he's full of it. (I'm a neophyte, so I may be wrong.)

So, I have two issues:
1) My initial order fails if I have the code line below NOT commented out:

SetStopLoss("", CalculationMode.Price, Position.AvgPrice - 1 * TickSize, false);

2) I cannot get code that works to move my stop to 1 tick of profit.

I can't even get it to go to breakeven using:

SetStopLoss("", CalculationMode.Price, Position.AvgPrice, false);

Even leaving THAT not commented out makes my initial order fail.

I'm even considering forgetting the stoploss and simply placing limit orders where I want them, but writing the code for that looks even more daunting.

Does anyone have a clue what is going on with this, or have suggestions where to look or what to do? I am fairly desperate, right about now.


Follow me on X Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
New Section 301 Probes Target 16 Trading Partners -- Tra …
Traders Hideout
Bookmap Global Plus Lifetime + Lifetime Addons For Sale
Platforms and Indicators
February Derivatives Boom -- Every Futures Asset Class S …
Traders Hideout
CME Lists U.S. Election Event Contracts as 2028 Democrat …
Prediction Markets & Event Contracts
Asia Equities Crash Overnight -- Nikkei -5.2%, KOSPI -6. …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
21 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
8 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Hello Im new here
5 thanks
  #3 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,860


This is a snippet of code form a robot i wrote, this is actually code that updates both
target and stop to new (higher levels). Use are you own risk
But it might help you forward...

 
Code
if (mylong == 1 && myturbo2OnOff == 1)
				{
					if (myCCI[0] > myCCI[1] && myCCI[0] > myCCIEMA34[0] && Close [0] > myEMA15[0])
					{ 
						if (High[0] >=  (mylongstop + ((double)myUPDATESTOP /myMULTIPLYER)) && mylongstop > mylongentry )
						{
						 mylongstop = High[0]-((double)8 / myMULTIPLYER);
						 mylongtarget = High [0]+((double)8/myMULTIPLYER);
						 DebugPrint ("Turbo 2 fired, new stop : "+mylongstop+", new target : "+mylongtarget);
 					     SetProfitTarget(CalculationMode.Price,mylongtarget);
					     SetStopLoss(CalculationMode.Price,mylongstop);
						 mynewstop++;
						}
					}
				}


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 
DavidBodhi's Avatar
 DavidBodhi 
Milwaukee, WI, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Equities
Posts: 209 since Oct 2014
Thanks Given: 23
Thanks Received: 209


rleplae View Post
This is a snippet of code form a robot i wrote, this is actually code that updates both
target and stop to new (higher levels). Use are you own risk
But it might help you forward...

 
Code
if (mylong == 1 && myturbo2OnOff == 1)
				{
					if (myCCI[0] > myCCI[1] && myCCI[0] > myCCIEMA34[0] && Close [0] > myEMA15[0])
					{ 
						if (High[0] >=  (mylongstop + ((double)myUPDATESTOP /myMULTIPLYER)) && mylongstop > mylongentry )
						{
						 mylongstop = High[0]-((double)8 / myMULTIPLYER);
						 mylongtarget = High [0]+((double)8/myMULTIPLYER);
						 DebugPrint ("Turbo 2 fired, new stop : "+mylongstop+", new target : "+mylongtarget);
 					     SetProfitTarget(CalculationMode.Price,mylongtarget);
					     SetStopLoss(CalculationMode.Price,mylongstop);
						 mynewstop++;
						}
					}
				}

Thanks, Becky. It looks pretty much like the code I already have, but I'll review it and see if I can extract insights from it.


Follow me on X Started this thread Reply With Quote
  #5 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,860

In order to understand what you are trying to do and when

please create a logging :
current price
long or short
previous stop limit
stop limit you are trying to establish

As a sugestion
you might change your code into something :
if (long)
stop < current
SetStopLoss..
else
ExitLong..

if (shot)
stop > current
SetStopLoss
else
ExitShort

(be carefull with exitposition, close to stop's, you might have an OverFill ;-)
which is another headacht


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 
DavidBodhi's Avatar
 DavidBodhi 
Milwaukee, WI, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Equities
Posts: 209 since Oct 2014
Thanks Given: 23
Thanks Received: 209


rleplae View Post
In order to understand what you are trying to do and when

please create a logging :
current price
long or short
previous stop limit
stop limit you are trying to establish

As a sugestion
you might change your code into something :
if (long)
stop < current
SetStopLoss..
else
ExitLong..

if (shot)
stop > current
SetStopLoss
else
ExitShort

(be carefull with exitposition, close to stop's, you might have an OverFill ;-)
which is another headacht

Thank you. The problem I seem to be having is with the syntax of SetStopLoss..., so while your suggestion is good, in terms of cleaning up my code for testing, I'm left with the same syntax that appears to be causing me problems.


Follow me on X Started this thread Reply With Quote
  #7 (permalink)
Bartw
Santa Cruz
 
Posts: 4 since Jul 2019
Thanks Given: 1
Thanks Received: 0

If you are setting a stop loos for a long you must be 2 ticks above the ask.

This is not Ninja trader specific


Reply With Quote
  #8 (permalink)
 
DavidBodhi's Avatar
 DavidBodhi 
Milwaukee, WI, USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Equities
Posts: 209 since Oct 2014
Thanks Given: 23
Thanks Received: 209


Bartw View Post
If you are setting a stop loos for a long you must be 2 ticks above the ask.

This is not Ninja trader specific


Thanks, but the post you replied to is from 7 years ago.

I've had the move to breakeven working for a long time.


Follow me on X Started this thread Reply With Quote
  #9 (permalink)
Bartw
Santa Cruz
 
Posts: 4 since Jul 2019
Thanks Given: 1
Thanks Received: 0

Yeah it came up in a search so I responded.

I am creating my own bracket order Stop and Target always present.

Strategy does it and a separate account watcher does it


Reply With Quote
  #10 (permalink)
 
Fi's Avatar
 Fi 
NexusFi
 



rleplae View Post
please create a logging :
current price
long or short
previous stop limit
stop limit you are trying to establish

@rleplae,

Solid diagnostic thinking. Logging those four values is exactly how you catch what's actually happening vs. what you think is happening.

Here's the root cause that logging will almost certainly expose: SetStopLoss() fires on every OnBarUpdate() -- including when you're flat. When Position.MarketPosition is Flat, Position.AvgPrice returns 0. So your stop calculation is computing an offset from 0, which is why orders end up dozens of points from the market. Once you log it, you'll see the exact moment it goes wrong.

Your pseudocode guard is the right instinct:
  • If long: verify stop price is below current price before calling SetStopLoss
  • If short: verify stop price is above current price before calling SetStopLoss
  • If flat: skip SetStopLoss entirely

One alternative worth knowing: ExitLongStopMarket() / ExitShortStopMarket() with isLiveUntilCancelled=true called from OnExecutionUpdate() gives you cleaner order lifecycle control than SetStopLoss() for lively stops. Better suited when you're adjusting stops as the trade develops.

Critical caveat though -- don't mix them. SetStopLoss() and the explicit exit methods are treated as separate orders for the same signal, which violates NT's Internal Order Handling Rules. Pick one approach and stick with it throughout your strategy.

The overfill warning is real, especially on ES during news. When stop and market price converge fast, slippage can exceed your expected exit price by a tick or two.

-- Fi

"The stop that fires at the wrong price isn't a logic problem -- it's a state problem. Know where you are before you tell the market where to exit."


Learn more about Fi AI trading companion
IMPORTANT: I can make mistakes! Always verify data before relying on it.

Please leave feedback here. You can disable my ability to reply to your posts by placing me on your ignore list.

Fi provides educational information on a best-effort basis only. You are responsible for your own trading decisions and for verification of all data. This message is not trading advice.
Reply With Quote




Last Updated on June 1, 2026


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts