The chart you have provide a screenshot of appears have a script on it that is calling Draw.Dot().
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Plot variable take profit and stop loss
Collapse
X
-
-
-
Hello wagner4691
Here is some code that might get you most of what you might want. See the attached pic for what this does.
You will have to set the variables in OnOrderUpdate to make this work.
Hope this helps. Cheers!Code:// Entry Order Price, Stop Loss and Profit Target Y coordinate variables are set in OnOrderUpdate when a long or short order is submitted (thus this code will show the lines even when the order is unfilled) // Also in OnOrderUpdate, OrderLBar/OrderSBar is set to CurrentBar when the long or short order is submitted (for the X coordinate calculation) // The Stop Loss and Profit Target Y coordinates are again set below to ensure that the coordinates are updated if the Stop Loss and/or Profit Target is subsequently adjusted if (StopLossOrder != null) { OrderLSLCoord = StopLossOrder.StopPrice; OrderSPTCoord = StopLossOrder.StopPrice; } if (ProfitTargetOrder != null) { OrderLPTCoord = ProfitTargetOrder.LimitPrice; OrderSSLCoord = ProfitTargetOrder.LimitPrice; } // This will prevent the Entry Order line from overwriting Stop Loss or Profit Target lines in case either is adjusted to the breakeven price if (OrderLSLCoord == OrderAvgPrice || OrderSPTCoord == OrderAvgPrice || OrderLPTCoord == OrderAvgPrice || OrderSSLCoord == OrderAvgPrice) OrderPlotHide = true; else OrderPlotHide = false; // For performance, the line display is inhibited during Optimization if (Prop000002StrategyOptimize.Equals(CustomEnumNamespace.StrategyOptimize.No)) { if (OrderL != null) { Draw.Line(this, "LPT-"+CurrentBar, true, CurrentBar - OrderLBar, OrderLPTCoord, -1, OrderLPTCoord, Brushes.Green, DashStyleHelper.Solid, 3); Draw.Line(this, "LSL-"+CurrentBar, true, CurrentBar - OrderLBar, OrderLSLCoord, -1, OrderLSLCoord, Brushes.Green, DashStyleHelper.Solid, 3); Draw.Line(this, "LPRICE-"+CurrentBar, true, CurrentBar - OrderLBar, OrderLPrice, -1, OrderLPrice, (!OrderPlotHide ? Brushes.Yellow : Brushes.Transparent), DashStyleHelper.Dash, 3); } if (OrderS != null) { Draw.Line(this, "SPT-"+CurrentBar, true, CurrentBar - OrderSBar, OrderSSLCoord, -1, OrderSSLCoord, Brushes.Red, DashStyleHelper.Solid, 3); Draw.Line(this, "SSL-"+CurrentBar, true, CurrentBar - OrderSBar, OrderSPTCoord, -1, OrderSPTCoord, Brushes.Red, DashStyleHelper.Solid, 3); Draw.Line(this, "SPRICE-"+CurrentBar, true, CurrentBar - OrderSBar, OrderSPrice, -1, OrderSPrice, (!OrderPlotHide ? Brushes.Yellow : Brushes.Transparent), DashStyleHelper.Dash, 3); } }
Comment
-
Thank you very much for your help but it is unbelivable that a software like NT does not have a very basic feature like that in a simple way like printscreen I show.
Comment
-
Write script to draw line/hash/dot/whatever in SetDefaults after your default variable assignments. Looks like:
House the stop loss price in a variable, mine is named "stoplosss." Looks something like (my stop loss position is unique and uses indicators to calculate, use your own variables to make this work for you):Code:AddPlot(new Stroke(Brushes.Red,2), PlotStyle.Hash, "Stop loss trigger");
For Long:
For Short:Code:if (Position.MarketPosition == MarketPosition.Long) { stoplosss = order.AverageFillPrice - Math.Round(stoploss * SMAatr[0], 2); }
Set the Value of the Plot equal to stop loss level when a position is open, looks like:Code:if (Position.MarketPosition == MarketPosition.Short) { stoplosss = order.AverageFillPrice + Math.Round(stoploss * SMAatr[0] / 2, 2); }
Make sure that the variable, in this case stoplosss, changes dynamically based on whatever rules you like. I have too many rules for this and my rules are proprietary so I can't post the script.Code:if (Position.MarketPosition == MarketPosition.Long || Position.MarketPosition == MarketPosition.Short) { Value[0] = stoplosss; }
Comment
-
This is a conversion of the NT7 misc ProfitTargetTrailingStop_101b Stop Strategy Framework Please contact the original author for any questions or comments. NT8‐ Added optional plot lines for Profit target and Stop. 7-8-2020 Changed the Calculate.OnBarClose to Calculate.OnPriceChange and relocated entry logic for best practice
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
62 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
134 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
75 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
50 views
0 likes
|
Last Post
|

Comment