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!
See more
See less

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:	431
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

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by samish18, 05-04-2024, 12:20 PM
              2 responses
              16 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
              31 responses
              100 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by reynoldsn, 05-04-2024, 02:34 PM
              1 response
              18 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by Vietanhnguyen2hotmailcom, 05-03-2024, 10:29 AM
              5 responses
              41 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by truepenny, Today, 03:45 AM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_RyanS  
              Working...
              X