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

Backtesting with Commissions

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

    Backtesting with Commissions

    I can't find an explanation of the data shown by strategy analyzer. I hope someone can explain what I'm seeing.

    I set commissions in Stocks - Replay and Stocks - Simulator, both to no levels and a minimum commission of $9.99. My broker charges a flat rate without regard to number of shares.

    After running the backtest, I look at the Executions tab what I see is
    Order Quantity Commissions
    Buy 257 $9.99
    Sell 100 $9.99
    Sell 100 $9.99
    Sell 100 $9.99

    I understand about partial fills, but I've never seen a broker that would charge separate commissions on each part of a partial fill. Is there a way to get one charge for each order the strategy generates (EnterLong or ExitLong) regardless of partial fills?

    Next, I look at the Trades tab. The Commission column shows varying amounts from about $10 to $14. How is this column computed? The numbers dont' make any sense to me.

    Thanks,
    ++PLS

    #2
    pls2000, there should be no partials given in backtesting - you mean you scale in / out of positions here in your script?

    For the trades tab commission amount you would see a weighted average then used taking into consideration the scale so commission would not be overstated.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I'm guessing I understand what's going on, but please confirm.

      I am working on a multi-instrument strategy where all trades on done on the instrument I add in Initialize. I am using managed order handling.

      My entry code is
      EnterLong(1, orderQuantity, strategyName);
      where orderQuantity is computed and strategyName is a string constant.

      My exit code is

      ExitLong(1, 100, strategyName +
      "Exit", strategyName); // Quantity is ignored

      The comment is key to how I though this worked. The help file for ExitLong says
      fromEntrySignal
      The entry signal name. This ties the exit to the entry and exits the position quantity represented by the actual entry.


      I'm providing the signal name of the entry transaction, so I though the order quantity in ExitLog would be ignored and it would exit the position entered through EnterLong.

      Instead, the ExitLong uses the order quantity and exits 100 shares. On the next bar, my strategy notices that the exit conditions are still in force and that there is still a position and does the ExitLong again, selling another 100 chares. This continues until there are fewer than 100 shares remaining, at which point NT just sells the remiander.

      Either I found a bug in NT managed order handling or the help file is badly wrong. Can you please tell me if what I wrote above is correct and whether the help file nr NT is wrong?

      Thanks,
      ++PLS

      Comment


        #4
        PLS, thanks for the follow up - if you're scaling out without scaling in first > this would unfortunately not work in managed mode. We would suggest to follow the concepts shown here - http://www.ninjatrader.com/support/f...ead.php?t=3751
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I am neither intending to nor wanting to scale out.

          My problem is that, as stated in my previous post, is that the ExitLong I'm using is not behaving as documented. Either the documentation is broken or Ninja Trader is broken. I'd like to know which.

          In other words, what does the publisher of the software think the correct behavior is? Knowing that I can finish my code. Then you should either fix NT or fix the documentation.

          ++PLS

          Comment


            #6
            Sorry, then I'm not following you here - why would this not be a scale out then?

            You have one entry with a varying qty and then have multiple exits from this entry in 100's.

            This would not be expected to work per the documentation sample I pointed you to, you would need to scale in via multiple entries in the managed approach first to be able to use those for scaling out later.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Repeating:

              >The help file for ExitLong says
              >fromEntrySignal
              >The entry signal name. This ties the exit to the entry and exits the >position quantity represented by the actual entry.


              This says that if I provide the entry signal name, then ExitLong will exit the entire position opened by the EnterLong with that signal name. The implication is that the order quantity in ExitLong is ignored and the actual order quantity to exit is taken from the EnterLong that established the position.

              But that's not how it really works. In code, the entry signal name is ignored and the order quantity in ExitLong is respected.

              Now, please read this paragraph twice. The behavior given in the documentation is not the behavior seen in code. Therefore, at least one of the NT code or the documentation is wrong. At least one of them needs to be fixed. As the publisher of the software, which behavior does NinjaTrader say is the correct one? And will the NT code be fix to conform to the documentation or vice versa?

              Thanks,
              ++PLS

              Comment


                #8
                PLS, in the Tips section of this link for ExitLong() you would also see stated -

                • If you do not specify a quantity the entire position is exited rendering your strategy flat

                However in your sample call you specify a qty to use.

                Can you please retest just calling the Exit method for your entry instead of trying to specify a partial exit?

                Thanks
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  So you're saying the behavior is correct and the documentation is wrong? Actually, the documentation is wrong, period. The dscription of fromEntrySignal and the tip contradict each other.

                  I am writing a multi-instrument strategy and making a decision in OnBarUpdate for data series 1 for a trade on data series 0. So I need a form of ExitLong that allows specifying BarsInProgress. The only documented form that does that does not give me the option of not specifying order quantity or fromEntrySignal.

                  I'll accept that this is the intended behavior. But the documentation really needs to be updated to specify the interaction between order quantity and fromEntrySignal. And maybe NT should provide a new method Flatten(BarsInProgress) to allow exiting a position in a different instrument.

                  Thanks,
                  ++PLS

                  Comment


                    #10
                    PLS, yes the behavior is as we would expect in the framework. We're also striving to improve our documentation and educational materials and I will make sure to pass your thoughts on.

                    Correct, the only overload allowing a BarsInProgress parameter would be -

                    ExitLong(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal)

                    I have added that methed enhancement thought to our internal lists as well for consideration, thanks for your input here.
                    BertrandNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by knighty6508, Today, 01:20 AM
                    2 responses
                    7 views
                    0 likes
                    Last Post knighty6508  
                    Started by franatas, Today, 01:53 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post franatas  
                    Started by knighty6508, Today, 01:17 AM
                    0 responses
                    7 views
                    0 likes
                    Last Post knighty6508  
                    Started by tierraany, Today, 01:06 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post tierraany  
                    Started by Wilmarobyi, Today, 12:48 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post Wilmarobyi  
                    Working...
                    X