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

Indicator is a type but it is used as a variable.

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

    Indicator is a type but it is used as a variable.

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class SMAOptimizer : OptimizationType
    {
    #region variables

    private int n;
    private int numberOfTrades;

    private double p;


    private DataSeries myTrades;



    #endregion

    public override double GetPerformanceValue(SystemPerformance systemPerformance)
    {

    numberOfTrades = systemPerformance.AllTrades.TradesPerformance.Trad esCount;






    for ( int n = 1; n < numberOfTrades; n++ );

    {
    myTrades.Set(systemPerformance.AllTrades[n].ProfitCurrency);
    }

    //next line is error
    double p = SMA(myTrades, 10)[0];



    return p;


    }
    }
    }



    I get error "Indicator is a type but it is used as a variable." whatever I do. Please help

    #2
    Hello,

    Thanks for the forum post.

    Unfortunately custom optimization type are not supported.

    I did take a quick look however and you have this in a Strategy file. This should not go in the strategy file. Should instead be manually put into the My Documents->NinjaTrader 7->bin->custom->type.

    Also, please compare with optimizer types here, do you see any differences between the stock NinjaTrader and yours?

    I look forward to assisting you further.

    Comment


      #3
      For one thing, you already declared "p" as a double at creation. Your assignation statement should not declare it afresh.

      Comment


        #4
        double p is not a problem... also there is no problem with optimizationType... here is another, better example.... I just opened a new strategy and tried making new DataSeries... then put few numbers in it and then run SMA on this DataSeries... that is my question. I still get the same error.

        So, to get it straight: I need to calculate SMA with custom DataSeries input. Simple as that.

        Thank for replies!


        // This namespace holds all strategies and is required. Do not change it.
        namespace NinjaTrader.Strategy
        {
        /// <summary>
        /// Enter the description of your strategy here
        /// </summary>
        [Description("Enter the description of your strategy here")]
        public class proba : Strategy
        {
        #region Variables
        // Wizard generated variables
        private int myInput0 = 1; // Default setting for MyInput0
        private double p;
        private DataSeries myTrades;

        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
        CalculateOnBarClose = true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
        myTrades.Set(34);
        myTrades.Set(34);
        myTrades.Set(7);
        myTrades.Set(87);
        myTrades.Set(45);

        p = SMA(myTrades, 4)[0];
        }

        #region Properties
        [Description("")]
        [GridCategory("Parameters")]
        public int MyInput0
        {
        get { return myInput0; }
        set { myInput0 = Math.Max(1, value); }
        }
        #endregion
        }
        }

        Comment


          #5
          I do not see where your DataSeries is properly initialized - http://www.ninjatrader.com/support/h...ries_class.htm
          BertrandNinjaTrader Customer Service

          Comment


            #6
            I corrected the mistake in last example and it works now. Thanks

            I spent few minutes with C# tutorial and I actually need SMA to run on my custom array. I thought that DataSeries will do, but I have a custom array of numbers. Is this possible in NinjaScript?

            Comment


              #7
              Great - using arrays is possible in NinjaScript as it's general a C# extention, but unfortunately we could not support the coding aspects of it. The SMA would expect a DataSeries as input, a custom SMA on a list / array could be coded in C# as well.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Thank you. I will try with that

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Belfortbucks, Today, 09:29 PM
                0 responses
                3 views
                0 likes
                Last Post Belfortbucks  
                Started by zstheorist, Today, 07:52 PM
                0 responses
                7 views
                0 likes
                Last Post zstheorist  
                Started by pmachiraju, 11-01-2023, 04:46 AM
                8 responses
                150 views
                0 likes
                Last Post rehmans
                by rehmans
                 
                Started by mattbsea, Today, 05:44 PM
                0 responses
                6 views
                0 likes
                Last Post mattbsea  
                Started by RideMe, 04-07-2024, 04:54 PM
                6 responses
                33 views
                0 likes
                Last Post RideMe
                by RideMe
                 
                Working...
                X