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

Multiple entry orders are processed differently in backtest from real mode

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

    Multiple entry orders are processed differently in backtest from real mode

    Hi,
    I have the following issue.

    I designed a strategy that on many occasions has more than one entry before it closes a position.

    Especially hen an entry is losing, it opens up new ones in orde to average the price between them.

    This results in a general discrepancy of the way orders are executed and closed in the back-test when compared with the real trading mode.

    In the backtest each new entry appears as a unique one and each profit/loss is unique to each unique entry whereas the real trading mode if I have 5 entries...with each new entry, as the average entry price adjusts, the profit and stop loss adjust to that one average price. This results in 5 entries with one stop loss and one profit taker.

    Can someone give me an advice on how to solve this? Is there a way how I can see in the backtest processing of the strategy in the same way it does in live trading?

    Thanks.

    #2
    Hello nikolaalx,

    Thank you for your post.

    Are you only using one SetStopLoss and SetProfitTarget? Or are you using multiple Set methods will different fromEntrySignalNames?

    Comment


      #3
      I am generating multiple entries with the same signal name and one SetStopLoss and SetProfitTarget.

      This is basically the effect that I want to accomplish...to have an effect of adding more entries and thus scaling in with adjusted price.

      Problem I have is that in backtest, this does not work that way and all entries are shown as if they are unique.




      Originally posted by NinjaTrader_PatrickH View Post
      Hello nikolaalx,

      Thank you for your post.

      Are you only using one SetStopLoss and SetProfitTarget? Or are you using multiple Set methods will different fromEntrySignalNames?

      Comment


        #4
        Hello nikolaalx,

        Thank you for your response.

        Are you using separate entry conditions for each of these entries?

        I see the behavior you detail in backtesting if my entries occur at different times and thus different fill prices. Are you seeing the same fill price in real-time?

        Comment


          #5
          I use the same entry condition in different moments in time. I can get 5-6 entries over a period of e.g. 2 hours.

          All those entries are generated by the same logic and code. Same signal name and same profit and stop loss parameters.

          Thus, the different entries have different fill prices, yes.

          My problem is the fact that backtest executes those entries as separate/unique ones...despite the fact that they have the same name and should be combined.

          Any ideas how I can fix this?



          Originally posted by NinjaTrader_PatrickH View Post
          Hello nikolaalx,

          Thank you for your response.

          Are you using separate entry conditions for each of these entries?

          I see the behavior you detail in backtesting if my entries occur at different times and thus different fill prices. Are you seeing the same fill price in real-time?

          Comment


            #6
            Hello nikolaalx,

            Thank you for your response.

            I am seeing the same behavior you detail in backtesting, but I also see the same performance in real-time testing. Can you provide an example and any code that will help to produce multiple entries under the same signalName and use the same Stop Loss and Profit Target levels in real-time trading?

            Comment


              #7
              Hi,
              I am providing screenshots of the two ways that the exact same strategy, same instrument, same settings, same bars is processed.

              Due to the nature of the strategy (the fact that it is a money management strategy where it increases quantity as price goes the wrong way) it calculates profit and stop loss based on Position Average Price. In that case the mistaken entries are covered by the ones that are added at a latter stage.

              When each entry is processed as independent one, the Position Average Price is unique to each entry and thus the "right"entries close right away...leaving the unclosed...basically uncovered and thus the end result is dramatically different from what it actually has to be.

              Any Ideas why this is happening and why average position size is unique to each additional order...even though they have the exact same entry name?


              EDIT: I just checked and the bug seems to be related to "Stop & Target Submission" feature.

              While this feature is available in the market replay, when I change it to ByStrategyPosition, orders are being handled properly...as all profit and stops are related ot the Position Average Price.

              When I change it to "PerEntryExecution" orders are being handled exactly as the screenshot that I uploaded with the mistaken handling.

              The big question is - Why isn't there such an option in the backtest/optimize feature?

              There isn't even a selector that I can choose for the "Stop & Target Submission". Is it being taken into account at all?


              Please let me know if I am right about this...or the problem could be elsewhere?


              p.s. I noticed that the computer that does the backtest properly is the one on which I have extensively done market replay (and hence, have activated that very same strategy with the PerStrategyPosition feature on the "Profit & Stops Submission".

              Not sure if this fixes the problem or not...but is another clue.

              Let me know what you think.

              Thanks.




              Originally posted by NinjaTrader_PatrickH View Post
              Hello nikolaalx,

              Thank you for your response.

              I am seeing the same behavior you detail in backtesting, but I also see the same performance in real-time testing. Can you provide an example and any code that will help to produce multiple entries under the same signalName and use the same Stop Loss and Profit Target levels in real-time trading?
              Attached Files
              Last edited by nikolaalx; 02-16-2015, 11:58 AM.

              Comment


                #8
                Hello nikolaalx,

                Thank you for your response.

                The Stop & target submission option is only available in real-time as there are not partial fills historically - they are all complete fills.
                However, you have thrown a factor in that is not designed. You use the same SignalName for each separate entry and this means NinjaTrader treats them as there own orders and not orders to scale in. A SignalName is designed to be used for a single entry point.
                If you wanted to control the exit orders more precisely you may wish to begin using the Unmanged Approach: http://www.ninjatrader.com/support/h...d_approach.htm

                Comment


                  #9
                  I use the same name, because this is how my strategy works.

                  Why create separate entries, when the basis of the whole strategy is the average position price and when I want them to be treated as a whole?

                  Also, my question is why I see the backtest handle the orders properly after I have played the strategy in market replay. Is there any reason behind this...or it is just a fluke.

                  I really do not wish to use unmanaged orders as they entirely rely on the IOrder variable...which would need alot additional coding for something that obviously can work in this way as well (thanks to that "fluke").

                  Comment


                    #10
                    Hello nikolaalx,

                    Thank you for your response.

                    True scaling into a position in NinjaScript would require the Unmanaged Approach. The Managed Approach is designed as single entry with single exit.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Tim-c, Today, 02:10 PM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by Taddypole, Today, 02:47 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post Taddypole  
                    Started by chbruno, 04-24-2024, 04:10 PM
                    4 responses
                    50 views
                    0 likes
                    Last Post chbruno
                    by chbruno
                     
                    Started by TraderG23, 12-08-2023, 07:56 AM
                    10 responses
                    400 views
                    1 like
                    Last Post beobast
                    by beobast
                     
                    Started by lorem, Yesterday, 09:18 AM
                    5 responses
                    25 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Working...
                    X