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

Checking if Today == EntryDate

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

    Checking if Today == EntryDate

    I need a programmatic way to check if..

    Today() == EntryDate()

    This seems like a way. Is there an easier way?

    Code:
    ToDay(Times[6][0]) == ToDay( Times[6] [ BarsSinceEntry() ] )
    Thanks

    #2
    Originally posted by borland View Post
    I need a programmatic way to check if..

    Today() == EntryDate()

    This seems like a way. Is there an easier way?

    Code:
    ToDay(Times[6][0]) == ToDay( Times[6] [ BarsSinceEntry() ] )
    Thanks
    Your question is a bit ambiguous. How exactly do you mean?

    Are you trying to find out if the CurrentBar time is the same as the trade entry time, or are you trying to determine if the actual current trading day is the same as the trade entry time? (In the latter case, any weekend day will always return false).

    Comment


      #3
      Current bar date. The exit trade logic needs to adjust for if the trade was entered on the same day.

      Thanks for the reply.

      Comment


        #4
        Originally posted by borland View Post
        Current bar date. The exit trade logic needs to adjust for if the trade was entered on the same day.

        Thanks for the reply.
        You are better off using DateTime objects then.

        First you must capture the entry time into a variable. Let us call it TradeEntryTime, which has to be a class DateTime variable.

        To compare the dates, simply compare them.
        Code:
        if (TradeEntryTime.Date == Time[0].Date)
        {
        //act as necessary
        }

        Comment


          #5
          Hello borland,

          koganam provides a great way to compare the time of when your entry occurred to the time of the bar your strategy is currently evaluating.

          To add on to koganam's post, you can use OnExecution() to obtain that entry time.

          Code:
          // assuming our entry has a signal name of "Entry"
          protected override void OnExecution(IExecution e)
          {
               if (e.Order != null && e.Order.Name == "Entry" && e.Order.OrderState == OrderState.Filled)
                    TradeEntryTime = e.Time;
          }
          Zachary G.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by WHICKED, Today, 12:56 PM
          2 responses
          15 views
          0 likes
          Last Post WHICKED
          by WHICKED
           
          Started by Felix Reichert, Today, 02:12 PM
          0 responses
          1 view
          0 likes
          Last Post Felix Reichert  
          Started by Tim-c, Today, 02:10 PM
          0 responses
          1 view
          0 likes
          Last Post Tim-c
          by Tim-c
           
          Started by cre8able, Today, 01:16 PM
          2 responses
          9 views
          0 likes
          Last Post cre8able  
          Started by chbruno, 04-24-2024, 04:10 PM
          3 responses
          49 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X