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

NinjaScriptProperty

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

    NinjaScriptProperty

    hi,
    i need to call myClass by Different ways

    Example:

    P1Class(int i);

    P1Class(int i, string s, double d);

    how can i create class in this way? i can setting attribute [NinjaScriptProperty]
    but only 1 time

    thanks

    #2
    Hello esignal,

    This would be general C# and would not be specific to NinjaScript.

    For multiple overloads, you need to declare the method multiple times with different overloads.

    Code:
    public void MyMethod()
    {
    
    }
    
    public void MyMethod(int intVariable)
    {
    
    }
    Below is a public available link to an educational site that discusses overloads.
    Use overloaded method calls. Inspect the IL code for overloads.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      i don't want to call method...but class indicator :
      Examples :

      P1Class(i).Pippo(3);
      or
      P1Class(i,"tttt",9.2).Pippo(3);

      is not method but class costructors i think..and when i create indicator i don't use constructors..i use attribute [NinjaScriptProperty] in the property


      Look @swing :
      ...
      ...

      Code:
      #region NinjaScript generated code. Neither change nor remove.
      
      namespace NinjaTrader.NinjaScript.Indicators
      {
      	public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
      	{
      		private Swing[] cacheSwing;
      		public Swing Swing(int strength)
      		{
      			return Swing(Input, strength);
      		}
      
      		public Swing Swing(ISeries<double> input, int strength)
      		{
      			if (cacheSwing != null)
      				for (int idx = 0; idx < cacheSwing.Length; idx++)
      					if (cacheSwing[idx] != null && cacheSwing[idx].Strength == strength && cacheSwing[idx].EqualsInput(input))
      						return cacheSwing[idx];
      			return CacheIndicator<Swing>(new Swing(){ Strength = strength }, input, ref cacheSwing);
      		}
      	}
      }
      in this code there is Overload..but it is built in ninjatrader when i compile it..
      Last edited by esignal; 11-29-2016, 03:35 PM.

      Comment


        #4
        Hello esignal,

        Any code you change in the NinjaScript generated code will be undone when the script is compiled.

        The code you add will need to be outside of this region.

        You can add a partial Indicator class that extends the indicator base and create an additional method with different overload parameters similar to the dotnetperls guide I have linked in my previous post.
        (This is basically the same as the NinjaTrader generated code but with your own custom methods and outside of that region)

        However, keep in mind, this is outside of what is supported by NinjaScript support.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          ok..i do it...

          Code:
          #region Using declarations
          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.ComponentModel.DataAnnotations;
          using System.Linq;
          using System.Text;
          using System.Threading.Tasks;
          using System.Windows;
          using System.Windows.Input;
          using System.Windows.Media;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Gui;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Gui.SuperDom;
          using NinjaTrader.Data;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.Core.FloatingPoint;
          using NinjaTrader.NinjaScript.DrawingTools;
          #endregion
          namespace NinjaTrader.NinjaScript.Indicators
          {
              public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
              {
          
                  public MainTrendAnalisys MainTrendAnalisys1(int contaBarre)
                  {
          
                      return MainTrendAnalisys(Input, contaBarre);
                  }
          
              }
          }
          
          #region NinjaScript generated code. Neither change nor remove.
          
          namespace NinjaTrader.NinjaScript.Indicators
          {
          	public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
          	{
          		private Indicator[] cacheIndicator;
          		public Indicator Indicator()
          		{
          			return Indicator(Input);
          		}
          
          		public Indicator Indicator(ISeries<double> input)
          		{
          			if (cacheIndicator != null)
          				for (int idx = 0; idx < cacheIndicator.Length; idx++)
          					if (cacheIndicator[idx] != null &&  cacheIndicator[idx].EqualsInput(input))
          						return cacheIndicator[idx];
          			return CacheIndicator<Indicator>(new Indicator(), input, ref cacheIndicator);
          		}
          	}
          }
          
          namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
          {
          	public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
          	{
          		public Indicators.Indicator Indicator()
          		{
          			return indicator.Indicator(Input);
          		}
          
          		public Indicators.Indicator Indicator(ISeries<double> input )
          		{
          			return indicator.Indicator(input);
          		}
          	}
          }
          
          namespace NinjaTrader.NinjaScript.Strategies
          {
          	public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
          	{
          		public Indicators.Indicator Indicator()
          		{
          			return indicator.Indicator(Input);
          		}
          
          		public Indicators.Indicator Indicator(ISeries<double> input )
          		{
          			return indicator.Indicator(input);
          		}
          	}
          }
          
          #endregion
          But when i compile , it give me error
          It create in automatic this code :

          #region NinjaScript generated code. Neither change nor remove.

          namespace NinjaTrader.NinjaScript.Indicators
          {
          public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
          {
          private Indicator[] cacheIndicator;
          public Indicator Indicator()
          {
          return Indicator(Input);
          }

          public Indicator Indicator(ISeries<double> input)
          {
          if (cacheIndicator != null)
          for (int idx = 0; idx < cacheIndicator.Length; idx++)
          if (cacheIndicator[idx] != null && cacheIndicator[idx].EqualsInput(input))
          return cacheIndicator[idx];
          return CacheIndicator<Indicator>(new Indicator(), input, ref cacheIndicator);
          }
          }
          }

          namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
          {
          public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
          {
          public Indicators.Indicator Indicator()
          {
          return indicator.Indicator(Input);
          }

          public Indicators.Indicator Indicator(ISeries<double> input )
          {
          return indicator.Indicator(input);
          }
          }
          }

          namespace NinjaTrader.NinjaScript.Strategies
          {
          public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
          {
          public Indicators.Indicator Indicator()
          {
          return indicator.Indicator(Input);
          }

          public Indicators.Indicator Indicator(ISeries<double> input )
          {
          return indicator.Indicator(input);
          }
          }
          }

          #endregion
          Last edited by esignal; 11-30-2016, 08:41 AM.

          Comment


            #6
            Hello esignal,

            Is the entire script?

            This will not compile. The entire indicator class is missing.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ChelseaB View Post
              Hello esignal,

              Is the entire script?

              This will not compile. The entire indicator class is missing.
              what i missing?...you say "You can add a partial Indicator ,,"

              i add it :
              Code:
               
              namespace NinjaTrader.NinjaScript.Indicators
              {
                  public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
                  {
               
                      public MainTrendAnalisys MainTrendAnalisys1(int contaBarre)s
                      {
               
                          return MainTrendAnalisys(Input, contaBarre);
                      }
               
                  }
              }
              MaintrendAnalisys is an indicator present in folder bind/custom/indicator

              Comment


                #8
                Hello esignal,

                When I mentioned you can add a partial class, I was not suggesting you should erase the indicator class.

                The errors are likely occurring because the NinjaTrader generated code is referencing the Indicator class that was deleted.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Kensonprib, 04-28-2021, 10:11 AM
                5 responses
                191 views
                0 likes
                Last Post Hasadafa  
                Started by GussJ, 03-04-2020, 03:11 PM
                11 responses
                3,230 views
                0 likes
                Last Post xiinteractive  
                Started by andrewtrades, Today, 04:57 PM
                1 response
                14 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by chbruno, Today, 04:10 PM
                0 responses
                7 views
                0 likes
                Last Post chbruno
                by chbruno
                 
                Started by josh18955, 03-25-2023, 11:16 AM
                6 responses
                441 views
                0 likes
                Last Post Delerium  
                Working...
                X