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

Using startTime & endTime with DrawLine(0)

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

    #16
    Hello PaulMohn,

    I am not sure what you mean by the real close and the use of two timestamps for that, the bar has a single close and end time. The BarsType being used calculates the bar times based on the given data for that range of time. The real close of a 1 minute bar would be a single time in 1 minute intervals or 2:11:00 as an example, we shouldn't see seconds being used there.

    If you want to plan a time before a projected time you need to first know what the projected time of that bar would be based on the given current timestamps.

    Using 1 minute as the example, both in realtime:

    If the Time[0] of the last Closed bar (OnBarClose) was 9:00:00 am and we wanted to know 10 seconds before the next bar close of 9:01:00 which would be 9:00:50 then you would have to add 1 minute to the last closed bars time 9:00:00 and then subtract 10 seconds from that value. The new value has no relation to the OnBarClose bar times and would be difficult to use in any meaningful way, you could have just used a time with 1 minute granularity without doing any other math because the seconds wont be used.

    If you are using 1 minute bars and OnEachTick in realtime you could see times which are within the 1 minute bar because that is in realtime building that bar. You could for example see 10 seconds before a bar closes but you need to calculate ahead of time what the bars end time.








    JesseNinjaTrader Customer Service

    Comment


      #17
      Ok, thanks for the explanation. I think I confused Time[0] as being the current/running Time (like Close[0] which is not (only) the "ultimate"/times-up price of the candle, but all the current prices fluctuations while the candle is still active/while the candle period's time is not yet up).
      GetTime() seems to work as intended, so I won't use Time[0] (unless if you would know of a more concise way that would use Time[] instead of GetTime() and work for my end use)).

      I just tested changing my chart timeframe from 1min to 2min and it seems to work (3, vs 4a/4b)

      2 : 17/05/2022 15:44:11
      3 : 17/05/2022 15:44:09
      4a : 17/05/2022 15:46:00
      4b : 17/05/2022 15:45:49
      PHP Code:
      Print("2 : " Time[0]);
      Print(
      "3 : " Time[1]);
      Print(
      "4a : " BarsArray[0].GetTime(CurrentBars[0]));
      Print(
      "4b : " BarsArray[0].GetTime(CurrentBars[0]).Subtract(TimeSpan.FromSeconds(11))); 

      Many thanks!


      Also, I'm getting a compile error with

      PHP Code:
      DateTime myStartTime = new DateTime(BarsArray[0].GetTime(CurrentBars[0]).Subtract(TimeSpan.FromSeconds(11))); 

      NinjaScript File Error Code Line Column
      Testa.cs The best overloaded method match for 'System.DateTime.DateTime(long)' has some invalid arguments CS1502 184 27
      NinjaScript File Error Code Line Column
      Testa.cs Argument 1: cannot convert from 'System.DateTime' to 'long' CS1503 184 40

      But no compile errors with
      PHP Code:
      DateTime myStartTime1 Bars.GetTime(CurrentBars[0]).Subtract(TimeSpan.FromSeconds(11)); 

      It seems myStartTime returns a datetime formated output and not a long?
      So why doesn't it work as well as with myStartTime1 ?

      What fix would you suggest? Thanks!

      Ah I found the fix, it was the syntax simply
      PHP Code:
      DateTime myStartTime BarsArray[0].GetTime(CurrentBars[0]).Subtract(TimeSpan.FromSeconds(11)); 

      No "new DateTime()" allowed.
      but why can't/musn't we add the new DateTime() method? Thanks!
      Last edited by PaulMohn; 05-17-2022, 08:07 AM.

      Comment


        #18
        Hello PaulMohn,


        but why can't/musn't we add the new DateTime() method? Thanks!
        You can use the constructor to create a new datetime, the errors you were getting were caused by the parameters you tried to use. You can see the constructors here: https://docs.microsoft.com/en-us/dot...tframework-4.8

        Theres not an overload that takes a datetime, you would have to extract the time values or use the ticks in the constructor.






        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by maybeimnotrader, Today, 05:46 PM
        0 responses
        6 views
        0 likes
        Last Post maybeimnotrader  
        Started by quantismo, Today, 05:13 PM
        0 responses
        6 views
        0 likes
        Last Post quantismo  
        Started by AttiM, 02-14-2024, 05:20 PM
        8 responses
        166 views
        0 likes
        Last Post jeronymite  
        Started by cre8able, Today, 04:22 PM
        0 responses
        8 views
        0 likes
        Last Post cre8able  
        Started by RichStudent, Today, 04:21 PM
        0 responses
        5 views
        0 likes
        Last Post RichStudent  
        Working...
        X