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

Holding a position through session break vs IsExitOnSessionCloseStrategy

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

    Holding a position through session break vs IsExitOnSessionCloseStrategy

    Hello,

    In the forex market, bid/ask spreads will dramatically increase around session break around 30 seconds till 14:00 PST (17:00 EST). This can cause a strategy to be stopped out prematurely. I know there is an option to use IsExitOnSessionCloseStrategy and set ExitOnSessionCloseSeconds = 30 for handling an open position. I also saw a code snippet for preventing new positions being opened during this time period. But how about holding an existing position through this period? If my target is reached during this time, I will take profit, but if my stop is reached I want to wait until spreads are typical again before exiting. What would be an appropriate way to achieve something like this if it is possible?

    PS. When I was looking into this, I was trying to find a built in method for tracking typical spreads but I couldn't find anything in documentation. This might be a nice feature if it doesn't already exist.

    #2
    Hello jflaggs,

    You would either want to cancel the exit stop order or change the stop price so much further behind the market it won't fill.
    And then at the start of a new session (or however many seconds after you would like) resubmit the exit stop order or change the stop price back near the trading action.

    Using a sessionIterator would give you the end session time as demonstrated in the PreventEntryAfterExitOnCloseExample you mentioned. You could cancel/modify the stop order as many seconds before the session end you would like.


    What are the specific rules that would define a typical spread?
    What would define a non-typical spread?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      What would be the proper way to measure time? I tried using Time[0] but that seems incorrect. I'm outputting the Time[0].Hour value each tick and it shows the same value of 15 even when my PC time goes from 14:00 to 15:00 (See attachments). The documentation is not really clear to me on why I'm getting this behavior: https://ninjatrader.com/support/help...eries_time.htm. Can you explain this behavior a bit more?

      Typical Spread:
      You can use statistics to determine typical and non-typical spreads. You can also just implement something like Spread.Median[0] as a history of median spreads values. For back testing forex, it would be great to have a parameters TypicalHistoricalSpread that is applied to long/short entry prices. Currently, we have to create this logic ourselves to get accurate back tests in forex. It's not so much of an issue for stocks and futures, but is a huge factor in forex, especially since NT8 does not support commission account connections from brokers like Forex.com. NT8 only supports Spread Only accounts.
      Attached Files

      Comment


        #4
        Hello jflaggs,

        Time[0] is the close time of the bar not the time of the PC.

        If you want the time of the PC and not the time of the bar, you can use Core.Globals.Now.

        "You can use statistics to determine typical and non-typical spreads."

        I cannot use statistics to determine the logic you want coded.
        You have not provided the rules or logic for a typical or non-typical spread that you want assistance coding. I would not be able to create those rules or logic on your behalf. But you have logic and are having difficulty writing this into C# I can assist with this.

        You could subtract the bid from the ask if this is what you are referring to as the spread and save this to a Series<double> object if this helps.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Do you mean that Time[0] is telling me the future time that the current bar will close at? For example, if the time is 14:51 and we are using 10min bars Time[0] will return 15:00? My goal is to access the same time value that is displayed on my charts. I would think that should be the bar time because my PC time changes based on where I am physically.

          Spreads:
          I think you misunderstood me. I'm not asking for coding assistance, I am suggesting a new NT8 feature to support forex trading and back testing. I can code this myself -- and so can thousands of other users -- but it would make more sense for it to be a built in feature. The implementation details would be up to your team.

          Comment


            #6
            Hello jflaggs,

            Yes, the close time of the bar is the time the bar will close. This is the same that is shown on the x axis (time scale) on the chart.

            I will submit feature request to support forex spread trading. Once I have a tracking ID for this request I will post in this thread for future reference.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello jflaggs,

              This request is being tracked with ID # SFT-6187.

              Please note, we receive many requests and cannot reasonably implement all requested features or changes. Interest is tracked internally and if enough interest is tracked, it would be weighed against how feasible it would be to make those changes to consider implementing, so we cannot offer an ETA or promise of fulfillment.

              When new features are implemented, they will be listed in the Release Notes page of the Help Guide. The ID number may be different than the internal feature request tracking ID, but the description of the feature will let you know if that feature has been implemented.

              Release Notes - https://ninjatrader.com/support/help...ease_notes.htm
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_ChelseaB View Post

                Time[0] is the close time of the bar not the time of the PC.

                If you want the time of the PC and not the time of the bar, you can use Core.Globals.Now.
                I'm not asking for either of these. I think the best way to rephrase is how to get the intra-bar time for current bar during tick replay? For example if it's noon and we are 35 seconds into a 1 minute bar during tick replay, I need to know the time is 12:00:35:00. If I use the PC time that will just return the same time as my watch. If I use the Time[0] time it will return 12:01:00:00 which is also not what I want. I want to know how many seconds, for example, until the current bar closes. Tradingview has the time until current bar close shown on the y axis by default.

                Comment


                  #9
                  Hello jflaggs,

                  You would need to add a 1 second series with AddDataSeries(), which will update OnBarUpdate() with BarsInProgress 1 each second.
                  This would give you intra-bar granularity of 1 second.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    That is a huge performance hit. Does NT have tick timestamps? That would be a better solution. I can't imagine there's no way to know the time of the last tick.

                    Comment


                      #11
                      Hello jflaggs,

                      If you want tick time stamps add a 1 tick series with AddDataSeries(), which will update OnBarUpdate() with BarsInProgress 1 for every received tick.

                      You can also check the marketUpdate.Time with TickReplay enabled. (This will use the same amount of CPU resources as adding a 1 tick series)
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Is there any way to determine if we are in playback mode?

                        To get the correct time, I'm trying to implement something like the following logic:


                        Code:
                        if (realtime)
                            return DateTime.Now;
                        else if (historical || playback)
                            return Time[0];​
                        This way, you don't get the current PC time during playback or during a backtest.
                        Last edited by jflaggs; 01-28-2024, 07:41 PM.

                        Comment


                          #13
                          Hello jflaggs,

                          if (Cbi.Connection.PlaybackConnection != null)
                          Print(Core.Globals.Now);
                          Chelsea B.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Jonafare, 12-06-2012, 03:48 PM
                          5 responses
                          3,986 views
                          0 likes
                          Last Post rene69851  
                          Started by Fitspressorest, Today, 01:38 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post Fitspressorest  
                          Started by Jonker, Today, 01:19 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post Jonker
                          by Jonker
                           
                          Started by futtrader, Today, 01:16 PM
                          0 responses
                          8 views
                          0 likes
                          Last Post futtrader  
                          Started by Segwin, 05-07-2018, 02:15 PM
                          14 responses
                          1,792 views
                          0 likes
                          Last Post aligator  
                          Working...
                          X