myEntry = EnterLong(contracts,"Going Long"); // Enter long market order
if (target > 0) SetProfitTarget(CalculationMode.Ticks, target);
double stop = <some criteria that returns a stop price or 0>;
if (stop > 0) SetStopLoss(CalculationMode.Ticks, stop);
else SetStopLoss(CalculationMode.Ticks, 0);
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Dynamic Stoploss
Collapse
X
-
Dynamic Stoploss
I want to be able to place a market order and set the stoploss for that order based on some criteria. Right now, this is how I'm doing it:
But when an order is created, there is no stoploss set. The profit target works fine, but why is the stoploss not working?Code:Tags: None
-
Hi, did you use TraceOrders to debug? http://www.ninjatrader-support.com/H...aceOrders.html
You also want to use Print() statements to debug your conditions - http://www.ninjatrader-support2.com/...ead.php?t=3418
To see sample code how to change the price of a StopLoss, please see this reference samlpe - http://www.ninjatrader-support2.com/...ead.php?t=3222
-
Originally posted by mrlogik View Postcassb,
Also, check the Log tab in your control center.
What you have should work.
Good thinking, Mr. I do see an error in the log:
Calculated stop order price for strategy 'TJ_BPS ' was smaller/equal 0. No stop order placed.
I see my mistake now. I should be using CalculationMode.Price, not Ticks. D'oh -- it's always something simple isn't it?
Thanks!
Bryan
Comment
-
I've got the same problem with an dynamic stop loss, and I've written an basic strategy (with the use of this example: http://www.ninjatrader.com/support/f...ead.php?t=3222) and I still receive this error:
My strategy:Code:**NT** Calculated stop order price for strategy 'TestStrat' was smaller/equal 0. No stop order placed.
The output window output:PHP Code:#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion namespace NinjaTrader.Strategy { [Description("Enter the description of your strategy here")] public class TestStrat : Strategy { protected override void Initialize() { CalculateOnBarClose = true; } protected override void OnBarUpdate() { if(Position.MarketPosition == MarketPosition.Flat) { SetStopLoss("EnterLong", CalculationMode.Price, 0, false); } if(CrossAbove(EMA(20), EMA(50), 1)) { SetStopLoss("EnterLong", CalculationMode.Price, EMA(50)[0] - ATR(14)[0], false); EnterLong("EnterLong"); Print("EnterLong. Stoploss value is: " + (EMA(50)[0] - ATR(14)[0])); } if (Position.MarketPosition == MarketPosition.Long) { SetStopLoss("EnterLong", CalculationMode.Percent, EMA(50)[0] - ATR(14)[0], false); Print("Adjust Stoploss. Stoploss value is: " + (EMA(50)[0] - ATR(14)[0])); } if(CrossBelow(EMA(20), EMA(50), 1)) { ExitLong("ExitLong", "EnterLong"); } } } }
I would love to hear any suggestion as how to solve this, also partly because I've already encountered numerous difficulties with a simple dynamic stop, so I would love to hear what's the best way to do this.Code:EnterLong. Stoploss value is: 202,539517134472 **NT** Calculated stop order price for strategy 'TestStrat' was smaller/equal 0. No stop order placed. Adjust Stoploss. Stoploss value is: 202,786202213329 Adjust Stoploss. Stoploss value is: 202,982148979163 Adjust Stoploss. Stoploss value is: 203,229759331933 Adjust Stoploss. Stoploss value is: 203,319350754973 Adjust Stoploss. Stoploss value is: 203,429408226915
Regards,
Comment
-
Thanks Bertrand and Cassb for your comments, highly appreciated.
I've incorporated your suggestions, and found the problem. Instead of CalculationMode.Price, I had used CalculationMode.Percent. In the following statement this is corrected:
Woops, such an simple error that's quite shamefulPHP Code:if (Position.MarketPosition == MarketPosition.Long) { Print(Time[0].ToShortDateString() + " Adjust Stoploss. Stoploss value is: " + (EMA(50)[0] - ATR(14)[0])); SetStopLoss("EnterLong", CalculationMode.Price, EMA(50)[0] - ATR(14)[0], false); }
, so sorry for bothering both of you with this question. 
Regards,
Comment
-
No worries -- I've made that same error myself! :-)Originally posted by J_o_s View PostThanks Bertrand and Cassb for your comments, highly appreciated.
I've incorporated your suggestions, and found the problem. Instead of CalculationMode.Price, I had used CalculationMode.Percent. In the following statement this is corrected:
Woops, such an simple error that's quite shamefulPHP Code:if (Position.MarketPosition == MarketPosition.Long) { Print(Time[0].ToShortDateString() + " Adjust Stoploss. Stoploss value is: " + (EMA(50)[0] - ATR(14)[0])); SetStopLoss("EnterLong", CalculationMode.Price, EMA(50)[0] - ATR(14)[0], false); }
, so sorry for bothering both of you with this question. 
Regards,
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
668 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
377 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
110 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
575 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
580 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment