Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

indicator reference

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

    indicator reference

    Hello i just wanted some clarification and on best practice example in the help ....

    private EMA myEMA;
    private Series<double> mySeries;
    private SessionIterator mySessionIterator;

    protected override void OnStateChange()
    {
    if (State == State.DataLoaded)
    {
    myEMA = EMA(20);
    mySeries = new Series<double>(this);
    mySessionIterator = new SessionIterator(Bars);
    }
    }

    In the above example it sets a reference to the EMA and then construct object in DataLoaded as is dependent on the Bars ?

    I have a custom indicator i use which i setup as a reference as in the EMA above ie
    private CustomInd1 myCustomInd;

    then initialise in the DaraLoaded state.

    With regards to ninja provided ones like EMA or SMA etc can they not just be referenced explicity in the onbarupdate method ie

    double value = EMA(High, 20)[0];

    What in the above is gained with the reference ? Is this needed in a strategy method or an indicator or typically when an indicator is calling a custom indicator within it.

    just trying to understand context here of this and the examples i come across.

    thanks

    #2
    Hello explorer101,

    With regards to ninja provided ones like EMA or SMA etc can they not just be referenced explicity in the onbarupdate method ie
    Sure, you can call the indicator directly or store it as a variable, you are using in the same way in both cases.


    What in the above is gained with the reference ? Is this needed in a strategy method or an indicator or typically when an indicator is calling a custom indicator within it.
    You don't need to keep filling in the parameters, you set them one time and then just use the indicators instance. If you are changing parameters or have variable logic, calling it from OnBarUpdate would be suggested in that case as a variable wouldn't handle the task.


    I look forward to being of further assistance.

    Comment


      #3
      thanks so just to confirm - if intended to mostly or only use set parameters store the indicator as a variable
      and if i plan to perhaps modify the input parameters for EMA or whatever being used based on certain conditions then call directly in onbarupdate is suggested?

      Comment


        #4
        Hello explorer101,

        Thanks for your reply.

        Correct, if you are dynamically changing the parameters while running then yes.

        Comment


          #5
          Originally posted by explorer101 View Post
          thanks so just to confirm - if intended to mostly or only use set parameters store the indicator as a variable
          and if i plan to perhaps modify the input parameters for EMA or whatever being used based on certain conditions then call directly in onbarupdate is suggested?
          It is always more efficient to use a named instance of an object. It you want to change the object's properties, that is exactly one of the imperatives of OOP. e.g, if you initially defined your EMA as ema, with Period as 10 (say), and want to change it to 20, you can either simply redefine the same object, or you can change the period directly.thus:
          Code:
          ema.Period = 20;

          Comment


            #6
            thanks Koganam for input.

            following from this it would appear that for a custom indicator and setting the parameters that in order to reference in another indicator and invoke an instance and even in the strategy builder - if i have an enum which i do (and have a type converter) and If i try to add it directly to a chart i can see the enum parameter and the dropdown options.
            But if i try to access it in strategy builder or setup a reference in the DataLoaded state in ninjascript code - ninja doesnt seem to recognise this enum based parameter and does not show up in either of these instances.
            Is this a known limitation? In which case i will be forced to do a numeric mapping ? In most cases in how i will use this i will not be directly adding to a chart as in most cases it will be referenced elsewhere.

            Also from what Kognam added above it would appear you can adjust the parameter value before making the reference in onbarupdate?

            thanks
            Last edited by explorer101; 10-29-2019, 09:48 AM.

            Comment


              #7
              Hello there, i just wanted to be clear that my last post had additional questions. I appreciate your team are attending to other questions as well so as and when
              thanks

              Comment


                #8
                Originally posted by explorer101 View Post
                thanks Koganam for input.

                following from this it would appear that for a custom indicator and setting the parameters that in order to reference in another indicator and invoke an instance and even in the strategy builder - if i have an enum which i do (and have a type converter) and If i try to add it directly to a chart i can see the enum parameter and the dropdown options.
                But if i try to access it in strategy builder or setup a reference in the DataLoaded state in ninjascript code - ninja doesnt seem to recognise this enum based parameter and does not show up in either of these instances.
                Is this a known limitation? In which case i will be forced to do a numeric mapping ? In most cases in how i will use this i will not be directly adding to a chart as in most cases it will be referenced elsewhere.

                Also from what Kognam added above it would appear you can adjust the parameter value before making the reference in onbarupdate?

                thanks
                Have you marked that enum property as a NinjaScriptProperty? That is how it gets recognized as a constructor parameter for the class.

                Comment


                  #9
                  Thanks Koganam, i did have it in place but because i am using a typeconverter for the enums which needs additional details i had commented that part out as it doesnt have a range like int or double. All sorted and i can see in strategy builder as well. Appreciated

                  Comment


                    #10
                    Originally posted by explorer101 View Post
                    Thanks Koganam, i did have it in place but because i am using a typeconverter for the enums which needs additional details i had commented that part out as it doesnt have a range like int or double. All sorted and i can see in strategy builder as well. Appreciated
                    Just remember that all Attribute decorations are optional. If an attribute makes no sense, just do not put it on.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    571 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    330 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
                    548 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    548 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X