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

Performance.AllTrades.GetTrades not returning a collection correctly

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

    Performance.AllTrades.GetTrades not returning a collection correctly

    I am trying to access AvgMAE from Performance.AllTrades objects and the Performance.AllTrades.GetTrades() method is only returning the correct value some of the time. More often its returns 0.

    Can you please take a look and tell me if the values I`m providing to Performance.AllTrades.GetTrades is correct what value should I use ?

    Here is an example of the code I used to print AvgMAE to the Output Window.


    for (ijk = 0; ijk < Performance.AllTrades.Count; ijk++)
    {
    intTradeNum++;
    theTrade = Performance.AllTrades[ijk];

    Print(intTradeNum.ToString() + "..\t" + theTrade.ToString()
    + "..\t" + Performance.AllTrades.GetTrades(theTrade.Entry.Ins trument.ToString(), theTrade.Entry.Order.Name.ToString(), 1).Count
    + "..\t" + Performance.AllTrades.GetTrades(theTrade.Entry.Ins trument.ToString(), theTrade.EntryExecution.Name.ToString(), 1).TradesPerformance.Currency.AvgMae
    );
    }





    Here is the output it produced. As you can see the GetTrades only works some of the time.


    1.. Instrument='YM 12-15' EntryPrice=16255 ExitPrice=16216 Quantity=1 Market position=Long EntryTime='9/10/2015 1:58:00 AM' ExitTime='9/10/2015 2:50:00 AM' TotalProfitCurrency=$-199.04.. 1.. 210
    2.. Instrument='YM 12-15' EntryPrice=16290 ExitPrice=16230 Quantity=1 Market position=Long EntryTime='9/10/2015 4:27:00 AM' ExitTime='9/10/2015 4:27:00 AM' TotalProfitCurrency=$-304.04.. 1.. 300
    3.. Instrument='YM 12-15' EntryPrice=16311 ExitPrice=16251 Quantity=1 Market position=Long EntryTime='9/10/2015 5:54:00 AM' ExitTime='9/10/2015 7:24:00 AM' TotalProfitCurrency=$-304.04.. 0.. 0
    4.. Instrument='YM 12-15' EntryPrice=16335 ExitPrice=16275 Quantity=1 Market position=Long EntryTime='9/10/2015 5:55:00 AM' ExitTime='9/10/2015 7:24:00 AM' TotalProfitCurrency=$-304.04.. 0.. 0
    5.. Instrument='YM 12-15' EntryPrice=16344 ExitPrice=16284 Quantity=1 Market position=Long EntryTime='9/10/2015 7:24:00 AM' ExitTime='9/10/2015 7:24:00 AM' TotalProfitCurrency=$-304.04.. 0.. 0
    6.. Instrument='YM 12-15' EntryPrice=16181 ExitPrice=16142 Quantity=1 Market position=Short EntryTime='9/10/2015 7:25:00 AM' ExitTime='9/10/2015 8:11:00 AM' TotalProfitCurrency=$190.96.. 0.. 0
    7.. Instrument='YM 12-15' EntryPrice=16185 ExitPrice=16142 Quantity=1 Market position=Short EntryTime='9/10/2015 7:30:00 AM' ExitTime='9/10/2015 8:11:00 AM' TotalProfitCurrency=$210.96.. 0.. 0
    8.. Instrument='YM 12-15' EntryPrice=16169 ExitPrice=16142 Quantity=1 Market position=Short EntryTime='9/10/2015 7:37:00 AM' ExitTime='9/10/2015 8:11:00 AM' TotalProfitCurrency=$130.96.. 0.. 0
    9.. Instrument='YM 12-15' EntryPrice=16175 ExitPrice=16142 Quantity=1 Market position=Short EntryTime='9/10/2015 7:41:00 AM' ExitTime='9/10/2015 8:11:00 AM' TotalProfitCurrency=$160.96.. 0.. 0



    I`ve uploaded a screen scrape of what the AvgMae for each trade should be using the output from the strategy analyzer


    Thank you
    Attached Files

    #2
    Hello rayko,

    Thank you for your inquiry.

    It looks like you always obtaining the most recent position with GetTrades() as you have specified 1 for the int instance argument.

    Please change this 1 to:
    Code:
    Performance.AllTrades.Count - (TradeNum - 1)
    for both instance arguments in both GetTrades() calls.

    Please, let me know if this does not resolve your issue.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Hello Zachary

      I changed the Print statements to...

      Print(intTradeNum.ToString() + "\t" + theTrade.Entry.Order.Name.ToString() + "..\t" + theTrade.ToString()
      + "..\t" + Performance.AllTrades.GetTrades(theTrade.Entry.Ins trument.ToString(), theTrade.Entry.Order.Name.ToString(), Performance.AllTrades.Count - (intTradeNum - 1)).Count
      + "..\t" + Performance.AllTrades.GetTrades(theTrade.Entry.Ins trument.ToString(),
      theTrade.EntryExecution.Name.ToString(), Performance.AllTrades.Count - (intTradeNum - 1)).TradesPerformance.Currency.AvgMae
      );



      But now I`m getting ZERO for all AvgMAE. Here is what the output looks like:


      1 LENT-30.. Instrument='YM 12-15' EntryPrice=16255 ExitPrice=16216 Quantity=1 Market position=Long EntryTime='9/10/2015 1:58:00 AM' ExitTime='9/10/2015 2:50:00 AM' TotalProfitCurrency=$-199.04.. 0.. 0
      2 LENT-40.. Instrument='YM 12-15' EntryPrice=16290 ExitPrice=16230 Quantity=1 Market position=Long EntryTime='9/10/2015 4:27:00 AM' ExitTime='9/10/2015 4:27:00 AM' TotalProfitCurrency=$-304.04.. 0.. 0
      3 LENT-44.. Instrument='YM 12-15' EntryPrice=16311 ExitPrice=16251 Quantity=1 Market position=Long EntryTime='9/10/2015 5:54:00 AM' ExitTime='9/10/2015 7:24:00 AM' TotalProfitCurrency=$-304.04.. 0.. 0
      4 LENT-45.. Instrument='YM 12-15' EntryPrice=16335 ExitPrice=16275 Quantity=1 Market position=Long EntryTime='9/10/2015 5:55:00 AM' ExitTime='9/10/2015 7:24:00 AM' TotalProfitCurrency=$-304.04.. 0.. 0
      5 LENT-46.. Instrument='YM 12-15' EntryPrice=16344 ExitPrice=16284 Quantity=1 Market position=Long EntryTime='9/10/2015 7:24:00 AM' ExitTime='9/10/2015 7:24:00 AM' TotalProfitCurrency=$-304.04.. 0.. 0
      6 SENT-47.. Instrument='YM 12-15' EntryPrice=16181 ExitPrice=16142 Quantity=1 Market position=Short EntryTime='9/10/2015 7:25:00 AM' ExitTime='9/10/2015 8:11:00 AM' TotalProfitCurrency=$190.96.. 0.. 0
      7 SENT-48.. Instrument='YM 12-15' EntryPrice=16185 ExitPrice=16142 Quantity=1 Market position=Short EntryTime='9/10/2015 7:30:00 AM' ExitTime='9/10/2015 8:11:00 AM' TotalProfitCurrency=$210.96.. 0.. 0
      8 SENT-49.. Instrument='YM 12-15' EntryPrice=16169 ExitPrice=16142 Quantity=1 Market position=Short EntryTime='9/10/2015 7:37:00 AM' ExitTime='9/10/2015 8:11:00 AM' TotalProfitCurrency=$130.96.. 0.. 0
      9 SENT-50.. Instrument='YM 12-15' EntryPrice=16175 ExitPrice=16142 Quantity=1 Market position=Short EntryTime='9/10/2015 7:41:00 AM' ExitTime='9/10/2015 8:11:00 AM' TotalProfitCurrency=$160.96.. 0.. 0



      Is instance supposed to represent a Position or a Trade ? The documentation made it sound like an occurrence of a collection of trades for a position.

      So.. if you look at the trades in the output...



      OrderName=LENT-30 is a LONG position with only 1 trade exited at '9/10/2015 2:50:00 AM'
      OrderName=LENT-40 is a LONG position with only 1 trade exited at '9/10/2015 4:27:00 AM'
      OrderName=LENT-44, LENT-45, LENT-46 is a LONG position with 3 trades exited at '9/10/2015 7:24:00 AM'


      So... what is GetTrades getting... a collection of trades for each position … right?



      Is GetTrades argument “entrySignalName” supposed to be the signalName of the FIRST trade of a possible multi-trade position ?


      Why does GetTrades need “entrySignalName” and “instance”, is it for partial fills?



      In the example I am testing with the trade quantity is always 1, yet the long and short positions are made up of 1 to many trades.


      Can you please let me know ?


      Thank you

      Comment


        #4
        Hello rayko,

        Please provide me your strategy so I can test on my end. If you do not want to submit your entire strategy, please submit a sample that reproduces this behavior.

        To export your script do the following:
        1. Click File -> Utilities -> Export NinjaScript
        2. Enter a unique name for the file in the value for 'File name:'
        3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
        4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


        By default your exported file will be in the following location:
        • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


        Below is a link to the help guide on Exporting NinjaScripts.
        http://www.ninjatrader.com/support/h...nt7/export.htm

        Once you have exported your strategy, please attach it to your next post, or send it to support [AT] ninjatrader [DOT] com with my name and a link to this thread referenced if you wish to not have your strategy on the forum.

        To answer your questions:
        • Instance refers to the occurence of the trade you are wanting to refer to. 1 is the most recent, 2 is the 2nd most recent position, etc.
        • GetTrades() returns a TradeCollection object representing all trades that make up the specified position.
        • The entrySignalName argument is referring to the signal name of the entry of a trade. A trade is comprised of an entry and exit.
        • GetTrades() utilizes the entrySignalName to determine which trades you would like to obtain. So, if you specify "myEntrySignal" for example, GetTrades() will obtain all trades that have "myEntrySignal" as the signal name for the entry order of the trade. Instance is the occurance to check for. 1 is the most recent, 2 is the 2nd most recent position, etc.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Hello Zachary,

          I`ve done what you asked. I included the code to print the trades on the OnTerminate event.

          The script is a copy of the NT standard "@SampleMACrossOver.cs" with the print code included.

          I`ve tested it using YM 12-15. I`ve also included a same Backtest screen scrape.
          Attached Files

          Comment


            #6
            Hello rayko,

            I'm investigating further on my end and will return with my findings.
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Hello rayko,

              I just wanted to inform you that this is a bug. It seems that the GetTrades() method call only works for long entries, but does not work for short entries. This bug is currently being tracked with an internal tracking number of TS-508.

              To get around this, you can manually calculate the MAE of short trades. The MAE is defined as (the worst price trade reached - entry price).

              Please, let us know if we may be of further assistance.
              Zachary G.NinjaTrader Customer Service

              Comment


                #8
                That’s disappointing.


                Unfortunately the work around you suggested won`t help right now. I am extracting the performance values from the OnTerminate event and I am not interested in add all the additional code required to calculate and test MAE, MFE, ETD for all trades within the strategy. Too much work for something that will be eventually fixed.


                Could you please tell me if you know when the next NT 7 point fix release will be available with fixes ?


                Thank you

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by usazencort, Today, 01:16 AM
                0 responses
                1 view
                0 likes
                Last Post usazencort  
                Started by kaywai, 09-01-2023, 08:44 PM
                5 responses
                603 views
                0 likes
                Last Post NinjaTrader_Jason  
                Started by xiinteractive, 04-09-2024, 08:08 AM
                6 responses
                22 views
                0 likes
                Last Post xiinteractive  
                Started by Pattontje, Yesterday, 02:10 PM
                2 responses
                21 views
                0 likes
                Last Post Pattontje  
                Started by flybuzz, 04-21-2024, 04:07 PM
                17 responses
                230 views
                0 likes
                Last Post TradingLoss  
                Working...
                X