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

finding calculating time difference

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

    finding calculating time difference

    hi
    could someone help me how to find out todays firstbarofsession time and then subtract 24 hours from it

    #2
    easyfying, you mean something like the below snippet?

    if (Bars.FirstBarOfSession)
    test = Time[0].AddHours(24);

    That would Add 24 hrs to the end bar time of the first bar of the session.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      basically what i am trying to plot is if its an upday ,the complete session colour should be green and if its down day it shoud be red.following is my code but it only drawss the last bar of session...pls advise
      Code:
      if ( Bars.BarsSinceSession >=0)
                      
                  {
                  if ((CurrentDayOHL().CurrentOpen[0] < Close[0]) &&  (ToTime(Time[0]) > 215900))
                      
                      {
                          BackColor = Color.FromArgb(100, Color.LightGreen);
                          
                      }
                  
                  if ((CurrentDayOHL().CurrentOpen[0] > Close[0]) &&  (ToTime(Time[0]) > 215900))
                      {
                          BackColor = Color.FromArgb(100, Color.LightPink);
                      }
                  }

      Comment


        #4
        easyfying, that's because you chose to do the coloring only from a certain time on for the bars where the condition holds true, you're not coloring the past bars at this point.

        You can do that however with the BackColorSeries by providing how many bars back to color via the index - https://www.ninjatrader.com/support/...olorseries.htm
        BertrandNinjaTrader Customer Service

        Comment


          #5
          yes i thought about it but problem is i am developing indicator for linebreak chart and there i cant give exact number of bars since session begin...because everyday there will be different numbers of bars formed

          Comment


            #6
            easyfying, correct but the BarsSinceSession property should reflect that. It would not be a static amount for the time based session, so giving you the actual bar count per session.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              thanks.
              i wanted to plot background colour depending upon if the session was up or down.below code is working for me.but problem is the indicator shows rectangle only for previous day and not for all days.

              Code:
                          if (Bars.FirstBarOfSession)
                          {
                              if(PriorDayOHLC().PriorOpen[0] < PriorDayOHLC().PriorClose[0])
                              
                                  
                                  {
                                      DrawRectangle("Colorupdown", true, Time[1], PriorDayOHLC().PriorLow[0], Time[1].AddHours(-24), PriorDayOHLC().PriorHigh[0], Color.Transparent, Color.Green,2);
                         
                                  }
                              
                          else if(PriorDayOHLC().PriorOpen[0] > PriorDayOHLC().PriorClose[0])
                              
                                  
                                  {
                                      DrawRectangle("Colorupdown", true, Time[1], PriorDayOHLC().PriorLow[0], Time[1].AddHours(-24), PriorDayOHLC().PriorHigh[0], Color.Transparent, Color.Pink,2);
                         
                                  }
                          }

              Comment


                #8
                The issue here is that you're really only drawing / modifying one object all the time by using the same tag id - namely the Colorupdown

                When you are settings things for the new day / session you want to use a new tag id as well so a new draw object would get created and you would be able to see the history as desired.

                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  thank you.it solved it..

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by algospoke, Today, 06:40 PM
                  0 responses
                  9 views
                  0 likes
                  Last Post algospoke  
                  Started by maybeimnotrader, Today, 05:46 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post maybeimnotrader  
                  Started by quantismo, Today, 05:13 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post quantismo  
                  Started by AttiM, 02-14-2024, 05:20 PM
                  8 responses
                  168 views
                  0 likes
                  Last Post jeronymite  
                  Started by cre8able, Today, 04:22 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post cre8able  
                  Working...
                  X