Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit all position on the given time.

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

    #16
    Hello kazbek966,

    A Renko bar is not a time based bar, this is based on movement. There wouldn't be any way of know what the close time of the bar will be, and there wouldn't be a way to predict what the last bar of a session is.

    It would be extremely unlikely for there to be a bar close at 15:00 exactly on a movement based bar if the session closes at 15:40.

    You could instead add a 1 minute series and have the time conditions be based on that so you have predictive bar closes.



    Use prints to understand the behavior.

    Print the time of the bar. Print all values in the conditions. Do you see a bar where the conditions evaluate as true?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Hi Chelsea,
      Indeed my main strategy is Renko based, and I was using 1MIN series by itself merely as a testing ground for the concept. What is confusing that when I do have purely 1 MIN series, without Renko, Close on Time command is still not working. I think we can agree that in the presence of 1 MIN series alone there is no need to add additional 1 MIN series. My approach is to make command perform on 1 MIN series and then transfer it on RENKO bar strategy. The whole point is that for now 1 MIN series are not working and if upon inspection there is no obvious faults in the code, I am scratching my head a bit.

      Comment


        #18
        Hello kazbek966,

        A working example of a time filter can be found in the help guide. Try running this on a 1 minute chart.


        For your script, use prints to understand the behavior. Print all values in the conditions along with labels to identify what each printed value is.


        Save the output to a text file and post this with your reply. I am happy to assist with understanding the output.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Hi Chelsea,
          I implemented additional time based series in the script, but before discussing those I mentioned some discrepancy between Exit Time on Session Closure specified in the strategy configuration and actual time when it was executed. There is consistent 60 seconds lag. Of cause this lag could be taken into consideration, though out of sheer curiosity where this 60 seconds lag ( as seen in the enclosed figure) might be coming from ? Cheers

          Click image for larger version

Name:	EXITonSessionClose.PNG
Views:	242
Size:	184.1 KB
ID:	1191922

          Comment


            #20
            Hello kazbek966,

            What Trading hours template is selected for the chart?

            What is your time zone?

            Are you in sync with internet time?


            Was this in real-time or is this historical?

            It looks like the exit order possibly part filled.. Is this what your inquiry is, why did the order part fill?

            What was the position size that was closed?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              Hi Chelsea,

              Indeed I think time zone synchronization is one of the crucial questions that can play a role there. I am enclosing current Time Zone and Trading Session related parameters.
              Click image for larger version  Name:	TimeZone.PNG Views:	0 Size:	268.9 KB ID:	1192038

              I am physically in UTC + 2 Time Zone ( Helsinki etc.). The chart showed in previous post was
              1. Market replay ( Playback connection)
              2 For two strategies run in parallel and independent of each other
              3. Differing only in Session Time Exit settings (180 vs 360 sec).
              4. Both had single contract

              So no partial filling issues and position was fully closed.
              I will check Internet Time sync post as it may help to resolve observed issues.
              Though, in general what are the optimal TimeZone NT settings recommended when trading from different than Central Time Zone.
              I dont really care which time settings to use as long as it provides robust performance.

              P.S. I updated and synced Internet Time with recommended NIST server and it had no effect whatsoever. Providing there are no other options to fix it may be we can move on as there are a couple of unusual, exit on session closure related observations, that did not make much sense.

              Cheers
              Last edited by kazbek966; 03-02-2022, 07:55 AM.

              Comment


                #22
                Hello kazbek966,

                The hours you are showing for the CME US Index Futures ETH is not correct for the trading hours of that exchange.
                The session end of day should be at 4:00 PM Central. It looks like you have modified this to 3:40 PM.

                To reset these to factory settings:

                Click Tools -> Database Management -> Update trading hour templates -> Update



                That said, 180 seconds before 3:40 PM would be 3:37 PM.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #23
                  Correct, Chelsea, I intentionally set it at 15:40 as to the best of my understanding, please correct me if I am wrong, I need to be out of position by 15:45. So this is first safeguard , among other two that I wanted to implement to make sure not to hold a position over session break, which is a big no-no. And regardless of end of set session time ( 15:40, 15:45 or 16:00) same 60 second lag exist. As I said, if you dont see obvious errors we can move on to other a bit more interesting cases.

                  Comment


                    #24
                    Hello kazbek966,

                    I think the issue would be more clear if prints were added to the script. Looking visually at a chart is often not helpful.

                    If you print the session close time from a session iterator on each new session in OnBarUpdate(), the ExitOnCloseSeconds in State.DataLoaded, and the order object from OnOrderUpdate(), we would have a print out of what the settings were set to, the expected close time of the session, and we can calculate the expected time of the exit on close event before the end of the session.

                    Below is a link to a forum post that demonstrates how to use Print() to understand behavior.


                    As well as a link to a forum post with a script that demonstrates using a session iterator to get the session end time and prevent new entries until the next session.
                    This also includes a video that demonstrates the exit on session close works as intended.
                    NinjaTrader Community, A common inquiry is that the Exit on close didn't work in a NinjaScript Strategy because there is a position after the exit on close should have occurred. When viewing the log we often find that the Exit on close does indeed exit the position shortly before the end of the session (based on the Exit on


                    However, I don't think the seconds was set to 180 seconds, as the exit on close would have occurred.

                    Please let me have a look at the output from the prints so I may see there is an issue.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #25
                      Hi Chelsea,
                      Actually I do not have any problems with new entries after exiting my position. Addition of Time filter works quite nicely, so when I am exiting position outside permitted by myself trading time no further entries occurred. So this part of the equation is taken care of. Second precautionary measure of Exit on Session Close is functioning plus minus 1 minute. So may be for now we can postpone those debugging by PRINT.
                      What is definitely not functioning at all is Exit as Specific Time on a strategy combining Renko and 1 MIN data .
                      Exit at specific time was put as final precautionary measure prior to exhaustively discussed Exit on Session Close.
                      To remind
                      1. I am using Renko bars as primary series and 1 MIN regular as a secondary.
                      2. I checked execution of Exit at set time when working with 1 MIN chart alone ( without Renko) and it was working correctly in all 3 modes of calculations ( bar closure, ticks and price change).
                      3. My Renko strategy is also using calculations on bar closure so seemingly there should not be incompatibility with modes of calculations
                      4. But when RENKO runs along with1 MIN dataseries somehow there is no response at exiting position at specified time synced with 1 MIN data series.
                      5. Though Exit on Session close maps quite well on 1 MIN Series ( with known 1 MIN delay)

                      I suspect some of the conditions for exit at specific time may be wrong. Currently they follow the logic of exiting position on primary RENKO series while monitoring time at secondary 1 MIN series.

                      // Set 2
                      if ((Position.MarketPosition == MarketPosition.Long)
                      // EXIT
                      && ((IsFalling(AuLLMA1.LLMA) == true)
                      || (Times[1][0].TimeOfDay == new TimeSpan(15, 0, 0))))
                      {
                      ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
                      }

                      Is this correct logical implementation or am I missing something ?

                      Cheers


                      ​​​​​​​

                      Comment


                        #26
                        Hello kazbek966,

                        Exit on session close should not affected by the bar in real-time.

                        This is based on seconds from the exit time of the Trading hours template.

                        What bar series are the orders being placed to?

                        The video demonstration I provided you a link to, does not have a 1 minute delay on minute bars. The exit on close event occurs at the moment.

                        The exit order gets submitted immediately. The order would appear on the bar that was building when the exit on close event occurred.

                        Prints would give us information to work with.

                        Regarding your suggested code, I also suggest using a print to see if this is the logic you intended evaluating as you expect.

                        Code:
                        Print(string.Format("{0} | BIP: {1}, {2} {3} | (Position.MarketPosition: {4} == MarketPosition.Long) && ( (IsFalling(AuLLMA1.LLMA): {5} == true) || (Times[1][0].TimeOfDay: {6} == new TimeSpan(15, 0, 0): {7}) ) )", BarsInProgress, BarsArray[BarsInProgress].BarsPeriod.Value, BarsArray[BarsInProgress].BarsPeriod.BarsPeriodType, Position.MarketPosition, IsFalling(AuLLMA1.LLMA), Times[1][0].TimeOfDay, new TimeSpan(15, 0, 0) ));
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #27
                          Hi Chelsea,
                          I see that Exit at Specific Time on 1 MIN series alone was also executed with 1 Min delay. THat being said I would not worry too much about it right now as long as it stays consistent.
                          As for the entrance: the order was placed against Indicator tracking progression of Renko series , Exit is also placed either against indicator tracking Renko ( holding position) or against Time tracking 1 MIN series ( used as a timer ).
                          What I want to achieve is to exit position taken on Renko as soon as set time , say 3 PM, is clocked.
                          Will put the Print script and see what will transpire.

                          Comment


                            #28
                            Hello kazbek966,

                            An order placed in OnBarUpdate() is different than the Exit on close order.
                            This order would be affected by the bars, where the Exit on close order would not.

                            With this order, was Calculate set to OnBarClose()? As in was the order submitted after the submission bar closed?
                            See this post about why orders appear on the next bar.


                            What is the bar close time that submitted the order? (Not the bar the order is appearing on, but the bar that the condition was true when the order was submitted)
                            What is the actual submission time of the order (Not the time of the bar it's on, but the actual order's time as shown in OnOrderUpdate when the OrderState is OrderState.Submitted)

                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #29
                              Hi Chelsea,

                              Thanks for the help with the Print. I even managed to put it in the right place. Enclosing output is related to relevant position and orders as seen in illustration.
                              Position is definitely long on Renko and nothing should prevent to close it either at 15 or 15:01.
                              Click image for larger version

Name:	ExitOnTime.PNG
Views:	277
Size:	172.7 KB
ID:	1192275


                              1/24/2022 3:45:33 AM Strategy 'AuLLMAwTradingExiTimeLong/257591038': Entered internal SubmitOrderManaged() method at 1/24/2022 3:45:33 AM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                              1/24/2022 8:56:17 AM Strategy 'AuLLMAwTradingExiTimeLong/257591038': Entered internal SubmitOrderManaged() method at 1/24/2022 8:56:17 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                              1/24/2022 9:09:35 AM Strategy 'AuLLMAwTradingExiTimeLong/257591038': Entered internal SubmitOrderManaged() method at 1/24/2022 9:09:35 AM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                              1/24/2022 9:25:15 AM Strategy 'AuLLMAwTradingExiTimeLong/257591038': Entered internal SubmitOrderManaged() method at 1/24/2022 9:25:15 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                              1/24/2022 9:48:56 AM Strategy 'AuLLMAwTradingExiTimeLong/257591038': Entered internal SubmitOrderManaged() method at 1/24/2022 9:48:56 AM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                              1/24/2022 11:43:06 AM Strategy 'AuLLMAwTradingExiTimeLong/257591038': Entered internal SubmitOrderManaged() method at 1/24/2022 11:43:06 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                              1/24/2022 12:37:17 PM Strategy 'AuLLMAwTradingExiTimeLong/257591038': Entered internal SubmitOrderManaged() method at 1/24/2022 12:37:17 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                              1/24/2022 12:46:40 PM Strategy 'AuLLMAwTradingExiTimeLong/257591038': Entered internal SubmitOrderManaged() method at 1/24/2022 12:46:40 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                              1/24/2022 1:22:48 PM Strategy 'AuLLMAwTradingExiTimeLong/257591038': Entered internal SubmitOrderManaged() method at 1/24/2022 1:22:48 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                              1/24/2022 1:59:01 PM Strategy 'AuLLMAwTradingExiTimeLong/257591038': Entered internal SubmitOrderManaged() method at 1/24/2022 1:59:01 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                              1/24/2022 3:34:01 PM CancelAllOrders: BarsInProgress=0
                              1/24/2022 3:34:01 PM CancelAllOrders: BarsInProgress=1
                              1/24/2022 3:34:01 PM Strategy 'AuLLMAwTradingExiTimeLong/257591038': Entered internal SubmitOrderManaged() method at 1/24/2022 3:34:01 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit on session close' FromEntrySignal=''
                              1/24/2022 5:25:20 PM Strategy 'AuLLMAwTradingExiTimeLong/257591038': Entered internal SubmitOrderManaged() method at 1/24/2022 5:25:20 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                              1/24/2022 6:50:07 PM Strategy 'AuLLMAwTradingExiTimeLong/257591038': Entered internal SubmitOrderManaged() method at 1/24/2022 6:50:07 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''

                              As I can see from output existing script did not even recognize time based exit logic I wanted to implement.

                              Indeed orders are submitted with On Bar Close calculations that may explain 60 sec delay, as bar specified at 15.00 closes at 15:01 and we are getting our 60 seconds lag.
                              Though why Exit on Time is not being recognized is a bit of a mystery.

                              Attached Files

                              Comment


                                #30
                                Hello kazbek966,

                                It would be necessary to get output from prints to diagnose your condition set further.

                                Regarding Exit on session close, testing on my end using the example script I have provided you a link to, I am not able to reproduce the behavior. There is no delay.

                                Currently, In the output you have provided all I am seeing is TraceOrders information, which can also be helpful. We see the Exit on close was submitted at 3:34:01.

                                If you want to diagnose the Exit on close, print the sessionIterator.ActualSessionEnd and print the ExitOnSessionCloseSeconds.

                                Save the output to a text file and attach this to your post.
                                Chelsea B.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, Yesterday, 05:17 AM
                                0 responses
                                62 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                134 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                75 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                45 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                50 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X