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

Usage of indicator within another indicator

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

    Usage of indicator within another indicator

    Hello,
    I developed an indicator "X" . I want to use the developed indicator "X" within another indicator "Y".
    I would like to access internal variables of "X" or variables that are plotted by "X [using Addplot].
    What I did is within "Y" :
    X newX = X(in0,in1) ;
    double tmp0 = newX. var0 ; // var0 is an AddPlot of "X"
    I get an error CS1061.
    My understanding from this is that I need to define "var0" differently.
    What is needed to be done in both X and Y indicators ?
    I tried looking for documentation but couldn't find any .
    Thanks

    #2
    Hello Leope,

    Thank you for the post.

    If var0 is a plot, you must have a series set up in your indicator to return the respective Values[] array.

    For example, look at the code of the MACD indicator, which has multiple plots. There is a custom series set up for each plot it has. Those series' get method returns the corresponding Values[][] array of the plot.

    In State.SetDefaults:

    Code:
    AddPlot(Brushes.Crimson,NinjaTrader.Custom.Resource.NinjaScriptIndicatorAvg);
    Then a custom series is set up to alias that series:

    Code:
    #region Properties
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Avg
    {
    	get { return Values[1]; }
    }
    Then you would access that series from your indicator like so:

    Code:
    double val = MACD(5,9,12).Avg[0];
    Notice that you do not need to reference the first index because the getter does that for you.

    Please let us know if we may be of any further assistance.
    Last edited by NinjaTrader_ChrisL; 04-19-2018, 09:07 AM.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,
      Thanks for your quick reply ! Your support is outstanding !
      I changed my indicator according to your answer, and now it compiles ok.
      But when I try to run it (on a chart), I get the following message:
      "A hosted indicator tried to load additional data. All data must first be loaded by the hosting Ninjascript in its configure state"
      What does this mean and what is still missing ?
      Thanks !!

      Comment


        #4
        Hello Leope,

        Thank you for the follow-up.

        Kindly see this post regarding the same item. My colleague's answer is in post #2.



        If you have an indicator that calls AddDataSeries() you must have a duplicate call to AddDataSeries() in the script which is using that indicator.

        Please see the section "Prevention of Redundant Data Loading" on this page:



        Please let me know if I may be of any further assistance.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,607 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        9 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        19 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        6 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        15 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X