Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to use Drawing Tools on Secondary AddDataSeries

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

    How to use Drawing Tools on Secondary AddDataSeries

    Dear Support,

    I have added a larger time frame secondary series and simply want to draw the a line beginning with the current close of the secondary series as shown bellow:

    Code:
    else if (State == State.Configure)
    {
    // Adds a secondary bar object to the indicator
    [COLOR=#3498db]AddDataSeries(BarsPeriodType.Week, 1);[/COLOR]
    }
    }
    
    protected override void OnBarUpdate()
    {
    // ensure both series have at least one bar
    if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
    return;
    
    [COLOR=#3498db]Draw.Line(this, "Prwc" , false, [/COLOR][COLOR=#e74c3c]0[/COLOR][COLOR=#3498db], Closes[1][0], [/COLOR][COLOR=#e74c3c]-5[/COLOR][COLOR=#3498db], Closes[1][0], Brushes.LightGray, DashStyleHelper.Solid, 4);[/COLOR]
    
    }
    The above Draw.Line statement works but will draw the line based on primary series bar index.

    1. Is it possible to Draw.Line based on secondary bar indexes?
    2. If so, what is the proper secondary bar index to use instead 0 and -5 so that the line is drawn based on the secondary bar series?

    Many Thanks.
    Last edited by aligator; 10-06-2020, 09:07 AM.

    #2
    Hello aligator, thanks for your post.


    If you need to draw a line into the future then SharpDX must be used in the OnRender method. Using negative values to index bars is not supported. I made a simple test that will draw a line based on the secondary series:


    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class TestWeeklySeries : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "TestWeeklySeries";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Week, 1);
    }
    }
    
    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
    return;
    
    if(BarsInProgress == 1)
    {
    Draw.Line(this, "WeeklyLine" + CurrentBar, 1, Closes[1][0], 0, Closes[1][0], Brushes.Red);
    }
    }
    }
    }
    Please let me know if I can assist any further.



    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hello aligator, thanks for your post.


      If you need to draw a line into the future then SharpDX must be used in the OnRender method. Using negative values to index bars is not supported. I made a simple test that will draw a line based on the secondary series:


      Code:
      namespace NinjaTrader.NinjaScript.Indicators
      {
      public class TestWeeklySeries : Indicator
      {
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Indicator here.";
      Name = "TestWeeklySeries";
      Calculate = Calculate.OnBarClose;
      IsOverlay = true;
      DisplayInDataBox = true;
      DrawOnPricePanel = true;
      DrawHorizontalGridLines = true;
      DrawVerticalGridLines = true;
      PaintPriceMarkers = true;
      ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
      //Disable this property if your indicator requires custom values that cumulate with each new market data event.
      //See Help Guide for additional information.
      IsSuspendedWhileInactive = true;
      }
      else if (State == State.Configure)
      {
      AddDataSeries(Data.BarsPeriodType.Week, 1);
      }
      }
      
      protected override void OnBarUpdate()
      {
      if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
      return;
      
      if(BarsInProgress == 1)
      {
      Draw.Line(this, "WeeklyLine" + CurrentBar, 1, Closes[1][0], 0, Closes[1][0], Brushes.Red);
      }
      }
      }
      }
      Please let me know if I can assist any further.


      Thank you ChrisL.

      Your code works just like my version in the Post#1, it only draws from 1 to 0 on bar index vs 0 to -1 and plots historical lines. I guess I may not have communicated well, I'll give it another try:

      Let's say you have a Daily chart and you will attach your simple indicator that adds the Weekly AddDataSeries and draws a line on the weekly close.

      When the above Draw.Line is implemented it uses the Close[1][0] from the Weekly series for Y value, but uses the Daily bar index for X value. This is fine if you want to show all historical drawn lines. However, I am only interested in the last drawn line and for that I have dropped the "+ CurrentBar". This causes the line to begin on current day instead of at the beginning of current week (secondary weekly series).

      The question is how to configure the Draw.Line statement to use BOTH the Y and X values from the secondary weekly series. Is that possible? If so, how?

      In case you want to try, just drop the "+CurrentBar" in the draw.line statement and attach your sample indicator to a daily (or smaller time frame) chart to see the difference.

      Note: I know I can accomplish what I want by superimposing a Weekly chart (with a line drawn on the current close) on a Daily chart, but I want to avoid having two charts superimposed.

      Thanks.

      Comment


        #4
        Hello aligator, thanks for your reply.

        The beginning of the week needs to be captured during the historical data run. For each bar, you would check it against DateTime.Now to determine if the Time[0] timestamp falls within the current week, if it does, draw the line.

        I found a guide on working with the DateTime object here:
        https://www.tutorialsteacher.com/csh...A59%3A59%20P.M.

        Please let me know if I can assist any further.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        574 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X