Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

[BUG] AllTrades in Markert Replay

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

    [BUG] AllTrades in Markert Replay

    Hello guys,

    I found the bug in MarketReplay mode (NT 8.0.4.0).

    SystemPerformance.AllTrades.TradesCount and SystemPerformance.RealTimeTrades.TradesCount updates count correctly but NOT this two:
    SystemPerformance.AllTrades.Count and SystemPerformance.RealTimeTrades.Count


    It would be fine for me to use TradesCount, but TradeCollection is empty also and I can't iterate through trades

    I attached screenshot and Strategy file to reproduce the bug.

    Please fix it, most of my strategy based on that and this is really blocking me from do any kind of strategy.

    Thank you in advance!
    Attached Files
    Last edited by login_dejavu; 03-04-2017, 09:37 AM.

    #2
    Does this help any?

    I just gave up and quit.

    Comment


      #3
      Not really, but thanks anyway, IncludeTradeHistoryInBacktest = true will have no effect in my case (I guess same as in yours) because I do trades only if State.Realtime. I hope somebody from NT team will have a look into this.

      Comment


        #4
        Hello login_dejavu,

        Our help guide is ambiguous and I've sent a note to update this to our development.


        I'm not showing Count as documented and I feel TradeCount should be used and not Count.

        I've submitted a feature request to remove the Count object to reduce confusion (and change the TradeCount documentation to use TradeCount.

        You've mentioned the SystemPerformance.AllTrades TradeCollection is empty, is this correct?
        I've created a script to test this but I am not able to reproduce this behavior with the Playback connection using Market Replay data or historically.
        Are you able to reproduce using the supplied test script?

        Below is a link to a video of the test. Attached is the test script.
        Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello ChelseaB, and thanks for your reply.

          I personally don't have a problem that you have some alias property. And btw you will not be able to remove "Count", unless you'll rewrite the entire implementation of TradeCollection, which I doubt. Because "Count" comes from ICollection interface which is implemented by TradeCollection. If you want to remove one property it can be "TradesCount".

          Will it be possible for you to open my attached file strategy and see that TradeCollection is empty in MarketReplay?

          Thanks
          Last edited by login_dejavu; 03-05-2017, 03:17 PM.

          Comment


            #6
            Hello login_dejavu,

            So the condition is to go long is if the hour is an even hour (like 10:00 PM, 12:00 PM, 2:00 AM, etc), otherwise if the hours is odd (11:00 PM, 1:00 AM, 3:00 AM etc) then enter an odd position.

            I'm showing that if the script starts on one hour, and then the hour ends and a new hour ends, the position changes, the trade closes, and the system position updates on the next minute bar.

            So based on the way you coded the logic, yes, this works perfectly as you have written it to work as shown in the video i've linked below. The hour changes, the order position flips, and the trade collection is updated.
            Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


            A heads up, the position does not change immediately after you call EnterLong. The position changes after the execution, after the order updates, and after ninjatrader has changed the position internally. This means it is possible for the performance, order information, and position information to not yet be updated if called immediately after an order submission. This is why in the script I have provided, the performance check occurs in OnPositionUpdate().

            I've provided you with a script that does not require the hour to change before changing the direction to make testing much easier.

            So, as far as I can see, there is no issue here. Can you demonstrate that I am incorrect using the script that I have coded for you to demonstrate the correct way to use this object?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hey Guys, is this fixed ? using the code provided by Chelsea above I am getting the following error (see below)

              v8.0.21.0 64-bit

              I have tried the following in playback mode ..

              SystemPerformance.AllTrades.Count .. never increments, always zero

              SystemPerformance.RealTimeTrades.Count .. increments, but then bombs out with the error below when you try to query the trade..

              --
              Strategy '<name>197047982': Error on calling 'OnPositionUpdate' method on bar 15310: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
              --
              ref: SystemPerformanceCountTest_NT8.zip

              Comment


                #8
                last message before it bombs out

                --
                03/03/2020 02:42:00 RealTimeTrades.TradesCount: 2
                --

                Comment


                  #9
                  can also see the docs are still pointing to .Count and not .Trades.Count https://ninjatrader.com/support/help...timetrades.htm

                  update: running the code on its own works fine !! .. I just added the OnPositionUpdate() function to my strategy and it generated the bars ago error .. i will dissect

                  Comment


                    #10
                    so, i added the code to my strategy ...

                    Code:
                    protected override void OnPositionUpdate(Position position, double averagePrice, int quantity, MarketPosition marketPosition)
                            {
                                if (Position.MarketPosition != MarketPosition.Flat)
                                    return;
                    
                                if (AllowHistorical)
                                {
                                    if (SystemPerformance.AllTrades.Count > 0)
                                    {
                                        Print(string.Format("{0} AllTrades.Count: {1}", Time[0], SystemPerformance.AllTrades.Count.ToString()));
                    
                                        for (int i = 0; i < SystemPerformance.AllTrades.Count; i++)
                                        {
                                            //Print(string.Format("{0}", SystemPerformance.AllTrades[i].ToString()));
                                        }
                                    }
                    
                                    if (SystemPerformance.AllTrades.TradesCount > 0)
                                    {
                                        Print(string.Format("{0} AllTrades.TradesCount: {1}", Time[0], SystemPerformance.AllTrades.TradesCount.ToString()));
                    
                                        for (int i = 0; i < SystemPerformance.AllTrades.TradesCount; i++)
                                        {
                                            //Print(string.Format("{0}", SystemPerformance.AllTrades[i].ToString()));
                                        }
                                    }
                                }
                                else
                                {
                                    if (SystemPerformance.RealTimeTrades.Count > 0)
                                    {
                                        Print(string.Format("{0} RealTimeTrades.Count: {1}", Time[0], SystemPerformance.RealTimeTrades.Count.ToString()));
                    
                                        for (int i = 0; i < SystemPerformance.RealTimeTrades.Count; i++)
                                        {
                                            //Print(string.Format("{0}", SystemPerformance.RealTimeTrades[i].ToString()));
                                        }
                                    }
                    
                                    if (SystemPerformance.RealTimeTrades.TradesCount > 0)
                                    {
                                        Print(string.Format("{0} RealTimeTrades.TradesCount: {1}", Time[0], SystemPerformance.RealTimeTrades.TradesCount.ToString()));
                    
                                        for (int i = 0; i < SystemPerformance.RealTimeTrades.TradesCount; i++)
                                        {
                                            //Print(string.Format("{0}", SystemPerformance.RealTimeTrades[i].ToString()));
                                        }
                                    }
                                }
                            }
                    As you can see, I comment out the Print() commands in the loop and I can see this .. no errors ..

                    02/03/2020 02:00:00 AllTrades.TradesCount: 296

                    So, there are trades there from historical, and I can see the counter increment when in playback mode and trades are taken.. just can't access them via
                    Code:
                    SystemPerformance.AllTrades[i]
                    for some reason ... what can I do to debug this? any ideas ?



                    Comment


                      #11
                      Hello 12tkram,

                      I'm not sure I'm clear. You have tested the script I have provided and this is causing errors?

                      I've tested this again and I'm finding this is still working as expected.

                      Below is a link to a video.



                      If the script I have provided is causing errors, I would like to schedule a call with you so that I may observe the behavior on your end.

                      If the script I have provided is working as expected, what is the exact index being used causing an error in your custom script?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hey Chelsea, so to clarify,

                        1. using your strategy script as-is works fine on my terminal.
                        2. adding the OnPositionUpdate() function from your script into my strategy script so I can list trade info causes the index error as seen above.
                        3. commenting out the Print statements from the OnPositionUpdate() function in my script allows the script to run without error, you can see the trade numbers increment up.
                        4. the issue as far as I can see is that I cannot access SystemPerformance.AllTrades[i] for some reason, this is what I am assuming the index causing the issue is, but why ? is there some locking in memory of the index ?


                        Comment


                          #13
                          Hello 12tkram,

                          There is no locking in memory of the index.

                          The script I have provided is accessing this without issue.

                          What change are you making that after is causing an issue?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            The function was cut and pasted as-is from your script to mine .. I only added the AllowHistorical bool .. then I commented out the print statements .. thats it ..

                            if there any tracing we can turn on ?

                            Comment


                              #15
                              Hello 12tkram,

                              If the script I have provided is working without issue and the script you have created is not, then these are not the same.

                              Use prints to find the line of code with the error and print all of the values used for indexes.

                              Below is a link to a forum post that demonstrates how to use prints to understand behavior.


                              TraceOrders would not help here, as this tells when orders are being submitted, ignored, or cancelled.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by FrancisMorro, Today, 03:24 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post FrancisMorro  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              10 responses
                              1,770 views
                              0 likes
                              Last Post Leafcutter  
                              Started by Rapine Heihei, 04-23-2024, 07:51 PM
                              2 responses
                              31 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by Shansen, 08-30-2019, 10:18 PM
                              24 responses
                              944 views
                              0 likes
                              Last Post spwizard  
                              Started by Max238, Today, 01:28 AM
                              0 responses
                              11 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Working...
                              X