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 trader3000a, Today, 04:23 AM
      0 responses
      4 views
      0 likes
      Last Post trader3000a  
      Started by apratm, Today, 03:05 AM
      3 responses
      27 views
      0 likes
      Last Post apratm
      by apratm
       
      Started by 05arminia, Today, 02:48 AM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Marco  
      Started by Stupid_idiot, Yesterday, 11:33 PM
      4 responses
      40 views
      0 likes
      Last Post Stupid_idiot  
      Started by TangoTX, Yesterday, 07:29 PM
      1 response
      19 views
      0 likes
      Last Post NinjaTrader_ChrisSch  
      Working...
      X