Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Correct time of day

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

    Correct time of day

    I am sure this has been asked before but doing a quick search I cannot find it.

    I have an automated strategy (using daily bars) that I only want to trade at the end of the day (around 3:55pm).

    How can I accomplish this ? I cannot use Calculate on bar close as the market will be closed. I cannot use ToTime(Time[0]) as that seems to be using the bar close time (which will be the end of the day).

    What do you suggest ?

    Thanks
    greg


    #2
    Hello Greg,

    Thanks for your post.

    Please see the following forum topic which includes a sample strategy for how use ToTime to trade during only a specified time frame.
    BrandonNinjaTrader Customer Service

    Comment


      #3
      thanks for the reply but your strategy is using:

      ToTime(Time[0]

      My understanding (and sampling) is that this represents the closing time of the bar. So if I am using daily bars then ToTime(Time[0] will never reflect the current time.

      Is my understanding wrong ?

      I need to use daily bars as my strategy is based on a daily time frame but I only want to trade at end of day (at 3:55pm).

      Is this doable with daily bars ?

      -greg

      Comment


        #4
        Hello Greg,

        Thank you for your response.

        Do you have a real-time data feed provider? Or are you using an End Of Day data feed provider such as Yahoo or Google?

        What time zone are you in? Is the 3:55 PM time before the close or after for the instrument you trade and the time zone you are in?

        I look forward to your response.

        Comment


          #5
          I am using Ninja Trader through my funded TD Ameritrade account. I am trying to write an automated strategy for equities using daily bars. I only want the strategy to trade once at the end of the day (but before the market closes).

          I need daily bars for my strategy so how do I trade once a day (around 3:55pm). Totime seems to use the closing time of the bar so how do I monitor the actual time to just trade at end of day.

          Comment


            #6
            I think this may work:

            ok2trade = false;

            if(DateTime.Now.TimeOfDay > System.TimeSpan.Parse("15:50:00"))
            ok2trade =
            true;


            This way I can use daily bars and use:

            CalculateOnBarClose = false;
            ExitOnClose =
            false;


            Then my daily strategy can run all day long and trade at the end of the day. I will also set a flag so once traded for the day it will not initiate another trade:

            // already had a trade today
            if (lastaction != Time[0].Date) tradedtoday = false;
            if (tradedtoday == true) ok2trade = false;

            after my trade, I will set lastaction:
            lastaction = Time[0].Date;

            I can probably do all of this with less code but for now I am just programming my way around the constant bar time.

            What do you think ?

            -greg

            Comment


              #7
              Hello gregm,

              Thanks for your reply.

              Using the process from the original sample strategy should work on Daily bars so long as you receive real time data and have CalculateOnBarClose set to false.
              If this does not work I would need more information about what instrument you are trading, your time zone, if there are any errors, and sample of the code used.
              BrandonNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by lightsun47, Today, 03:51 PM
              0 responses
              5 views
              0 likes
              Last Post lightsun47  
              Started by 00nevest, Today, 02:27 PM
              1 response
              10 views
              0 likes
              Last Post 00nevest  
              Started by futtrader, 04-21-2024, 01:50 AM
              4 responses
              46 views
              0 likes
              Last Post futtrader  
              Started by Option Whisperer, Today, 09:55 AM
              1 response
              14 views
              0 likes
              Last Post bltdavid  
              Started by port119, Today, 02:43 PM
              0 responses
              10 views
              0 likes
              Last Post port119
              by port119
               
              Working...
              X