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 Barry Milan, Today, 10:35 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by WeyldFalcon, 12-10-2020, 06:48 PM
      14 responses
      1,428 views
      0 likes
      Last Post Handclap0241  
      Started by DJ888, Yesterday, 06:09 PM
      2 responses
      9 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      40 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Today, 08:51 AM
      2 responses
      16 views
      0 likes
      Last Post bill2023  
      Working...
      X