Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plot indicator only in certain time window

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

  • NinjaTrader_BrandonH
    replied
    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

    Leave a comment:


  • trendisyourfriend
    replied
    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.

    Leave a comment:


  • sierrajpr
    started a topic Plot indicator only in certain time window

    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);
                }​

Latest Posts

Collapse

Topics Statistics Last Post
Started by Mindset, 04-21-2026, 06:46 AM
0 responses
88 views
0 likes
Last Post Mindset
by Mindset
 
Started by M4ndoo, 04-20-2026, 05:21 PM
0 responses
134 views
0 likes
Last Post M4ndoo
by M4ndoo
 
Started by M4ndoo, 04-19-2026, 05:54 PM
0 responses
68 views
0 likes
Last Post M4ndoo
by M4ndoo
 
Started by cmoran13, 04-16-2026, 01:02 PM
0 responses
119 views
0 likes
Last Post cmoran13  
Started by PaulMohn, 04-10-2026, 11:11 AM
0 responses
69 views
0 likes
Last Post PaulMohn  
Working...
X