Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

**NT** Error on getting/setting property

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

    **NT** Error on getting/setting property

    Hi,

    I have just written this very simple strategy, which is just supposed to print the state of bid-ask prices for input instruments. Unfortunately I am getting the following error, that I do not understand at all.

    **NT** Error on getting/setting property 'Instruments' for strategy 'MyCustomStrategy/37ac2ca530ae4e1d9fd316ad4cf0829e': Object of type 'NinjaTrader.Cbi.Instrument[]' cannot be converted to type 'System.String'.
    My code is quite simple, 'Instruments' is a string, I do not know why NT is complaining about 'Cbi.Instrument'.....

    Code:
    namespace NinjaTrader.Strategy
    {
        [Description("...")]
        public class MyCustomStrategy : Strategy
        {
            #region Variables
            private string instruments = "";
    		private string[] instruemntsArray;
    		private Dictionary<string, double> bidDict = new Dictionary<string, double>();
    		private Dictionary<string, double> askDict = new Dictionary<string, double>();
    		private List<string> barDesc = new List<string>();
    		private DateTime currentTime = new DateTime();
            #endregion
    
            protected override void Initialize()
            {
                CalculateOnBarClose = true;
    			instruemntsArray = instruments.Split(',');
    			
    			foreach (string instr in instruemntsArray)
    			{
    				Add(instr, BarsPeriod.Id, 1, MarketDataType.Bid);
    				Add(instr, BarsPeriod.Id, 1, MarketDataType.Ask);
    				bidDict.Add(instr, 0);
    				askDict.Add(instr, 0);
    				barDesc.Add("Bid");
    				barDesc.Add("Ask");
    			}
            }
    
            protected override void OnBarUpdate()
            {
    			if (Historical) { return; }
    			
    			#region print out data if new timestamp
    			if (currentTime != Time[0])
    			{
    				string thisPrint = currentTime.ToString();
    				foreach (string instr in instruemntsArray)
    				{
    					thisPrint += "#" + bidDict[instr] + "#" + askDict[instr];
    				}
    				Print(thisPrint);
    				currentTime = Time[0];
    			}
    			#endregion
    			
    			#region assign new price
    			switch (barDesc[BarsInProgress])
    			{
    				case "Bid":
    					bidDict[Instrument.FullName] = Close[0];
    					break;
    				case "Ask":
    					askDict[Instrument.FullName] = Close[0];
    					break;
    				default:
    					break;
    			}
    			#endregion
            }
    
            #region Properties
            [Description("")]
            [GridCategory("Parameters")]
            public string Instruments
            {
                get { return instruments; }
                set { instruments =value; }
    		}
    		#endregion
    	}
    }

    #2
    Hello benoirat,

    Thanks for writing in.

    Instruments is an already existing class created by NinjaTrader as StrategyBase.Instruments. You will not be able to set this variable.

    I recommend you rename the variable in both the variables region and the properties region.


    Please let me know if this does not resolve your inquiry.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by andrewtrades, Today, 04:57 PM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by chbruno, Today, 04:10 PM
    0 responses
    3 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    436 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    7 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    19 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X