Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get diference of time between two bars

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

    How to get diference of time between two bars

    Hello,
    I try to create an indicator showing the difference in time between two bars.
    Using the NinjaScript editor /New Indicator,

    I only create two plots:
    the Cero line ( named as "Cero" ), and Volatility bars ( named "Volat")


    The only code that I write in the OnBarUpdate() is this:


    protected override void OnBarUpdate()
    {
    if(CurrentBars[0] < 1 )
    return;

    Cero[0]=0;
    Volat[0]= ToTime(Time[0])- ToTime(Time[1]);

    }


    And when I compile, there is a message of "Unhandled Exception.....Click image for larger version

Name:	image.png
Views:	41
Size:	8.1 KB
ID:	1334066

    And then NinjaTrader8 is closed.
    ¿Where is the mistake??
    ¿How to get the time difference between two bars correctly??
    Thanks.


    #2
    I forget to tell that the bars I use are renko bars, not time based bars.

    Whith this type of bars, the creation of each new bar, with explosions of high volatility, can be in less than a second, and I want to use that indicator as a filter, not entering trades when new bars are created in less than 1 second, because is not good idea enter with high volatility, stops can be hit very easy.

    Comment


      #3
      Hello Parmenides48,

      Are you trying to get a difference in time between two bars or price? The code you have now is making a difference in time which is not something that you could plot. The difference between two bars in price would be:

      Volat[0]= Close[0] - Close[1];
      JesseNinjaTrader Customer Service

      Comment


        #4
        Hello,
        I want to get difference of time, not price.
        If time difference is in hh mm ss, and I cant plot it, how can I convert hours and minutes in seconds, and add all the seconds between this two bars. ?
        What I want is to plot the total amount of seconds ( integer) , to see the "speed" of creation of every range bar.

        Comment


          #5
          Hello Parmenides48,

          You would have to figure out what time value you wanted to plot, for example seconds. You can use the results TotalSeconds property



          (Time[0] - Time[1]).TotalSeconds

          JesseNinjaTrader Customer Service

          Comment


            #6
            I am going to work on it.
            Infinite thanks.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by brucerobinson, Today, 07:08 AM
            3 responses
            18 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by Dudley, Today, 09:52 AM
            2 responses
            10 views
            0 likes
            Last Post Dudley
            by Dudley
             
            Started by Johnny, Yesterday, 12:39 PM
            6 responses
            33 views
            0 likes
            Last Post Johnny
            by Johnny
             
            Started by Saronna, Today, 02:08 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by celtey, 03-21-2025, 09:46 AM
            6 responses
            80 views
            0 likes
            Last Post celtey
            by celtey
             
            Working...
            X