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 TheWhiteDragon, 01-21-2019, 12:44 PM
      4 responses
      541 views
      0 likes
      Last Post PaulMohn  
      Started by GLFX005, Today, 03:23 AM
      0 responses
      3 views
      0 likes
      Last Post GLFX005
      by GLFX005
       
      Started by XXtrader, Yesterday, 11:30 PM
      2 responses
      11 views
      0 likes
      Last Post XXtrader  
      Started by Waxavi, Today, 02:10 AM
      0 responses
      7 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Started by TradeForge, Today, 02:09 AM
      0 responses
      14 views
      0 likes
      Last Post TradeForge  
      Working...
      X