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

How do I chain custom indicators in code?

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

    How do I chain custom indicators in code?

    Hi,

    I'm new to NinjaTrader and am in the process of porting over some of my indicators.

    Many of these indicators are chained together so that the output of one is used as the input of another.

    So far I haven't had any luck getting this setup, or finding the right help docs that explain how to connect one custom indicator to another in code. I've figure out how to do this manually on a chart, but I need to be able to set/call a custom indicator as an input to another custom indicator from within the indicator code.

    Can anyone give me some pointers on how this is accomplished, or where I can find the relevant help docs?

    Thanks,
    Mark

    #2
    Hi Mark

    Hopefully, I should be able to help out here.

    If you just want to reference an existing indicator within another, say EMA references MAX, it can be done very simply thus:

    Plot0.Set(EMA(MAX(High, 14), 7)[0]);

    This is all you need in OnBarUpdate() for it to be plotted.

    If you want to reference another indicator within one you're creating, you do this via the DataSeries method. (Good idea to look this up in NT Help.)

    In this example, I create a Data Series 'zseries' which I then embed within an EMA.

    Code:
    [B]Variables[/B]
    
    private DataSeries    zseries; // [I]"zseries" is my own name: could be anything.[/I]
    
    ...
    
    [B]protected override void Initialize()[/B]
    
        zseries    = new DataSeries(this);
    
    ...
    
    [B]protected override void OnBarUpdate()[/B]
    
    (my calculations for z)
    
    zseries.Set(z);
                
    double zz = EMA(zseries, 14)[0]; // [I]EMA(zseries, 14)[0] can be placed directly within Plot0.Set if you wish.[/I]
                
    Plot0.Set(zz);
    This certainly works for me. Hope it all works out.
    Last edited by arbuthnot; 01-19-2013, 08:24 AM.

    Comment


      #3
      Hello Mark,

      You may also view the following thread that has some helpful link to get started programming in NinjaScript.
      JCNinjaTrader Customer Service

      Comment


        #4
        clarifications

        Hi guys,

        Thanks for the links and sample code. I appreciate the help. I think perhaps my question was not entirely clear. What I'm looking to do is similar to what arbuthnot posted here:

        If you just want to reference an existing indicator within another, say EMA references MAX, it can be done very simply thus:

        Plot0.Set(EMA(MAX(High, 14), 7)[0]);
        Except that I'm trying to do this with a chain of my custom indicators, such as

        Plot0.Set(MyCustomIndicator()[0]);

        Obviously the calculations are more complex in my indicators, but hopefully this clarifies what I'm trying to do. I still haven't had any luck figuring this part out.

        Thanks again for any help,
        Mark

        Comment


          #5
          Originally posted by mark0419 View Post
          Hi guys,

          Thanks for the links and sample code. I appreciate the help. I think perhaps my question was not entirely clear. What I'm looking to do is similar to what arbuthnot posted here:

          Except that I'm trying to do this with a chain of my custom indicators, such as

          Plot0.Set(MyCustomIndicator()[0]);

          Obviously the calculations are more complex in my indicators, but hopefully this clarifies what I'm trying to do. I still haven't had any luck figuring this part out.

          Thanks again for any help,
          Mark
          That should work perfectly. You just need to make sure that you call MyCustomIndicator() with all the public properties that you defined when you coded it.

          Comment


            #6
            problem solved

            Thanks for all the help guys, I figured out my problem. With koganam's confirmation that the statement syntax was correct, I realized I some problems with the base line indicator and not in the one I was trying to create.

            Thanks!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Mestor, 03-10-2023, 01:50 AM
            16 responses
            388 views
            0 likes
            Last Post z.franck  
            Started by rtwave, 04-12-2024, 09:30 AM
            4 responses
            31 views
            0 likes
            Last Post rtwave
            by rtwave
             
            Started by yertle, Yesterday, 08:38 AM
            7 responses
            29 views
            0 likes
            Last Post yertle
            by yertle
             
            Started by bmartz, 03-12-2024, 06:12 AM
            2 responses
            22 views
            0 likes
            Last Post bmartz
            by bmartz
             
            Started by funk10101, Today, 12:02 AM
            0 responses
            7 views
            0 likes
            Last Post funk10101  
            Working...
            X