Announcement

Collapse
No announcement yet.

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.








    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.






        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        557 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X