• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time [] & ToTime()

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

    Time [] & ToTime()

    Do Time and/or ToTime ever look at only the computer time or do they always look at the chart time?

    Reason being, the computer time may be 9:30 AM but the time stamp on the 1 hour candle would be 10:00 AM on the chart.

    #2
    Hello jg123,

    When using Time[0] this is simply referring to the datetime object stored in the bar it is currently accessing. So to answer your question, Time[] is looking at the bar time and not your computer time.

    ToTime and also ToDay convert the datetime object into a integer value to make comparing times or dates easy.

    If you are looking to get the system time you do have access to the C# datetime methods.
    Here is a MSDN page about Datetime in C#
    http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx

    Please let me know if I may be of additional assisstance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Great thank you

      This does lead me to 2 questions.

      In my code I use both Time & ToTime.

      First:
      In my user defined Parameters, I have a start time designed to be the beginning of a range. The Parameters code that I use is here:

      Code:
              [GridCategory("Parameters")]
      		[Gui.Design.DisplayName("1 Start Range")]
              public DateTime StartRange
              {
                  get { return startRange; }
                  set { startRange = value; }
              }
      Here is how startRange is calculated in the Variables:

      Code:
              private DateTime startRange = DateTime.Today.AddHours(2); // Hour that the range will start
      but, whenever I bring up the properties window in order to start the strategy and set the user defined inputs, the wrong date comes up. For example, in the screenshot attached, you will see the properties window. This is a brand new instance of this window immediately after restarting NinjaTrader and connecting it to a data feed. It says 8 July rather than today which is 14 July. Why is that, do you think, and how can I set it so that it will automatically start up with today's date?

      2nd Question:
      This is a debugging question.

      I calculate an overnight range and then, at or after 9:00 AM Germany time, if the price breaks out of that range, I enter the market. Today, it did not enter the market at the correct time (It should have been at 9:08 AM). It entered the market on a break of the 10:00 candle when the 15:00 candle broke it.

      Here is the code that is used to in order to enter on the breakout.

      Code:
      				if (LongEntryOCO == null
      					&& ShortEntryOCO == null
      					&& ToTime(Time[0]) >= ToTime(endRangeHr, endRangeMin, 00)
      					&& ToTime(Time[0]) < ToTime(removeOrderHr, removeOrderMin,00)
      					&& High[0] >= LongEntryPrice
      					&& restrictTrade == false)
      				{
      					LongEntryOCO = EnterLong(positionSize, "BreakoutLongOCO");
      				}
      Here are the calculations for the variables:

      Code:
             	private int endRangeHr = 10; // Hour that the range will end
      	private int endRangeMin = 00; // Minute that the range will end
              private int removeOrderHr = 19; // Hour that unfilled entry orders will be removed
      	private int removeOrderMin = 00; // Minute that that unfilled entry orders will be removed
      Can you please help me figure out why this did not trigger at 9:08?

      for endRangeHour, I have it set to 10. The reason is because I am trading this on hourly charts and I want it to trigger at 9:00 AM or later and the time Stamp for a tick at 9:00 AM on an hourly chart is 10:00 AM. So it seems to me that this should have triggered earlier than it did.

      I am attaching a screenshot of the chart also.
      Attached Files

      Comment


        #4
        Hello,

        For your first question, I believe that this is caused by the variable being set where you are declaring it; I don't think the script can get a date before the script is initialized, so I just added
        Code:
         
        protected override void Initialize()
        {
        startRange = DateTime.Today.AddHours(2);
        }
        That gets the date and sets it before the user can see the properties appear and displays the correct date.

        For your second question I would like to get a few more details on how the strategy is run before I try to answer you.

        From what you described this is how I interpreted it. -> You are running a strategy that checks if the current bars time is after 9 and before 10, if so and the price breaks, then submit an order, am I correct in thinking this is the logic you are going for?.

        I would like to ask, are you running this on CalculateOnBarClose = false ?

        If you have calculate on bar close set to true and you are using an hourly chart I would expect it to not place trades in between 9 and 10 because it is only processing as each bar closes so if the condition permitted as the 9 bar closed and moved to the 10 bar, it would place the order.

        Another way you could possibly check what is happening is after trading is done today, if you have the market replay data available either by recording or downloading, to playback the day up until the point where it makes the error trade.
        This would probably be the best way to check this as you can pause, rewind and retry with Print() statements or whatever else you may need to add in order to debug the logic.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks for your reply Jesse.

          will look into the addition that you suggested for the Initialize method.

          For further clarification on Question #2.

          I am looking for a breakout that happens between 9:00 AM and 18:00. If an order is not triggered and filled within that time, then it will call the CancelOrder() method.

          CalculateOnBarclose is set to False.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Tradarr, Today, 06:25 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_JoshG  
          Started by cocopod, Today, 04:47 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_JoshG  
          Started by digibob, Today, 02:47 AM
          2 responses
          14 views
          0 likes
          Last Post NinjaTrader_Kate  
          Started by mntemel, Today, 03:31 PM
          4 responses
          21 views
          0 likes
          Last Post mntemel
          by mntemel
           
          Started by mrlucky1x, Today, 03:14 PM
          2 responses
          7 views
          0 likes
          Last Post mrlucky1x  
          Working...
          X