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 helpwanted, Today, 03:06 AM
      1 response
      7 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      7 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      5 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      242 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      385 views
      1 like
      Last Post Gavini
      by Gavini
       
      Working...
      X