Announcement

Collapse
No announcement yet.

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.

    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.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        661 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        375 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        110 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        580 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X