The chart you have provide a screenshot of appears have a script on it that is calling Draw.Dot().
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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.
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:
Code:AddPlot(new Stroke(Brushes.Red,2), PlotStyle.Hash, "Stop loss trigger");
For Long:
Code:if (Position.MarketPosition == MarketPosition.Long) { stoplosss = order.AverageFillPrice - Math.Round(stoploss * SMAatr[0], 2); }
Code:if (Position.MarketPosition == MarketPosition.Short) { stoplosss = order.AverageFillPrice + Math.Round(stoploss * SMAatr[0] / 2, 2); }
Code:if (Position.MarketPosition == MarketPosition.Long || Position.MarketPosition == MarketPosition.Short) { Value[0] = stoplosss; }
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by samish18, 05-04-2024, 12:20 PM
|
2 responses
16 views
0 likes
|
Last Post Today, 07:47 AM | ||
Decrease the size of the RegionHIghLightY on each tick when the price touches it
by cmtjoancolmenero
Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
|
31 responses
100 views
0 likes
|
Last Post Today, 07:45 AM | ||
Started by reynoldsn, 05-04-2024, 02:34 PM
|
1 response
18 views
0 likes
|
Last Post Today, 07:39 AM | ||
Started by Vietanhnguyen2hotmailcom, 05-03-2024, 10:29 AM
|
5 responses
41 views
0 likes
|
Last Post Today, 07:33 AM | ||
Started by truepenny, Today, 03:45 AM
|
1 response
14 views
0 likes
|
Last Post Today, 07:29 AM |
Comment