• 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

Indicator Date/Time from 3 Days prior to current day

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

    Indicator Date/Time from 3 Days prior to current day

    My indicator creates Support/Resistance ZONES that could have been created several days in the past and are still current today.
    I have the valid DateTime that the ZONE was created but can't figure out how many days in the past it was created compared to today?

    Can you help me with the Ninjascript code for the solution please?

    #2
    Hello jkt1120,

    When the zone is created, are you saving the CurrentBar number to a variable so that you can get this later?

    private int actionBarNumber;

    if (/* condition to trigger action */)
    {
    // trigger action
    actionBarNumber = CurrentBar;
    }

    Then on later bars you can get the time of that bar using a barsAgo value from the CurrentBar.

    Print(Time[CurrentBar - actionBarNumber]);
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      My code so far looks like if (ToDay (zoneStartTime) ..... which is the beginning of the Zone

      Comment


        #4
        Hello jkt1120,

        I'm not sure what you are trying to accomplish with this code.

        Are you trying to save the date and time of when an action has occurred?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I'm not saving the CurrentBar when the zone is created but that's an easy fix. If I save CurrentBar when The Zone is created, how do I figure out how many days ago that happened?

          Comment


            #6
            I'm trying to delete zones that were created over 3 days ago

            Comment


              #7
              Hello jkt1120,

              You can compare the time of the current bar to the time of the saved bar to see how many days ago it is.

              Subtracting two dates results in a TimeSpan object which as a TotalDays property.

              Print( (Time[0] - Time[CurrentBar - actionBarNumber]).TotalDays );



              If you are trying to delete a drawing object, this would be done with the tag name.

              if (/* condition to draw object */)
              {
              DrawDot("myDot" + CurrentBar, true, 0, High[0], Brushes.Green);
              actionBarNumber = CurrentBar;
              }

              if (/* condition to remove object */)
              {
              RemoveDrawObject("myDot" + (CurrentBar - actionBarNumber));
              }
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by abdullah, 11-15-2017, 08:44 PM
              11 responses
              822 views
              0 likes
              Last Post NinjaTrader_Kate  
              Started by brunoviveiros, Today, 04:31 AM
              3 responses
              13 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by foxy_rav, Today, 06:31 AM
              1 response
              4 views
              0 likes
              Last Post NinjaTrader_Jim  
              Started by neilzep, Today, 06:42 AM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by teafortwo, Today, 04:26 AM
              3 responses
              9 views
              0 likes
              Last Post NinjaTrader_PaulH  
              Working...
              X