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

  • NinjaTrader_Jesse
    replied
    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 .

    Leave a comment:


  • mbesha
    replied
    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

    Leave a comment:


  • NinjaTrader_Bertrand
    replied
    mbesha, correct the Performance collection would only hold completed / booked trades.

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

    http://www.ninjatrader.com/support/h...7/position.htm

    If you're working MultiSeries - http://www.ninjatrader.com/support/h.../positions.htm

    Leave a comment:


  • mbesha
    replied
    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.

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    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.

    Leave a comment:


  • mbesha
    replied
    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, 08:48 PM.

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    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.

    Leave a comment:


  • mbesha
    replied
    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

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello,

    I wanted to ask have you defined any custom DataSeries in your script?

    Generally the error you are getting is related to a variable that was defined but given a value so it is not set to anything essentially.

    Being that this is happening on startup it is most likely that there is a data series that needs to be corrected or that there is a null value variable.

    The most common is when you create a data series like this

    Code:
    DataSeries test;

    but forget to add in your Initialize()

    Code:
    test = new DataSeries(this);

    That is just a example as other types of objects could do this.

    If you would like I can take a look at the code if you can not locate it.

    I look forward to being of further assistance.

    Leave a comment:


  • mbesha
    replied
    Error message when trying to enable strategy

    Hi Jesse

    Thanks as always for your help. I have encountered a problem when trying to enable my strategy. I keep getting an error message saying "Object reference not set to an instance of an object" despite the fact that the strategy code compiled without any problems. I have tried checking my code over again and again but I still can't pinpoint where the problem is. Can you please help me figure this out? I have attached my strategy file and a screenshot of the data settings for the primary data. Thanks.
    Attached Files

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello mbesha,
    For this could you please write me at platformsupport @ ninjatrader.com so that I can look into what you are seeing a little more.

    Please reference the link to this forum thread in the email so that It can get to me.

    I look forward to being of further assistance.

    Leave a comment:


  • mbesha
    replied
    Question about the way the chart is plotting

    Hi Jesse. I have a question for you regarding the way the bars are being plotted on the chart. As you can see from the screenshot I have attached, the chart is for the M6E 09-14 series and this is today's data. I have also attached a screenshot of the chart properties for your reference. Since it is a line break chart, I do not expect to see bars with zero range being plotted but that is what I find on the chart. Could you please tell me why this is happening? Thanks as always for your help and assistance.
    Attached Files

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello,

    If you are trying to use DateTime.Now instead of Time[0] you would just need to replace Time[0] with DateTime.Now

    Time[barsAgo] does exactly the same thing as DateTime.Now except that Time[barsAgo] you tell it how many bars ago to get the date from. Either way Time[0] and DateTime.Now return a DateTime object.

    You can then use ToTime to convert the DateTime into a integer value for easy comparison.

    Here is a example where I switched the two:

    Code:
    if((ToTime(DateTime.Now) >= 070000 && ToTime(DateTime.Now) <= 235959) || (ToTime(DateTime.Now) >= 000000 && ToTime(DateTime.Now) <= 061500))
    Now this would work to compare your local DateTime to an integer value, this still would work in coordination to the OnBarUpdate so this would only be checked each bar or each tick depending on your CalculateOnBarClose setting.

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

    Leave a comment:


  • mbesha
    replied
    Thanks for your input. Could you please tell me how exactly to code for DateTime.Now instead of Time[0]? For example, would this code "Condition 2 <= ToTime(DateTime.Now) >= Condition 1" for the time and "DateTime.Now.DayOfWeek == DayOfWeek.Saturday" for the day work? Please let me know.

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello mbesha,

    You are correct the Time[0] will return the timestamp from the bar.

    Time[0] is returning a DateTime object so it can be replaced with DateTime.Now to return the current PC time instead.

    DateTime is an object of time which has methods that are built into it for different time manipulations. Getting the current time, or subtracting or adding time from a date and so on.

    Here is a link for more information on DateTIme in C# http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx

    Please try and use the DateTime.Now and see if that corrects the results for your time condition.

    I look forward to being of further assistance.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by futurenow, 02-06-2021, 12:36 PM
9 responses
351 views
0 likes
Last Post music_p13  
Started by efeuvejota01, Yesterday, 06:24 PM
2 responses
62 views
0 likes
Last Post jeronymite  
Started by Don22Trader1, Today, 01:44 PM
2 responses
32 views
0 likes
Last Post bltdavid  
Started by trader3000a, Today, 02:33 PM
1 response
17 views
0 likes
Last Post NinjaTrader_Kate  
Started by trader3000a, Today, 02:06 PM
1 response
20 views
0 likes
Last Post NinjaTrader_Jim  
Working...
X