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 StockTrader88, 03-06-2021, 08:58 AM
      45 responses
      3,991 views
      3 likes
      Last Post johntraderuser2  
      Started by TAJTrades, Today, 09:46 AM
      0 responses
      7 views
      0 likes
      Last Post TAJTrades  
      Started by rhyminkevin, Yesterday, 04:58 PM
      5 responses
      62 views
      0 likes
      Last Post dp8282
      by dp8282
       
      Started by realblubb, Today, 09:28 AM
      0 responses
      8 views
      0 likes
      Last Post realblubb  
      Started by AaronKoRn, Yesterday, 09:49 PM
      1 response
      19 views
      0 likes
      Last Post Rikazkhan007  
      Working...
      X