Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to call a custom indicator into another custom indcator as a ISeries<double>

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

    How to call a custom indicator into another custom indcator as a ISeries<double>

    I am new to C# and Ninjatrader.


    I have 2 custom indicators. For simplicity I wil expose my problem like this : One is very simple. it is a copy of the official EMA.cs and I call it EMA_CUSTOM.
    Now I want to call EMA_CUSTOM inside My_cutom_indi_2 but it needs to be as a iSeries, because afterwards I take again the EMA of this, by calling EMA( my custom ISeries<double>, some period).

    In My_cutom_indi_2, I call various indicators like this :
    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class My_cutom_indi_2: Indicator
    {
    
    < lots of things >
    
    protected ISeries<double> _Average;
    protected ISeries<double> choose_MA(int param_1, int parma_2, double param_3)
    {
    switch(param_1)
    {
    case custom_enum.enum_1 :
    _Average=EMA_CUSTOM(parma_2, param_3);
    break;
    case custom_enum.enum_2 :​
    _Average=EMA(parma_2);
    break;
    case custom_enum.enum_3 :​​
    _Average=HMA(parma_2);
    break;
    }
    return _Average;
    }
    
    <lots of things >
    THen in OnBarUpdate(), I call choose_MA and I put it in the official EMA again :

    Code:
    Values[0] = EMA(choose_MA( param_1 , param_2, param_3 ), some_period )[0];
    Now the error of the Editor is : CS013. The name EMA_CUSTOM does not exist in the current context

    In the folder D:\Documents\NinjaTrader 8\bin\Custom\Indicators, I do Have the file EMA_CUSTOM.cs

    Both my custom indicators do compile and print on the chart when I comment out ''_Average=EMA_CUSTOM(parma_2, param_3);'' in the switch of choose_MA in My_cutom_indi_2
    Last edited by alanlopen; 03-17-2023, 11:40 AM.

    #2
    Hello alanlopen,

    I would suggest using the strategy builder to generate the code that you need to call the indicator. If you use your indicator in a condition and then click view code it will show the generated indicator code. You can then copy/paste the generated parts of the code relating to the indicator to use it in your existing indicator.

    Comment


      #3
      I dont'use any strategy. THe two scripts are really 2 indicators. When you talk about ''strategy builder'', you mean the ''new indciator'' wizard ?

      I forgot to say I am new to NT and C#

      Comment


        #4
        okay i solved it.

        My error was that I copy pasted the official EMA.cs, then replaced all occurences of ''EMA"' by ""CUSTOM_EMA". and apprently the underscore was problematic. Once I remove it, and compile again CUSTOM_EMA, then second indicator My_cutom_indi_2 with CUSTOM_EMA replaced by CUSTOMEMA, the script My_cutom_indi_2 compiled

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmoran13, Yesterday, 01:02 PM
        0 responses
        23 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        16 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        160 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        94 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        147 views
        2 likes
        Last Post CaptainJack  
        Working...
        X