Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plot variable take profit and stop loss

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Hello wagner4691,

    The chart you have provide a screenshot of appears have a script on it that is calling Draw.Dot().
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Sorry but it is not clear, can you give me an exemple?

      Comment


        #18
        How can I draw dots with the SL and TP like the chart I show you?

        Comment


          #19
          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);
                          }
                      }
          Hope this helps. Cheers!
          Click image for larger version

Name:	ENTRY-PT-SL.JPG
Views:	527
Size:	75.4 KB
ID:	1086667

          Comment


            #20
            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


              #21
              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");
              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):

              For Long:
              Code:
              if (Position.MarketPosition == MarketPosition.Long)
                          {
                          stoplosss = order.AverageFillPrice - Math.Round(stoploss * SMAatr[0], 2);
              }
              For Short:
              Code:
              if (Position.MarketPosition == MarketPosition.Short)
                          {
                          stoplosss = order.AverageFillPrice + Math.Round(stoploss * SMAatr[0] / 2, 2);
              }
              Set the Value of the Plot equal to stop loss level when a position is open, looks like:
              Code:
              if (Position.MarketPosition == MarketPosition.Long || Position.MarketPosition == MarketPosition.Short)
                          {
                          Value[0] = stoplosss;
                          }
              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.

              Comment


                #22
                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
                54 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                131 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                73 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                44 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                49 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X