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 CortexZenUSA, Today, 12:53 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by CortexZenUSA, Today, 12:46 AM
              0 responses
              1 view
              0 likes
              Last Post CortexZenUSA  
              Started by usazencortex, Today, 12:43 AM
              0 responses
              5 views
              0 likes
              Last Post usazencortex  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              168 responses
              2,266 views
              0 likes
              Last Post sidlercom80  
              Started by Barry Milan, Yesterday, 10:35 PM
              3 responses
              13 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X