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

Custom Trading Performance Class

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

    Custom Trading Performance Class

    I'd like to create a custom class with methods that will allow me to add entry/exit trade events to a list and analyse the list to create stats.

    Has anything similar been done before or can anyone offer any advise?

    or may be a better question is what's the best way to structure this in the NinjaScript framwork given I may need to use it in different files?

    - the list would need to store trade event objects (date, time, entry, exit, etc.) so what would I use class/struct or something for each object?

    ... also not sure about how to pass plot series to custom methods and do custom methods have access to Time[0], Close[0], etc.?
    Last edited by futurenets; 01-01-2015, 11:22 AM.

    #2
    Hello,

    Thank you for the question.

    This would not be something that NinjaScript can do by its self but you could certainly create a List using C# and populate it with data how you wish to. What you are referring to would be a List using a custom Object that you create. Here is a MSDN article on collections with some examples. If you scroll to the bottom there is an example showing how to use a class as an object for the list.


    WIth that being said this is more of a general C# item than NinjaScript so there would not be anything in the help guide on this also this would be unsupported as this lies outside of NinjaScript.

    As far as using this in multiple files, you may run into problems depending on what you are trying to do. NinjaTrader runs each script as its own instance so there is not really a way to share data between two running scripts. In general if you are trying to share data between lets say a strategy and an indicator you would need to call the indicator and read its values from the strategy. there is no supported way for two separate running items to communicate.

    You can use the UserDefinedMethods script to place shared methods but please note if you will be exporting this script for others it would be best to just create your own class and use that instead.

    For your question on methods, are you referring to a private method you have created? If so you could do the following, please keep in mind you do not need to do this but this would be how to pass an object in an overload.

    Code:
    protected override void Initialize()
    {
            Add(new Plot(Color.Orange, PlotStyle.Line, "Plot0"));
    }
    protected override void OnBarUpdate()
    {
    	MyCustomMethod(Plot0);
    }
    private void MyCustomMethod(DataSeries series)
    {
    //do something with series. 
    }
    This would not be needed as Plot0 can be used in any method in your script because you define it as a public property in the properties section. This would be relevant if you had created a local variable that is not in the scope of the entire script.

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

    Comment


      #3
      thank you.

      Primarily I'm a C++ programmer but the NT C# is very good. I've created my own class which appears to work ok.

      I was going to

      mc = new myClass();

      and then use mc in my indicator but unsure if there are any limitations on what I can do with class methods/data?

      unrelated question but if I

      atr = ATR(Closes[
      0],period);

      I can get atr[0] but what if the indicator has multiple plots or other data I need to access?

      Comment


        #4
        Hello,

        As long as your class is either in the same namespace as your indicator or is accessible by using the correct syntax that should be fine.

        I would leave classes to what you are doing with your list, in general you wont need external classes much using NinjaScript. NinjaTrader tries to make as many methods available that do work for you so you don't need to do things like create custom classes. In this case for what you need a custom class is probably easiest.

        You can assign a indicator dataseries to a variable like you have
        Code:
        atr = ATR(Closes[0],period);
        To access a plot within the ATR, you could use a period or

        Code:
        atr = ATR(Closes[0],period).PlotNameHere
        A better example:
        Code:
        DataSeries bol = Bollinger(Close,1,10).Lower;
        Print(bol[0]);
        I would like to mention that if you do this, make sure it runs every bar otherwise you will be stuck with a static value.

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

        Comment


          #5
          class works great thanks

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by itrader46, Today, 09:04 AM
          0 responses
          3 views
          0 likes
          Last Post itrader46  
          Started by timmbbo, Today, 08:59 AM
          0 responses
          1 view
          0 likes
          Last Post timmbbo
          by timmbbo
           
          Started by bmartz, 03-12-2024, 06:12 AM
          5 responses
          33 views
          0 likes
          Last Post NinjaTrader_Zachary  
          Started by Aviram Y, Today, 05:29 AM
          4 responses
          14 views
          0 likes
          Last Post Aviram Y  
          Started by algospoke, 04-17-2024, 06:40 PM
          3 responses
          28 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X