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 set2win, 08-04-2021, 09:23 AM
            39 responses
            999 views
            0 likes
            Last Post WaleeTheRobot  
            Started by md4866, Today, 08:15 PM
            0 responses
            1 view
            0 likes
            Last Post md4866
            by md4866
             
            Started by mjbatts91, Yesterday, 04:48 PM
            2 responses
            23 views
            0 likes
            Last Post mjbatts91  
            Started by pibrew, Today, 06:10 PM
            1 response
            17 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by actualfacts.2021, 07-25-2021, 03:11 PM
            8 responses
            1,184 views
            0 likes
            Last Post linkcou
            by linkcou
             
            Working...
            X