Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plot indicator only in certain time window

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

    Plot indicator only in certain time window

    I am trying to use the Swing indicator in my strategy and I successfully have it marking swing highs and lows. But now I want to constrict it to only identifying swing highs and lows in a certain time window.This was my attempt. It did not work. Anyone can point me in the right direction? Thank you!

    Code:
     sessionStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 3, 0, 0);
                // Set session end time to 4 am
                sessionEnd = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 4, 0, 0);
                DateTime currentTime = Time[CurrentBar];
                if (currentTime > sessionStart && currentTime < sessionEnd)
                {
                    Swing1 = Swing(Close, 5);
                    Swing1.Plots[0].Brush = Brushes.DarkCyan;
                    Swing1.Plots[1].Brush = Brushes.Goldenrod;
                    AddChartIndicator(Swing1);
                }​

    #2
    Originally posted by sierrajpr View Post
    I am trying to use the Swing indicator in my strategy and I successfully have it marking swing highs and lows. But now I want to constrict it to only identifying swing highs and lows in a certain time window.This was my attempt. It did not work. Anyone can point me in the right direction? Thank you!

    Code:
     sessionStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 3, 0, 0);
    // Set session end time to 4 am
    sessionEnd = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 4, 0, 0);
    DateTime currentTime = Time[CurrentBar];
    if (currentTime > sessionStart && currentTime < sessionEnd)
    {
    Swing1 = Swing(Close, 5);
    Swing1.Plots[0].Brush = Brushes.DarkCyan;
    Swing1.Plots[1].Brush = Brushes.Goldenrod;
    AddChartIndicator(Swing1);
    }​
    Have you read this help file entry:
    https://ninjatrader.com/support/help...tindicator.htm
    Warning: This method should ONLY be called from the OnStateChange() method during State.DataLoaded

    One option I would consider is to assign a variable to the Swing indicator and add a plot to replicate the behavior of the native Swing indicator. This plot would be activated when the specified condition is true, and the Reset() command would be used when the condition is not met.

    Check this entry:
    https://ninjatrader.com/support/help...lightsub=reset
    Last edited by trendisyourfriend; 07-22-2023, 08:45 AM.

    Comment


      #3
      Hello sierrajpr,

      Thanks for your post.

      Instead of calling AddChartIndicator(), you could consider adding plots in your strategy by calling the AddPlot() method. Then, create a Time Filter condition in your script and within that Time Filter condition you could assign the Swing() indicator values to the plots you created.

      By doing so, Swing() indicator values will only be assigned to the plots you created when the Time Filter condition is true.

      See the help guide documentation below for more information.

      AddPlot(): https://ninjatrader.com/support/help...t8/addplot.htm
      Creating Time Filter Conditions: https://ninjatrader.com/support/help...ateTimeFilters
      Swing(): https://ninjatrader.com/support/help.../nt8/swing.htm
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by chrischongpdx, Today, 09:39 PM
      0 responses
      7 views
      0 likes
      Last Post chrischongpdx  
      Started by Mountain_cast, Today, 12:41 PM
      2 responses
      9 views
      0 likes
      Last Post Mountain_cast  
      Started by dontpanic, 04-07-2015, 04:42 AM
      4 responses
      1,322 views
      0 likes
      Last Post BeachTrader11807  
      Started by algospoke, Today, 07:54 PM
      0 responses
      5 views
      0 likes
      Last Post algospoke  
      Started by Rxxar, Today, 06:26 PM
      0 responses
      10 views
      0 likes
      Last Post Rxxar
      by Rxxar
       
      Working...
      X