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

NT hangs when I run a strategy

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

    #31
    Hi Jesse

    Thanks for your prompt response. I have only included this code in the Initialize() section for my secondary data.

    Add("M6E 09-14",PeriodType.Second,5);

    Other than that and the primary data, I don't have any custom DataSeries. Could you please take a look at the code for me because I have tried everything to no avail. Thanks

    Comment


      #32
      Hello,

      It looks like you are not closing the stream writer in your ToWrite() method.

      The streamwriter would need to be closed between each write, Here is a example:

      Code:
      private void ToWrite(string txt) //Input of the StreamWriter
      {
      sw = new StreamWriter(path, true, System.Text.Encoding.UTF8);
      sw.WriteLine(txt);
      sw.Close();
      }
      A good way to test for problems when you don't know where they are is to use a single print statement.

      I place a print in the top of OnBarUpdate because the error indicated that's where it was coming from.

      I compile and run it, it of course terminates but my print printed, now i move below the next line and work my way through the code until I hit the point where it no longer prints.

      While this is a slow way to debug it sometimes is the only fast option so that's how i determined it was the ToWrite method.

      Please let me know if I may be of additional assistance.
      JesseNinjaTrader Customer Service

      Comment


        #33
        Hi Jesse

        I really owe you one, actually more than one by now, because my strategy is up and running now thanks to the changes you recommended. I will keep the tip you gave in mind the next time I have to debug my code but how exactly do you see the single printed statement? Do you do your debugging on NT or on a different software because if the strategy isn't enabled in NT, nothing prints on the output window but an error message is displayed instead. Anyway, a million thanks and your support and assistance are a prime reason why NT is my preferred trading software!
        Last edited by mbesha; 09-11-2014, 09:48 PM.

        Comment


          #34
          Hello,

          For the single print statement it would be listed in your Tools -> Output window. I am just referring to commenting out any prints that are not relevant and just using one Print() statement and moving it line by line as needed.

          I generally only use the NinjaScript editor for most everything, in the cases that I can not use the NinjaScript editor for some reason (I.E. customer indicator causes NinjaTrader to crash while running it), in that situation I may run a debug using visual studio if it is necessary.

          The NinjaScript editor in general can be used for just about all items NinjaScript related so I would not really recommend looking into any alternative editors until you feel very comfortable with not only NinjaScript but C# in general. Besides, not having more advanced code completion features causes you to use the resources available to you and helps you learn it better.

          Please let me know if I may be of additional assistance.
          JesseNinjaTrader Customer Service

          Comment


            #35
            Hi Jesse. I got a quick question for you. How do you get the current number of open trades? I tried using Performance.RealtimeTrades.Count but it only seems to get the number of past trades but not the live ones. Thanks.

            Comment


              #36
              mbesha, correct the Performance collection would only hold completed / booked trades.

              For the current strategy position, you could look into the Position object -



              If you're working MultiSeries - https://www.ninjatrader.com/support/.../positions.htm
              BertrandNinjaTrader Customer Service

              Comment


                #37
                Problem with the way the ninjatrader code is executing

                Hi. I am having some problems with the way some ninjatrader code is executing. I have attached my strategy, which won't enable because of the forementioned problem, for reference. As you can see from lines 96 & 97, the BarsSinceSession is printed to the output window and if you look at a screenshot of the chart I have attached, you will notice that there are numerous bars since the session started but from the screenshot of the output window which I have attached, you can see that the value printed is 1. Line 106 calls a method NumberOfContracts() whose code is from line 328 and despite the cash value of the sim account being $1000, the value written to the text file is zero. I have narrowed down the cause of the error caused when the program attempts to enable the strategy to the for loop in the CheckBars() method which is called in line 105 and its code is from 408. If the number of BarsSinceSession is not correct as in this case, the for loop doesn't work well. Could you please tell me why the value of the BarsSinceSession and AccountValue are not as they should be when I try to enable the strategy? Thanks.
                Attached Files

                Comment


                  #38
                  Hello,

                  I just wanted to update you.

                  Because of the size of this script I am having difficulty locating what is exactly causing the issue with the BarsSinceSession specifically.

                  I know that one thing that may come up is that the AccountValue is only displayed as a value above 0 in realtime data otherwise it is reported as a 0.

                  As for the BarsSinceSession I am still looking into this. It is possible that it would be better to take just the BarsSinceSession logic into a separate file for testing. I will continue looking at this file, if you can easily duplicate the logic in a separate file to test I would recommend that otherwise we will need to continue to see what is happening with the barsSinceSession here

                  I look forward to being of further assistance .
                  JesseNinjaTrader 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,769 views
                  0 likes
                  Last Post Leafcutter  
                  Started by Rapine Heihei, 04-23-2024, 07:51 PM
                  2 responses
                  30 views
                  0 likes
                  Last Post Max238
                  by Max238
                   
                  Started by Shansen, 08-30-2019, 10:18 PM
                  24 responses
                  943 views
                  0 likes
                  Last Post spwizard  
                  Started by Max238, Today, 01:28 AM
                  0 responses
                  10 views
                  0 likes
                  Last Post Max238
                  by Max238
                   
                  Working...
                  X