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

Most Efficient way to interact with the output of an Indicator

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

    Most Efficient way to interact with the output of an Indicator

    Hello. I am trying to determine what is the processor efficient way to develop and interact with Indicators. Part of my confusion is trying to understand the what is happening in the background when accessing an Indicator in the following scenario...
    myVariable1 = SomeOtherIndicator(Param1, Param2).InfoNeeded1[0];
    myVariable2 = SomeOtherIndicator(Param1, Param2).InfoNeeded2[0];
    myVariable3 = SomeOtherIndicator(Param1, Param2).InfoNeeded3[0];
    In the above, it is safe to assume the entire code inside "SomeOtherIndicator" is being run through 3 times. (Ordinarily, this may not seem so bad, but one of my indicators has about 25 parameters and the code size is ~ 20,000 lines, and I may need to access several of its variables as output.)

    If the following were added to access a prior bar's data...
    myVariable4 = SomeOtherIndicator(Param1, Param2).InfoNeeded3[1];
    ... then I assume the entire code in the indicator would be run through once again.


    From what I understand of C#, I believe I should instead...

    1. Create an instance of the SomeOtherIndicator
    2. Initialize the new instance
    3. Access its public variables as necessary... as in this format...


    public class MyStrategy: Strategy
    {
    private int myVariable1 = 0;
    private int myVariable2 = 0;
    private int myVariable3 = 0;

    SomeOtherIndicator MyInstanceOfSomeOtherIndicator;
    protected override void Initialize()
    {
    MyInstanceOfSomeOtherIndicator = new SomeOtherIndicator (Param1, Param2);
    }

    protected override void OnBarUpdate()
    {
    myVariable1 = MyInstanceOfSomeOtherIndicator.InfoNeeded1;
    myVariable2 = MyInstanceOfSomeOtherIndicator.InfoNeeded2;
    myVariable3 = MyInstanceOfSomeOtherIndicator.InfoNeeded3;
    }
    }


    The above assumes that SomeOtherIndicator has a Constructor which will allow the initial parameters to be initialized.

    Do I have it right? Thanks in advance.
    Last edited by montana; 04-28-2014, 11:56 AM.

    #2
    Hello montana,

    Yes, you may create an indicator variable like that but NinjaTrader will cache the Indicator as long as it has the same parameters so it would be basically the same thing either way.

    You may do it either way depending on what is easier for you.

    To create a indicator like a variable you may do something like the following:
    Indicator.SMA mySMA = new Indicator.SMA();

    protected override void OnStartUp()
    {
    mySMA = mySMA.SMA(Input, 14);
    }

    protected override void OnBarUpdate()
    {

    if(CurrentBar < BarsRequired) return;

    Print("mySMA: "+mySMA[0]);
    }
    JCNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by sidlercom80, 10-28-2023, 08:49 AM
    170 responses
    2,271 views
    0 likes
    Last Post sidlercom80  
    Started by Irukandji, Yesterday, 02:53 AM
    2 responses
    17 views
    0 likes
    Last Post Irukandji  
    Started by adeelshahzad, Today, 03:54 AM
    0 responses
    3 views
    0 likes
    Last Post adeelshahzad  
    Started by CortexZenUSA, Today, 12:53 AM
    0 responses
    3 views
    0 likes
    Last Post CortexZenUSA  
    Started by CortexZenUSA, Today, 12:46 AM
    0 responses
    1 view
    0 likes
    Last Post CortexZenUSA  
    Working...
    X