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

AllTrades.Count = 0 after closed managed trades

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

    AllTrades.Count = 0 after closed managed trades

    Hello,

    I am hoping you can help me figure out a problem I am having getting realtime strategy trades to show up in the SystemPerformance object. In version 8.0.0.12 standard beta, had same problem in .11 over last few days. Not sure if this is code problem or maybe corruption problem.

    Code:
            private bool    entryPlaced = false;
            
            protected override void OnBarUpdate()
            {
                if (State == State.Realtime) {
    
                    if (Position.MarketPosition == MarketPosition.Flat) {
                        Print(CurrentBar + " Position is FLAT and AllTrades Count is "+SystemPerformance.AllTrades.Count);
                        if (!entryPlaced) {
                            EnterLong();
                            SetStopLoss(CalculationMode.Ticks, 2);
                            SetProfitTarget(CalculationMode.Ticks, 2);
                            entryPlaced = true;
                        }
                    }             
                    else Print(CurrentBar + " Position is NOT FLAT and AllTrades Count is "+SystemPerformance.AllTrades.Count);
                    
                }
                                
            
            }
    On my machine, this code will enter a trade and then exit as expected. Sync status starts at TRUE and then after stop or target is filled it goes to FALSE. Not sure if that's right. And I would expect the count of trades in performance to increment 1 but it stays at 0. The output window is like:

    Enabling NinjaScript strategy 'LongPlacerTestSync/70812310' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On each tick IsUnmanaged=False MaxRestarts=4 in 5 minutes
    7039 Position is FLAT and AllTrades Count is 0
    7/11/2016 11:46:12 PM Strategy 'LongPlacerTestSync/70812310': Entered internal SubmitOrderManaged() method at 7/11/2016 11:46:12 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
    NinjaScript strategy 'LongPlacerTestSync/70812310' submitting order
    7/11/2016 11:46:12 PM Strategy 'LongPlacerTestSync/70812310': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Ticks Value=2 IsSimulatedStop=False IsMarketIfTouched=False
    7/11/2016 11:46:12 PM Strategy 'LongPlacerTestSync/70812310': Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Ticks Value=2 IsSimulatedStop=False IsMarketIfTouched=False
    NinjaScript strategy 'LongPlacerTestSync/70812310' submitting order
    NinjaScript strategy 'LongPlacerTestSync/70812310' submitting order
    7039 Position is NOT FLAT and AllTrades Count is 0
    7039 Position is NOT FLAT and AllTrades Count is 0
    7040 Position is NOT FLAT and AllTrades Count is 0
    7040 Position is FLAT and AllTrades Count is 0
    7040 Position is FLAT and AllTrades Count is 0
    Disabling NinjaScript strategy 'LongPlacerTestSync/70812310'
    Thank you.

    #2
    Hello greagrea,

    Thank you for writing in and welcome to the NinjaTrader Support Forum!

    I do not see any issues with the syntax of the code snippet you have provided. I have tested this code on my end and was successfully able to get AllTrades.Count to increment once the exit order filled.

    For further testing on my end, can you please provide the script cs file you are using as well as a screenshot of the strategy parameters you are using for your strategy in the Strategies window?

    To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

    Click here for instructions

    Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

    Click here for detailed instruction
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      unable to deserialize

      Hi Zachary,

      Thank you for your response. I went ahead and ran the same strategy on a separate NT8 install on a different computer. It runs fine there so I think I can rule out the strategy itself. Seems I may have a corrupted install here.

      So I looked into the log on the install that isn't working. I have deserialization error messages. (screenshot below)

      Regarding the deserialization errors, is there a recommended way to fix this? I tried removing all custom strategies, re-compiling, deleting cached files. No luck. Am I looking at a complete wipe and reinstall?

      Thank you.
      Attached Files

      Comment


        #4
        Hello greagrea,

        Do you have a template saved for this strategy?

        To check for this, shut down NinjaTrader and follow the steps below:
        1. Navigate to the (My) Documents\NinjaTrader 8\templates\Strategy directory on your computer
        2. Remove the template for your strategy
        3. Restart NinjaTrader and re-test
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ZacharyG View Post
          Hello greagrea,

          Do you have a template saved for this strategy?

          To check for this, shut down NinjaTrader and follow the steps below:
          1. Navigate to the (My) Documents\NinjaTrader 8\templates\Strategy directory on your computer
          2. Remove the template for your strategy
          3. Restart NinjaTrader and re-test
          Unfortunately no, there are no templates for the strategy. The only template I have created is for a DrawingTool. I did have another strategy that was referencing this DrawingTool. I tried removing that but had no effect after restart and retest.

          Comment


            #6
            Hello greagrea,

            There may be an issue with the database.

            Please follow the instructions below to reset the NinjaTrader database.
            • Disconnect NinjaTrader from any open connections via File > Disconnect
            • From the NinjaTrader Control Center window select the menu Tools > Database
            • Press "Reset DB"
            • Check Historical Orders to remove historical orders
            • Check Historical Trades to remove historical trades
            • Press the "Reset" button


            Please, let us know if you continue to see the error.
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Well, that cleared up the serialization errors -- no longer showing up in the log.

              But the strategy still behaves incorrectly, so I guess it was unrelated. Anything else I can try?

              Comment


                #8
                Hello greagrea,

                Can you please provide the strategy you are running that is behaving incorrectly so I may test it on my end?

                Please ensure you are providing it from the computer that is showing the incorrect behavior.

                Your strategy can be found within the (My) Documents\NinjaTrader 8\bin\Custom\Strategies folder.
                Zachary G.NinjaTrader Customer Service

                Comment


                  #9
                  strategy is attached

                  Hi Zachary,

                  Sure thing. Here it is.

                  Thank you.
                  Attached Files

                  Comment


                    #10
                    Hello greagrea,

                    Thank you for providing the script.

                    I do not see this unexpected behavior on the script.

                    I would suggest renaming your database.

                    Please rename your database with the following steps:
                    • Shutdown NinjaTrader and Go to the Start Menu
                    • Select My Documents--> NinjaTrader 8--> DB--> NinjaTrader.SDF.
                    • Right click on NinjaTrader.SDF and select "Rename." *Name it "OLDNinjaTrader.SDF."
                    • Then restart the software and NinjaTrader will create a fresh database file to use
                    • Unfortunately the following items stored in the old database will be lost - Session templates, Instrument Lists / Custom Instruments, historical trade execution data, saved Strategy Analyzer backtest results


                    To prevent running into situations where you can potentially lose important data, we advise to run regular backups via our inbuilt backup feature in NinjaTrader - http://ninjatrader.com/support/helpG...up_archive.htm

                    Please, let us know if the behavior persists.
                    Zachary G.NinjaTrader Customer Service

                    Comment


                      #11
                      I have performed these instructions. NT created a new database. Unfortunately, behavior continues unchanged.

                      Thank you.

                      Comment


                        #12
                        Hello greagrea,

                        As a test, please take the following steps to force NinjaTrader to start without your saved workspace. You will have the option to reopen these after our tests.
                        • Shut down NinjaTrader
                        • Navigate to (My) Documents\NinjaTrader 8\workspaces
                        • Cut and paste all the files within this folder onto your desktop
                        • Restart NinjaTrader which should startup without any workspaces.
                        • Once NinjaTrader has started on just the control center, please open a new chart with no custom bar types/indicators/templates and test for issue.
                        Zachary G.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Zachary,

                          OK, have some new information. I followed your instructions. Actually, this is the first time I'm running this strategy from a chart now. I had been adding to strategy window and setting up instrument information there.
                          So, running this within a chart works correctly. I get the count of 1 after trade closes.
                          I then tried again running from the control panel, and that behaves incorrectly. Count stays at 0.

                          I put all the workspaces back in and restarted. Same thing. Works from a chart. Doesn't work from control panel.

                          As I recall, on the other computer it did work from control panel. Thoughts?

                          Thank you.

                          Comment


                            #14
                            Hello greagrea,

                            Please send me your log and trace files so that I may investigate further.

                            You can do this by going to the Control Center-> Help-> Email Support.

                            Ensuring 'Log and Trace Files' is checked will include these files. This is checked by default.

                            Please reference both my name and a link to this thread in the body of the email.
                            Zachary G.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello greagrea,

                              I have created a simple test script that will just enter and exit a position. Can you please test this test script on your end to see if you are still not seeing SystemPerformance.AllTrades.Count increment?
                              Attached Files
                              Zachary G.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by love2code2trade, 04-17-2024, 01:45 PM
                              4 responses
                              36 views
                              0 likes
                              Last Post love2code2trade  
                              Started by alifarahani, Today, 09:40 AM
                              2 responses
                              13 views
                              0 likes
                              Last Post alifarahani  
                              Started by junkone, Today, 11:37 AM
                              3 responses
                              16 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by pickmyonlineclass, Today, 12:23 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post pickmyonlineclass  
                              Started by frankthearm, Yesterday, 09:08 AM
                              12 responses
                              44 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Working...
                              X