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

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 ラリー, 10-05-2022, 02:10 PM
              3 responses
              54 views
              0 likes
              Last Post ラリー  
              Started by hbolorin, Yesterday, 01:05 PM
              2 responses
              19 views
              0 likes
              Last Post hbolorin  
              Started by rblunsom, 02-15-2019, 12:19 PM
              6 responses
              3,199 views
              0 likes
              Last Post Bullseye  
              Started by rasdaka, Today, 01:38 AM
              0 responses
              13 views
              0 likes
              Last Post rasdaka
              by rasdaka
               
              Started by Spiderbird, 10-03-2022, 10:15 PM
              3 responses
              68 views
              0 likes
              Last Post Spiderbird  
              Working...
              X