No announcement yet.

Partner 728x90


Entry and stop loss - and general logic.

  • 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.

    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:
    Paul H.NinjaTrader Customer Service


      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?


        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:

        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


          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.


            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: 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


              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?



                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:

                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


                  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:	22
Size:	214.6 KB
ID:	1120113


                    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.


                    Paul H.NinjaTrader Customer Service


                    Latest Posts


                    Topics Statistics Last Post
                    Started by redart1021, Today, 10:29 AM
                    0 responses
                    1 view
                    Last Post redart1021  
                    Started by ervin, Today, 09:23 AM
                    1 response
                    Last Post NinjaTrader_Kate  
                    Started by xxzbill, Today, 10:02 AM
                    2 responses
                    Last Post NinjaTrader_Jesse  
                    Started by xxzbill, 08-19-2020, 11:06 PM
                    4 responses
                    Last Post xxzbill
                    by xxzbill
                    Started by tonynt, Today, 09:39 AM
                    1 response
                    Last Post NinjaTrader_Zachary