Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Possible to apply "displacement" to a plot that is part of the strategy?

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

    Possible to apply "displacement" to a plot that is part of the strategy?

    Title says it all. I've got a plot AddPlot(Brushes.Red, "GainLevel"); and I'm aware I can apply an offset in an indicator.

    Can I do this the way I'm attempting or do I need to build a customer indicator and then add it to the strategy to pull this off?


    Thanks!

    #2
    Hello DogEars,

    Thank you for your post.

    Are you talking about displacement, like when you apply the indicator to a chart so it plots a few bars in advance or behind the current bar with the value for that bar? Displacement is not a property of a strategy, this is a visual only item which applies to only indicators and really only applies toward manually added indicators.

    Using negative indexes or trying to project into the blank space to the right of the Data Series bars on the chart is not officially supported.
    https://ninjatrader.com/support/foru...072#post836072

    You can custom render anywhere you would like in OnRender() if you wanted to write some estimation logic on your own to decide where to render things if you're trying to displace a plot into the future.
    https://ninjatrader.com/support/foru...606#post789606

    If you're wanting to displace the plot backward, for example, have a value of something you calculated 5 bars ago be the current value for your plot, that you could easily do by computing values on the bar they actually occur on, saving those to a Series<T> data series, then assigning the value of that series 5 bars ago to your current bar's plot value.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Thanks for the reply, appreciate it. Support here is fantastic.

      Comment


        #4
        Going to resurrect this one because what I thought would work isn't quite panning out. I added a Displacement = -10 to my indicator in the defaults. When I load the indicator it functions as expected. The plot shifts backwards where I want it.

        When I add this indicator to a strategy I am unable to see it behave properly. It ignores the Displacement = -10 and I cannot figure out why. Would it not just render the plot exactly the same as I have it defined in the indicator?

        If what I'm doing is impossible, do you have an example of the approach you were mentioning earlier?


        Thanks!

        Comment


          #5
          Here is the code in the indicator

          Code:
           Displacement = -10;
          AddPlot(Brushes.Red, "GainLevel");
          Plots[0].Width = 2;
          Referencing it like this in the strategy

          Code:
           /// <summary>
          /// Set visuals for plots and other indicators
          /// </summary>
          private void SetIndicatorVisuals()
          {
          AddChartIndicator(KalmanFilter(Gain, SmoothInput, VelocityInput));
          }

          Comment


            #6
            Hello DogEars,

            Thank you for your reply.

            You can try overriding the Displacement in State.Historical - the following works for me to displace an SMA plot by 10 bars back:

            Code:
            namespace NinjaTrader.NinjaScript.Strategies
            {
            public class DisplaceIndiPlotStrategyExample : Strategy
            {
            [B]private SMA SMA1[/B];
            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            Description = @"Enter the description for your new custom Strategy here.";
            Name = "DisplaceIndiPlotStrategyExample";
            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;
            }
            else if (State == State.DataLoaded)
            {
            [B]SMA1 = SMA(14);
            AddChartIndicator(SMA1);[/B]
            }
            else if (State == State.Historical)
            {
            [B]SMA1.Displacement = -10;[/B]
            }
            }
            
            protected override void OnBarUpdate()
            {
            //Add your custom strategy logic here.
            }
            }
            }
            Please let us know if we may be of further assistance to you.

            Comment


              #7
              That worked fabulously. I didn't think to try in historical.

              Thanks!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              48 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              126 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              66 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              42 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              46 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X