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

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.
    JesseNinjaTrader Customer Service

    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 LawrenHom, Today, 10:45 PM
      0 responses
      3 views
      0 likes
      Last Post LawrenHom  
      Started by love2code2trade, Yesterday, 01:45 PM
      4 responses
      28 views
      0 likes
      Last Post love2code2trade  
      Started by funk10101, Today, 09:43 PM
      0 responses
      7 views
      0 likes
      Last Post funk10101  
      Started by pkefal, 04-11-2024, 07:39 AM
      11 responses
      37 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Yesterday, 08:51 AM
      8 responses
      44 views
      0 likes
      Last Post bill2023  
      Working...
      X