Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question regarding parameters for Draw.Line

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

    Question regarding parameters for Draw.Line

    I would like to code an indicator which would draw a line which starts of at the start of the current trading day and ends at the close of the actual trading day. I tried to set the parameters of the Draw.Line as follows but there was an error with the sessioniterator part. I have written the relevant time parameters in bold.

    Draw.Line(this, "line1", false, new DateTime(Time[Bars.BarsSinceNewTradingDay].Year, Time[Bars.BarsSinceNewTradingDay].Month, Time[Bars.BarsSinceNewTradingDay].Day, 7, 00, 0),
    j , new DateTime(sessionIterator.ActualTradingDayEndLocal),
    j , Brushes.Brown, DashStyleHelper.Dot , 2);

    Could you please advise me on what is wrong with my use of the session iterator to find the time when the trading day ends or alternatively, if there is a better way to code for the objective I am trying to accomplish, please let me know. Thanks in advance.

    #2
    Hello mbesha,

    Thank you for writing in.

    There is an issue with beta 10 where Draw objects will not initially draw anything until historical data has been reloaded if using an overload that takes in a DateTime parameter. This has been rectified and will be in beta 11.

    As a way to get around this, you can utilize Bars.GetBar() to obtain a barsAgo value for where to draw your line.

    For example:

    Code:
    Draw.Line(this, CurrentBar.ToString(), 0, Close[0], CurrentBar - Bars.GetBar(sessionIterator.ActualTradingDayEndLocal), Close[0], Brushes.Blue);
    More about Bars.GetBar() can be found here: http://ninjatrader.com/support/helpG...us/?getbar.htm

    Alternatively, to do this with DateTime objects:
    Code:
    Draw.Line(this, CurrentBar.ToString(), true, sessionIterator.ActualSessionBegin, Close[0], sessionIterator.ActualTradingDayEndLocal, Close[0], Brushes.Blue, DashStyleHelper.Dash, 5);
    Just make sure you are reloading historical data (right-click chart -> select Reload All Historical Data) in order for the line to appear in beta 10 due to the issue stated at the beginning of the post.

    Make sure you are doing this within an if (Bars.IsFirstBarOfSession) check and that you have called GetNextSession() to calculate the next session:
    Code:
    if (Bars.IsFirstBarOfSession)
    {
         sessionIterator.GetNextSession(Time[0], true);
    
         // logic
    }
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X