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

Entry and stop loss - and general logic.

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

    Entry and stop loss - and general logic.

    I have a simple strategy - but with mulitple time series. Everything works well - but when i insert a simple stop loss - just for double security - it is really messing it all up.

    I then get two orders in same direction and few other werid things.

    So im considering what are the "corerct" good normal rules for having enter long and short - and what is genreal good practice when running a strategy.

    Some of what i believe was going wrong was that when i tried with 2 long trades in same direction - then at one point the strategy was stopping those two long positions - as it should - and in the same time starting two in oppposite direction. But sinse the first two orders where not "finished" exiting - it could then not enter the short positions for the 2 new because of limited ammount on the account.

    But this was only the issue when i tried with two orders - but it was not what was causing the other issues as mentioned above.

    #2
    Hello KarstenKafl,

    Thanks for your post.

    An important consideration is that all entry methods will automatically detect a position in the opposite direction and will issue first "Close Position" order and then a second order to leave you in the intended position and quantity.

    If you have an exit order occurring at the same time as an entry in the opposite direction, it is possible that you could end up with more orders than expected.

    For example, if you were 1 long and your strategy logic called EnterShort and ExitLong at the same time, the EnterShort would issue 1 "close position sell order and 1 "sell" to leave you one short, however, depending on the actual timing, the ExitShort will issue a sell order as well, leaving you 2 short in your position where you had intended 1. This likely could continue to accumulate contracts as it goes.

    I would suggest making sure that your Entry conditions (for the opposite direction) are not the same as your exit conditions.

    If you haven't reviewed the Managed approach information, please see: https://ninjatrader.com/support/help...d_approach.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you Paul

      I see that in my strategy im using default quantity - but is that someting that i can access from when i start the strategy?

      Comment


        #4
        Hello KarstenKafl,

        Thanks for your reply.

        Yes, there are a number of ways to handle this.

        1) With no changes, when you apply the strategy (any strategy), look for the parameter "Set order quantity" which by default is set to "Strategy. If you select "default quantity" a numerical field shows, populated with 1, that you can change to allow for multiple contracts per order. Reference: https://ninjatrader.com/support/help...tegyProperties

        2) You could create a user input variable that you can then assign to the order quantity in your strategy.

        3) In your strategy, you could replace the default quantity with a set value by clicking set >misc>Numerica value and then enter a quantity.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks again Paul

          I think i understand it all a bit better now.

          Im using two time series - and i believe that this means that an order is simply not "realized" before the bar of the one time seires is done.

          Can you show any example of how a good practice would be to keep the order alive - until it is actually "realized" - as an position.. ?

          thanks a lot.

          Comment


            #6
            Hello KarstenKafl,

            Thanks for your reply.

            Glad you asked that questions as I had forgotten to provide a reference to working with a multi time frame or multi-series scripts.

            Please see the help guide here: https://ninjatrader.com/support/help...nstruments.htm While the entire section is a good read on the subject, to answer your initial questions please see the section titled, "Entering, Exiting and Retrieving Position Information".

            "Can you show any example of how a good practice would be to keep the order alive - until it is actually "realized" - as an position.. ?" Is this question related to a limit order used for entry or exit?
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              thanks - i was thinking that it was for entry - so how to make sure that an enterlong order was not skipped because the bar was finished - before the order was filled.

              But i also consider it for exit?

              So if i have a cross above - and that subtmits and order - but that order is not filled before the bar is closed.. then in next bar it is not cross above any longer right?

              thanks

              Comment


                #8
                Hello KarstenKafl,

                Thanks for your reply.

                If you are using EnterLong() then that is a market order that would be placed and filled immediately (in most instruments/markets).

                I would suggest adding a print statement to ensure that the conditions to place the EnterLong() order are hit/true.4
                Please see the help guide tips here for debugging: https://ninjatrader.com/support/help...script_cod.htm

                If your strategy is running with Calculate.OnBarClose, then your script is run once per bar and if the conditions to place an order are true then the order should be placed and filled on the next bar, again print statements can be used to validate your condition logic.

                If your strategy is running Calculate.OnEachTick or Calculate.OnPriceChange, then it could place an order intrabar.

                Again I would suggest thoroughly reviewing the Multi time frame information as it contains critical concepts for programming in this environment.

                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Hello again Paul

                  Thanks for all you replyes- they make good sense.

                  Now i have located some of the problems for my weird results when backtesting.

                  When i go back to the dates like 10 sep - and see it by 2000 tick - then the bars look "messed up".
                  I then have tryed differnet ways to reload all historical data - and bit other things - in the graph - or by manually deleting that day - and then reloading data from historical data menu.

                  I dont think 10 sep. is any "Holy day" - or similar?

                  Im using tick data from Kinetick, Would you say that i should try something more - or should i conatact Kinetic?


                  Click image for larger version

Name:	2020-09-28 09_57_38-Chart - MES 12-20.png
Views:	254
Size:	214.6 KB
ID:	1120113

                  Comment


                    #10
                    Hello KarstenKafl,

                    Thanks for your reply.

                    September 10 was the MES contract rollover date in the Ninjatrader platform. There was not much volume on the 12/20 contract for that specific date.

                    You can change the rollover date for that contract in your platform and in that way change which contract's historical data is pulled into the chart.

                    To change the rollover date, go to tools>Instruments. Type in MES in the search bar and then select the MES instrument from the list then click "edit" at the bottom left of the instruments window. In the instrument window that opens, scroll to the last row. and click in the field for "contract months". In the contract months window, locate the 12-20 on the left side and left-click on it, change the date to something later such as 9/11/2020, click OK, click Ok and click close. Now recreate the chart.

                    References: https://ninjatrader.com/support/help...nstruments.htm


                    Paul H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by MarianApalaghiei, Today, 10:49 PM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by love2code2trade, Yesterday, 01:45 PM
                    4 responses
                    28 views
                    0 likes
                    Last Post love2code2trade  
                    Started by funk10101, Today, 09:43 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post funk10101  
                    Started by pkefal, 04-11-2024, 07:39 AM
                    11 responses
                    37 views
                    0 likes
                    Last Post jeronymite  
                    Started by bill2023, Yesterday, 08:51 AM
                    8 responses
                    46 views
                    0 likes
                    Last Post bill2023  
                    Working...
                    X