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 FrazMann, Today, 11:21 AM
          0 responses
          3 views
          0 likes
          Last Post FrazMann  
          Started by geddyisodin, Yesterday, 05:20 AM
          8 responses
          52 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by cmtjoancolmenero, Yesterday, 03:58 PM
          10 responses
          36 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by DayTradingDEMON, Today, 09:28 AM
          4 responses
          24 views
          0 likes
          Last Post DayTradingDEMON  
          Started by George21, Today, 10:07 AM
          1 response
          20 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Working...
          X