Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Please Help with Calling an Indicator Within an Indicator

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

    Please Help with Calling an Indicator Within an Indicator

    I posted a while ago on a similar issue and thought that I had it figured out. But..............

    I write an indicator that gives me the ability to call one of several MA's. (I used the Ninja MACrossBuilder as an example of how to do this) The pertinent code is as follows:

    #region ------------------------- MA ASSIGNMENTS
    switch (MA0Type)
    {
    case CDMAtype.DEMA:
    MA0Series = DEMA(FastMAPeriod).Value;
    break;


    case CDMAtype.EMA:
    MA0Series = EMA(FastMAPeriod).Value;
    break;

    case CDMAtype.HMA:
    MA0Series = HMA(FastMAPeriod).Value;
    break;

    case CDMAtype.SMA:
    MA0Series = SMA(FastMAPeriod).Value;
    break;

    case CDMAtype.TEMA:
    MA0Series = TEMA(FastMAPeriod).Value;
    break;

    case CDMAtype.TMA:
    MA0Series = TMA(FastMAPeriod).Value;
    break;

    case CDMAtype.VWMA:
    MA0Series = VWMA(FastMAPeriod).Value;
    break;

    case CDMAtype.WMA:
    MA0Series = WMA(FastMAPeriod).Value;
    break;

    case CDMAtype.ZLEMA:
    MA0Series = ZLEMA(FastMAPeriod).Value;
    break;
    }


    It compiles and works as expected. If I then try to add another MA say KAMA for this discussion, , I get an error, "'CDMAType does not contain a definition for 'KAMA'" Here's the modified code snippet:


    #region ------------------------- MA ASSIGNMENTS
    switch (MA0Type)
    {
    case CDMAtype.DEMA:
    MA0Series = DEMA(FastMAPeriod).Value;
    break;

    case CDMAtype.KAMA:
    MA0Series = KAMA(FastMAPeriod, 8).Value;
    break;

    case CDMAtype.EMA:
    MA0Series = EMA(FastMAPeriod).Value;
    break;



    Any suggestions as to why I'm getting this error?

    TIA

    #2
    Hello dmking,

    Thanks for your post.

    The error is advising you that you are accessing the custom enum CDMAType, looking for a moving average that is not added to that enum.

    Please see below for further insight on using enums in C# and NinjaScript.



    Enum's (Publicly available resource) - http://csharp-station.com/Tutorial/CSharp/Lesson17

    I suggest looking in your source code to see where "CDMAtype" is defined so you can see where you can add to this enum. You may also wish to turn this into a new enum altogether to prevent conflicts with the MACrossBuilder script.

    We look forward to assisting.



    Comment


      #3
      Thanks Jim.

      I created a new Enum - MAType - and added it in so all is OK now. Seems that when I cut and pasted then modified the new code, there was still some ref to the enum in the origiinal code. I thought that I had removed all refs to the original indicator, but some how my new code was using the Enum ref from the original. Can't figure that out.

      Comment


        #4
        Hello dmking,

        Keep in mind that the MACrossBuilder script places enums outside of any namespace. The enum is outside of the indicator's class and would be available globally. This would mean that you can create an enum outside of any namespace and another script that is being compiled at the same time would be able to use it.

        We would suggest keeping the old enum in your script, renaming it to your own if you want to add to it, and to change your script to use the new enum accordingly.

        Also as a tip, if you place the enum in a custom namespace like in SampleUniversalMovingAverage, it will be less likely to conflict with other scripts that may make global enums of the same name.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        579 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X