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 GLFX005, Today, 03:23 AM
      0 responses
      1 view
      0 likes
      Last Post GLFX005
      by GLFX005
       
      Started by XXtrader, Yesterday, 11:30 PM
      2 responses
      11 views
      0 likes
      Last Post XXtrader  
      Started by Waxavi, Today, 02:10 AM
      0 responses
      6 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Started by TradeForge, Today, 02:09 AM
      0 responses
      12 views
      0 likes
      Last Post TradeForge  
      Started by Waxavi, Today, 02:00 AM
      0 responses
      2 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Working...
      X