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

Rectangle & Dates (NT7)

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

    Rectangle & Dates (NT7)

    Hi, I am trying to draw a rectangle on the high/low of a specified date range. I want to use:

    DrawRectangle(string tag, bool autoScale, DateTime startTime, double startY, DateTime endTime, double endY, Color color, Color areaColor, int areaOpacity)

    How would I set the 'startTime' to 9:30 AM and the 'endTime' to 4:00 PM in the code? My session template is 24 hours and I don't want to change that, so I need to specify the times programatically.

    Thanks!

    #2
    Hello Pman777,

    Thank you for writing in.

    You would want to create and assign Datetime variables which you then pass into the Draw.Rectangle method.

    Under public class MyCustomindicator: Indicator, add

    Code:
    private DateTime NineThirty = DateTime.Parse("9:30 AM");
    private DateTime FourThirty = DateTime.Parse("4:30 PM");
    Then under OnBarUpdate,

    Code:
    protected override void OnBarUpdate()
    		{
    	
    			if(CurrentBar<20) return;
    			Draw.Rectangle(this, @"MyCustomStrategy31 Rectangle" , false, NineThirty, Close[0], FourThirty, High[0], Brushes.CornflowerBlue, Brushes.CornflowerBlue, 0);
    		
    		}
    Please let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Mine was an NT7 question ... does answer still apply?

      Comment


        #4
        OK .. .almost got it working but the code:
        private DateTime NineThirty = DateTime.Parse("9:30 AM");
        private DateTime FourThirty = DateTime.Parse("4:30 PM");

        sets the time variables to 2/7/20117 9:30:00 AM and 2/7/2017 4:40:00 PM respectively ... but the date is always 2/7/2017 for every session.

        What I need to produce is 9:30 AM and 4:00 PM for each date of the given session ... for example:
        2/7/20117 9:30:00 2/7/2017 4:40:00 PM
        2/6/20117 9:30:00 2/6/2017 4:40:00 PM
        2/5/20117 9:30:00 2/5/2017 4:40:00 PM
        2/4/20117 9:30:00 2/4/2017 4:40:00 PM


        So ... is there a way to extract only the date portion of "Time[0]" and concatenate it with 9:30:00 AM and 4:30:00 PM to get the full DateTime?

        tx

        Comment


          #5
          the above comment should say "4:30" not "4:40"

          Comment


            #6
            Hello pman777,

            You could use the following,

            Code:
            DateTime aTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 30, 0).AddDays(-1);
            DateTime bTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 14, 30, 0).AddDays(-1);
            Which would give you a day before today, at a time of 9:30am and 2:30PM, then pass these date time objects into the rectangle.

            Code:
            Draw.Rectangle(this, @"Rectangle1", false, aTime, Low[0], bTime, High[0], Brushes.CornflowerBlue, Brushes.CornflowerBlue, 0);
            If you wanted to extract just the date from Time[0], you could use,

            Code:
            string timeString = Time[0].Date.ToString("MM-dd-yyyy");
            To concatenate it with 9:30:00,

            Code:
            string timeStringa = timeString +" 09:30:00";
            Then to turn the concatenated variable into a date time object which you could then pass into the Draw.Rectangle method,

            Code:
            DateTime cTime =DateTime.Parse(timeStringa);
            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by usazencort, Today, 01:16 AM
            0 responses
            1 view
            0 likes
            Last Post usazencort  
            Started by kaywai, 09-01-2023, 08:44 PM
            5 responses
            603 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by xiinteractive, 04-09-2024, 08:08 AM
            6 responses
            22 views
            0 likes
            Last Post xiinteractive  
            Started by Pattontje, Yesterday, 02:10 PM
            2 responses
            21 views
            0 likes
            Last Post Pattontje  
            Started by flybuzz, 04-21-2024, 04:07 PM
            17 responses
            230 views
            0 likes
            Last Post TradingLoss  
            Working...
            X