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.

    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.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              88 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              48 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              30 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              34 views
              0 likes
              Last Post TheRealMorford  
              Started by Mindset, 02-28-2026, 06:16 AM
              0 responses
              68 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Working...
              X