Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 bortz, 11-06-2023, 08:04 AM
    47 responses
    1,606 views
    0 likes
    Last Post aligator  
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    9 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    19 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    6 views
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    15 views
    0 likes
    Last Post Javierw.ok  
    Working...
    X