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

multiple overloads of indicator

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

    multiple overloads of indicator

    is it possible to create an indicator with several overloads?

    like it was possible to call my indis:

    MyIndi ( bool XYZ )

    and also with

    MyIndi ( int XYZ )

    and i could handle each scenario in MyIndi code.

    does it break anything if i add constructors (inside ` public class MyIndi: Indicator`) like these:

    Code:
    public MyIndi(int xyz) { }
    public MyIndi(bool xyz) { }
    Last edited by ttodua; 07-24-2018, 04:47 AM.

    #2
    Hello TazoTodua,

    Thank you for the post.

    You could do this by creating a second partial class that is similar to the existing NinjaScript generated code at the bottom of the file. Please note this is not something we document or support, but I will provide a small sample that you can further explore. I see that when compiling this does not get removed, so in theory, this will allow for a custom set of overloads to be defined. In the case this did get replaced, you could move this into a second .cs file.

    Creating another partial class would allow you to define a new constructor with extra parameters. A public property from the indicator is used, but you could also toggle other user input properties at this point as well.

    Code:
    public partial class Indicator : IndicatorBase
    {
    	public ExtraContructorIndicator ExtraContructorIndicator(bool b)
    	{
    		ExtraContructorIndicator t = ExtraContructorIndicator(Input);
    		t.TestBool = b;
    		return t;
    	}
    }
    Once the class is defined, you can then explore the overload sets the indicator has which I have shown below:

    Code:
    double a = ExtraContructorIndicator()[0];  // no parameters 
    double b = ExtraContructorIndicator(Close)[0];  // default input
    double c = ExtraContructorIndicator(true)[0];  // custom bool
    I look forward to being of further assistance.
    Attached Files
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse, what it could be if you were not here
      U superb as always

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by nandhumca, Yesterday, 03:41 PM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by The_Sec, Yesterday, 03:37 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by vecnopus, Today, 06:15 AM
      0 responses
      1 view
      0 likes
      Last Post vecnopus  
      Started by Aviram Y, Today, 05:29 AM
      0 responses
      5 views
      0 likes
      Last Post Aviram Y  
      Started by quantismo, 04-17-2024, 05:13 PM
      3 responses
      27 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X