Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Creating chart makers for profit targets and stop losses for NT8 Strategy

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

    Creating chart makers for profit targets and stop losses for NT8 Strategy

    Hi,

    I have a strategy I built and I would like to display the line and price marker as the order is in process. I have seen something like this
    Click image for larger version

Name:	Screenshot 2023-04-06 at 19.00.43.png
Views:	203
Size:	97.5 KB
ID:	1244934
    Drawing or rendering the line is simple, as done in Indicator. However, the Price marker is more of a challenge. The below post tries to answer it, but somehow NT8 doesn't support PaintPriceMarkers or updating plots, which were added by AddPlot. https://forum.ninjatrader.com/forum/...nd-stop-losses

    Any idea how to achieve the above visual?

    #2
    Hello Shai Samuel,

    There is not a way to render in the price scale, to get markers like you have shown you would need to add plots so the plot price markers are shown in the scale. Strategies can add plots and you can update or reset the plots value as frequently as you like.

    Comment


      #3
      Thank you Jessy for your quick response. I am trying to achieve this, but for some reason this simple little code doesn't compile (on 8.1.1.3 64-bit):

      Code:
      namespace NinjaTrader.NinjaScript.Strategies
      {
          public class AACustomStrategy : Strategy
          {
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description                                    = @"Enter the description for your new custom Strategy here.";
                      Name                                        = "AACustomStrategy";
                      Calculate                                    = Calculate.OnBarClose;
                      EntriesPerDirection                            = 1;
                      EntryHandling                                = EntryHandling.AllEntries;
                      IsExitOnSessionCloseStrategy                = true;
                      ExitOnSessionCloseSeconds                    = 30;
                      IsFillLimitOnTouch                            = false;
                      MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                      OrderFillResolution                            = OrderFillResolution.Standard;
                      Slippage                                    = 0;
                      StartBehavior                                = StartBehavior.WaitUntilFlat;
                      TimeInForce                                    = TimeInForce.Gtc;
                      TraceOrders                                    = false;
                      RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                      StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                      BarsRequiredToTrade                            = 20;
                      // Disable this property for performance gains in Strategy Analyzer optimizations
                      // See the Help Guide for additional information
                      IsInstantiatedOnEachOptimizationIteration    = true;
      
                      // *** My custom strategy plot
                      PaintPriceMarkers                            = true;
                      AddPlot(Brushes.Red, "OrderStop");
                      AddPlot(Brushes.Green, "OrderTarget");
                  }
                  else if (State == State.Configure)
                  {
                  }
              }
      
              protected override void OnBarUpdate()
              {
                  // *** My custom strategy plot
                  OrderStop[0] = Close[0]+20*TickSide;
                  OrderTarget[0] = Close[0]-20*TickSide;
              }
          }
      }​
      Last edited by Shai Samuel; 04-06-2023, 10:26 AM.

      Comment


        #4
        Hello Shai Samuel

        From the given code you haven't created public properties for the plots you added. You can use the indicator wizard to generate code for plots and then copy that to your strategy. Alternatively you can use the Values collection:

        Values[0][0] = Close[0]+20*TickSide;
        Values[1][0] = Close[0]-20*TickSide;​

        Comment


          #5
          Thank you Jesse, you are correct.

          Still PaintPriceMarkers doesn't work with Strategy. Any ideas?

          Comment


            #6
            Hello Shai Samuel,

            I am not certain I understand, are you trying to turn the markers off?

            PaintPriceMarkers is for indicators only to toggle the price markers on or off as a default. The price markers will automatically appear when using a plot from a strategy, if you wanted to remove them you would either not set a plot value or if you have reset the plot value to clear it.

            Comment


              #7
              Thanks for your reply Jesse. I see the PriceMarker for the the price, but I don't see PriceMarkers for the plots. Here is my screen and my simple code:

              Click image for larger version  Name:	Screenshot 2023-04-06 at 20.45.37.png Views:	0 Size:	92.5 KB ID:	1244975

              Code:
              namespace NinjaTrader.NinjaScript.Strategies
              {
                  public class AACustomStrategy : Strategy
                  {
                      protected override void OnStateChange()
                      {
                          if (State == State.SetDefaults)
                          {
                              Description                                    = @"Enter the description for your new custom Strategy here.";
                              Name                                        = "AACustomStrategy";
                              Calculate                                    = Calculate.OnBarClose;
                              EntriesPerDirection                            = 1;
                              EntryHandling                                = EntryHandling.AllEntries;
                              IsExitOnSessionCloseStrategy                = true;
                              ExitOnSessionCloseSeconds                    = 30;
                              IsFillLimitOnTouch                            = false;
                              MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                              OrderFillResolution                            = OrderFillResolution.Standard;
                              Slippage                                    = 0;
                              StartBehavior                                = StartBehavior.WaitUntilFlat;
                              TimeInForce                                    = TimeInForce.Gtc;
                              TraceOrders                                    = false;
                              RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                              StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                              BarsRequiredToTrade                            = 20;
                              // Disable this property for performance gains in Strategy Analyzer optimizations
                              // See the Help Guide for additional information
                              IsInstantiatedOnEachOptimizationIteration    = true;
                              AddPlot(Brushes.Red, "OrderStop");
                              AddPlot(Brushes.Green, "OrderTarget");
                          }
                      }
              
                      protected override void OnBarUpdate()
                      {
                          //Add your custom strategy logic here.
                          double tickSize = this.TickSize;
                          Values[0][0] = High[0]+10*tickSize;
                          Values[1][0] = Low[0]-10*tickSize;
                      }
                  }
              }
              Attached Files
              Last edited by Shai Samuel; 04-06-2023, 11:53 AM.

              Comment


                #8
                Hello Shai Samuel,

                After further research it does appear that strategy based AddPlot is currently working differently from indicators AddPlot, I will forward this to development to review that situation.

                To accomplish the goal it looks like you would need to add a indicator for the purpose of plotting the strategy value.

                You can either add that price logic to the indicator directly, for example you always want 2 lines plotted with those specific values. You can otherwise use a dummy indicator that has no logic of its own and have it read values from your strategy. We have a sample of how to plot values from a strategy using an indicator following link. The strategy calls the indicator in its OnBarUpdate so the indicator processes changes for the plot and uses AddChartIndicator to display it.

                For what you want to do you would need to look at the SampleOverlayPlot indicator in the sample so it displays on the same panel as the strategy by using IsOverlay = true;

                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
                130 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                70 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