Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time and drawing lines

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

    Time and drawing lines

    Hi,

    How do I instruct the code to draw the line till 4am or till the end of regular trading hours, which ever is later, taking into account daylight saving. How would the endTime be input? I tried keying in various combinations of 040000 but it got rejected.

    This is the code I'm trying to use:-

    Draw.Line(NinjaScriptBase owner, string tag, bool isAutoScale, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush, DashStyleHelper dashStyle, int width)

    I'm using the attached code which I got from Ninjatrader's ecosystem but when I select the "Extend Line", it is drawing the line way past the end of session - till 11:59pm.

    Thanks in advance.

    Regards

    Kay Wai
    Attached Files
    Last edited by kaywai; 06-10-2021, 03:29 AM.

    #2
    Hello kaywai,

    Thanks for the post.

    To draw a line between two times you would need to first figure out the end time and which you wanted to use.

    You can get the trading hours for the given instrument by using the session iterator: https://ninjatrader.com/support/help...essioniterator

    You could then check if the 4am time or the trading hours time is greater to save whichever is greater to a variable.

    Code:
    DateTime endTime     = sessionIterator.ActualSessionEnd;
    DateTime myEndTime = endTime; 
    DateTime fourAmTime = new DateTime(endTime.Year, endTime.Month, endTime.Day, 4,0,0); 
    if(fourAmTime > endTime)
        myEndTime = fourAmTime;
    Once you have the end time you wanted to use you can supply that as the end time.

    I look forward to being of further assistance.

    Comment


      #3
      Thank you Jesse. That worked like a gem! Appreciate it.

      Regards
      Kay Wai

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      647 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
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X