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

Using Time as a Stop condition

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

    Using Time as a Stop condition

    I am looking to exit a Trade after a certain period of time. Is there a way to do this without using Strategy Builder - in other words is there a Trade Order Conditional function already built in for Time. Again, I would prefer not to use Strategy Builder - I just want to make it a condition of the Trade Order submission process. Thanks for your help.

    #2
    Bro, you can go the here to check whether got the thing you want or not.
    NinjaTrader Ecosystem

    This is basically the free indicator and strategy you can download anytime, anywhere.

    If it do not have the thing you want, to be honest, you have to do it by yourselves.
    And my opinion is the the stop strategy should be happens on strategy, so I suggest make it in strategy.

    Comment


      #3
      Hello MaraAnkh,

      Welcome to the NinjaTrader forums!

      Outside of the Strategy Builder is an unlocked script you can do much more in. The "Trade" will have an entry and exit Order object and you can get the time, price, or any other information about the order you want.

      Below are links to the help guide.




      zhttps://ninjatrader.com/support/helpGuides/nt8/currency.htm
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thanks for the welcome Cincai and Chelsea B. I will check out these references to see if I can accomplish what I'm trying to do. - Mara Ankh

        Comment


          #5
          Hello ChelseaB! Per the discussion above, I, too, would like to EXIT out of any singular trade after so many seconds. I'm a newer trading coding person and need assistance as to:
          1) Check to see if I'm in a position.
          2) Collect that one position's time stamp of execution.
          3) Compare it to how much time has elapsed vs. the current time.
          4) Exit after so many seconds at the market to flatten the position out.

          Is there any reference out there that I can coat-tail on and try mucking through, or would you have some impactful suggestions of coding that I can test out? Thanks for you consideration
          and hellos from me!

          Comment


            #6
            Hi, thanks for posting. The strategy is certainly capable of exiting based on time.

            1. https://ninjatrader.com/support/help...tionupdate.htm - The Position object to track position information, also search "OnPositionUpdate" for an event based notification.

            2. See OnExecutionUpdate:


            3. This can be done by comparing the execution time stamp to either Time[0], which is the latest time stamp of each bar, or using DateTime.Now, which is a C#/.NET construct.

            4. You can keep track of time by running the strategy on 1 second bars, after every bar that elapses you will automatically know that 1 second has passed.

            Kind regards,
            -ChrisL
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Thanks for the reply Chris L! Ok...so HOW do code / write the "DateTime time" function inside the OnExecutionUpdate to read:

              IF DateTime.Now minus DateTime time of OnExecutionUpdate >= Time converted to seconds (user input), THEN ExitLong / ExitShort

              I'd like to exit at the market after the time elapsed has progressed x amount of seconds and have it execute the exit inside the OnExecutionUpdate.

              Comment


                #8
                Hi, thanks for your reply. Unfortunately, I will not be able to create any new examples or custom code. This is so we can help all of our clients in a timely manner. The best way to get a feel for the flow of a strategy and the data a strategy can use, utilize the Print() method to see the output of all the built in functions and events that a strategy can use.



                Kind regards,
                -ChrisL
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  cincai
                  "If it do not have the thing you want, to be honest, you have to do it by yourselves."

                  TRUE THAT! LOL If that ain't no lie. That was like medicine for me cincai

                  You better off pulling teeth than to try to get actual help round here. ahhh I feel better now.

                  The time they spend telling folk they can't do cuz of this that the other thing, they could help a OL' Lot more ppl instead of frustrating their paying clients. hip anyone?
                  Last edited by trdninstyle; 11-02-2022, 04:19 PM.

                  Comment


                    #10
                    Chris L, so then how do I ONLY reference time of the OnExecutionUpdate in the Print() function. How do I type it out? So far the only thing that gives me printed Output window data is:

                    Print(execution.ToString());

                    But I don't want the ENTIRE string. I'm trying to isolate referencing the filled order's execution time only.

                    Comment


                      #11
                      I do NOT know HOW to completely code and so I'm asking questions of ASSISTANCE, because you know better and can save me time by at least pointing me in the correct direction with snippets of context. I'm a trader, not a programmer. I do not wish to learn C# entirely. I'm a good customer of Ninjatrader Brokerage and ask of your expertise to save my time as I attempt to figure out what is impactful with my attempt at coding within the Editor. I hope you understand and can offer assistance per requested. I'm NOT asking you to program me up the entire endeavor.

                      Comment


                        #12
                        Hi, thanks for the follow up. Creating custom scripts takes a lot of trial and error testing, this can take a significant amount of time to create a script and test that it works to make sure we do not give out examples that do not work properly. As you could imagine, if we had to create new code for every client that requested examples this would just not be feasible since we have many customers to help per day. We recommend being at least intermediate level in C# programming before starting out with NinjaScript, it is a prerequisite to creating custom strategies. There are many free tutorials on C# out there on the Web, so this is where I would suggest to start in your journey of learning NinjaScript.

                        Kind regards,
                        -ChrisL

                        Chris L.NinjaTrader Customer Service

                        Comment


                          #13
                          Chris, the response you typed out took longer for you to type out than just supplying a snippet of assistance. I've asked you now twice for assistance with BASIC questions. You have not assisted. I'm asking you to help me help myself with items that are NOT readily available through the resources. Again, I asked you how to use Print() for function of time within OnExecutionUpdate. I cannot find out how to isolate just the time within this function. I'm again asking for assistance or please refer this entire forum thread to somebody that is willing and can assist.

                          Comment


                            #14
                            Hi, thanks for the follow up. You can Print the execution time in OnExecutionUpdate like this:

                            Code:
                            protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
                            {
                                if (execution.Order.OrderState == OrderState.Filled)
                                {
                            
                                    Print(execution.Time);
                            
                                }
                            }​
                            All of these data points are documented in our help guide here:



                            Kind regards,
                            -ChrisL
                            Chris L.NinjaTrader Customer Service

                            Comment


                              #15
                              Chris L.

                              Thank you very much for your help! I appreciate you and your time.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, 04-17-2024, 06:40 PM
                              6 responses
                              48 views
                              0 likes
                              Last Post algospoke  
                              Started by arvidvanstaey, Today, 02:19 PM
                              4 responses
                              11 views
                              0 likes
                              Last Post arvidvanstaey  
                              Started by samish18, 04-17-2024, 08:57 AM
                              16 responses
                              61 views
                              0 likes
                              Last Post samish18  
                              Started by jordanq2, Today, 03:10 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post jordanq2  
                              Started by traderqz, Today, 12:06 AM
                              10 responses
                              19 views
                              0 likes
                              Last Post traderqz  
                              Working...
                              X