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

Parameters do not change when change strategy & Failed to Call Method error

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

    Parameters do not change when change strategy & Failed to Call Method error

    I created a strategy. When I go to backtest it, I choose the instrument, click Backtest, and then choose the strategy name. When I do, none of the parameters change. They stay on whatever strategy was chosen before.

    Here is what happens when click Bactest on an instrument:


    Then, I choose my strategy I want to backtest:


    As you can see, the parameters have not changed.

    I then open the output window, and it says:
    **NT** Failed to call method 'Initialize' for strategy 'Mymoneymaker/b66c95fa84c0440fa26f72f7d404a518': Unexpected initial token 'Integer' when populating object. Expected JSON object or array. Path '', line 1, position 1.

    What do I do to fix this error so I can backtest this strategy?

    The strategy I am trying to backtest is:
    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// Based upon APEX's Momentum Scalping Strategy
        /// </summary>
        [Description("Based upon APEX's Momentum Scalping Strategy")]
        public class Mymoneymaker : Strategy
        {
            #region Variables
            // Wizard generated variables
            private int profitTarget = 6; // Default setting for ProfitTarget
            private int stopLoss = 9; // Default setting for StopLoss
            // User defined variables (add any user defined variables below)
            #endregion
    		private int  	target1 		= 6;
    		private int 	stoploss1		= 9;
    		
    
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                Add(ApexDiagnosticExpectedVolume("4, 0, true"));
                CalculateOnBarClose = true;
            }
    		
    		private void GoLong()
    		{
    			EnterLongStop(DefaultQuantity, High[1] + (3 * TickSize), "MomLong");
    			SetProfitTarget("MomLong", CalculationMode.Price, High[1] + (Target1*TickSize));
                SetStopLoss("MomLong", CalculationMode.Price, High[1] + (Stoploss1*TickSize), false);
                
    		}
    		
    		private void GoShort()
    		{
    			EnterShortStop(DefaultQuantity, Low[1] - (3 * TickSize), "MomShort");
    			SetProfitTarget("MomShort", CalculationMode.Price, Low[1] - (Target1*TickSize));
                SetStopLoss("MomShort", CalculationMode.Price, Low[1] - (Stoploss1*TickSize), false);
    		}
    		
            protected override void OnBarUpdate()
            {
    			if (Position.MarketPosition != MarketPosition.Flat) return;
    			
                // Long Condition
                if (ApexDiagnosticExpectedVolume("4, 0, true").ActualVolumeDataSeries[1] > ApexDiagnosticExpectedVolume("4, 0, true").ExpectedVolumeDataSeries[1]
                    && Close[1] > Open[1])
                {
                    GoLong();
                }
    
                // Short Condition
                if (ApexDiagnosticExpectedVolume("4, 0, true").ActualVolumeDataSeries[1] > ApexDiagnosticExpectedVolume("4, 0, true").ExpectedVolumeDataSeries[1]
                    && Close[1] < Open[1])
                {
                    GoShort();
                }
            }
    		
    
    
            #region Properties
            [Description("Momentkum Strategy")]
            [GridCategory("Parameters")]
            public int Target1
            {
                get { return target1; }
                set { target1 = Math.Max(1, value); }
            }
    
            [Description("")]
            [GridCategory("Parameters")]
            public int Stoploss1
            {
                get { return stoploss1; }
                set { stoploss1 = Math.Max(1, value); }
            }
            #endregion
        }
    }
    Thanks for your help!

    -Stearno

    #2
    Stearno, would expect that behavior with the initialize error you get, would you get the same outcome if you commented out the custom indicator you try to Add() for visualization?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Yep, I removed that line and it fixed the initialization error message.

      I now can see the parameters in Strategy Analyzer.

      But I think I still have a problem because it results with zeros.

      One possible problem is when I reference the custom indicator in the code, it will not let me just use type in the 3 arguments like with other indicators.

      Okay, if I right click and use insert condition, choose the indicator, then it inserts it like this: ApexDiagnosticExpectedVolume("{"PeriodInMinutes":4 ,"OffsetInMinutes":0,"UseFuturesVolumeForForex":tr ue}").ActualVolumeDataSeries[1]

      I then get an error when I try to compile it. It says ( is expected, : is expected, etc.)

      So, then I remove all the excess info and make it have normal arguments like a normal indicator. So I type in:

      ApexDiagnosticExpectedVolume(4, 0, true).ActualVolumeDataSeries[1]

      Then again, I get error messages about having the wrong number of arguments. It says it needs 3 arguments (which I have).

      So, to not get error messages, I have to use the "" around the arguments. But then my fear is that it is not accessing the custom indicator like it is suppose to.
      ApexDiagnosticExpectedVolume("4, 0, true").ActualVolumeDataSeries[1]

      So how do I reference the custom indicator properly in this strategy? I appreciate your help!

      I cannot post the indicator here as it is proprietary and I only rent it, but I can email to you if that will help. Thanks.

      -Stearno
      Last edited by stearno; 05-23-2014, 08:39 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by alifarahani, Today, 09:40 AM
      6 responses
      36 views
      0 likes
      Last Post alifarahani  
      Started by Waxavi, Today, 02:10 AM
      1 response
      17 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by Kaledus, Today, 01:29 PM
      5 responses
      14 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by Waxavi, Today, 02:00 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by gentlebenthebear, Today, 01:30 AM
      3 responses
      17 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X