Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CloseOnExit in Range Bars under CalculateOnBarClose

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

    CloseOnExit in Range Bars under CalculateOnBarClose

    Hi Ninjas,

    Since I've read here that there's an issue, that sometimes NT doesn't execute properly the ExitOnClose on positions that an automated Algo might have, I've tried to create my own sub-routine. For example, this simple one:

    if(ToTime(Time[0]) >= 165500 && ToTime(Time[0]) <= 171450)
    {
    ExitLong();
    ExitShort();
    return;
    }

    It seems that it could do its job, but I've realized an obvious problem: since my Algo works on range bars under CalculateOnBarClose=True, it never closes the position in the last bar because the Algo doesn't know which bar will be the last one until it's a closed bar. The problem is that I can't work with CalculateOnBarClose=False, so, questions:

    1. Is already solved and reliable the procedures ExitOnclose and the general Faltten-All for an automated Algo? if so: Should I use it both as true at the same time in order to have more guarantee to ExitOnClose properly, or is it better just one?

    2. If not: what changes could I do to my sub-routine in order to solve that situation?

    Thanks
    Last edited by pstrusi; 09-08-2013, 08:18 AM.

    #2
    Hello pstrusi,

    Thank you for your post.

    To better understand what you are attempting to work around can you provide details on what ExitOnClose does not achieve that you wish to achieve and any links to these discussions on the forum here that you have viewed?

    I look forward to assisting you further.
    Last edited by NinjaTrader_PatrickH; 09-09-2013, 08:36 AM.

    Comment


      #3
      It's pretty simple. Imagine for a moment that NT has not the capability of closing positions before the close of session ( as many traders like me don't like to have positions in the meantime until the market is once again opened ) having in mind that my Algo work with "CalculateOnBarClose"=true, this means that NT won't know which bar will be the last one of the serie before the market closes. So I thought that it must exist a function working with time, that I could code in, telling to my Algo "closes if there's left 30 seconds to close" for example.

      I tried to use TimeTo but since it works with "CalculateOnBarClose", I have no time info with it until the bar is built. Do you understand it ?

      So far, I've instructed the Flatten-All and the ExitOnClose NT's functions but I know that I must keep un eye on them till close just in case.

      Any ideas then?

      Comment


        #4
        Hello pstrusi,

        Thank you for your response.

        You may be looking for something like the Stopwatch class: http://msdn.microsoft.com/en-us/libr...stopwatch.aspx

        Comment


          #5
          Thank you very much Patrick, that's just what I was looking for to complete as last emergency resource.

          Best regards

          Comment


            #6
            Patrick, as always I do when I´ve finished to solve an issue, here is the sub-routine to ExitOnClose, working with the CalculateOnBarClose=true :

            TimeSpan end = new TimeSpan(16, 59, 40);
            TimeSpan now = DateTime.Now.TimeOfDay;
            if ((now > end))
            {
            ExitLong();
            ExitShort();
            return;
            }

            Regards,

            Comment


              #7
              BUT, I have to say again, when this sub-routine is working under CalculateOnBarClose=true, it really doesn't work until the powerful method OnBarUpdate upgrades and overrrides with a new built bar. So, at this time I continue to trust on both: Flatten-All and the Algo's own ExitOnClose.

              So, should any weird reason be that avoid either one of two methods to work, there's no other tool to avoid going with a position at close. Therefore is very important to solved any execution problem with them whenever an Algo is in real-time with real money.

              Thanks as always for your attention

              Comment


                #8
                Hello pstrusi,

                Thank you for your response.

                You can separate logic in your indicator to update on the close of a bar and on each incoming tick. For a reference sample on this please visit the following link: http://www.ninjatrader.com/support/f...ad.php?t=19387

                Please let me know if I may be of further assistance.

                Comment


                  #9
                  Hi Patrick, thanks for your response.

                  Interesting these alternatives, however the FirstTickOfBar isn't quite helpful much, cause it triggers at the beginning of a new bar. What I mean is when you are closer to the final close, you really don't know how many Bars in a "Range Bar" chart could be built, cause it'll depend on price movements. That's why I was trying to access some function that in fact goes with the local time on the PC in order to close when the market really is about to finish that session.

                  If any ideas or suggestions please let me know

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by GLFX005, Today, 03:23 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post GLFX005
                  by GLFX005
                   
                  Started by XXtrader, Yesterday, 11:30 PM
                  2 responses
                  11 views
                  0 likes
                  Last Post XXtrader  
                  Started by Waxavi, Today, 02:10 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post Waxavi
                  by Waxavi
                   
                  Started by TradeForge, Today, 02:09 AM
                  0 responses
                  12 views
                  0 likes
                  Last Post TradeForge  
                  Started by Waxavi, Today, 02:00 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post Waxavi
                  by Waxavi
                   
                  Working...
                  X