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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    65 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    139 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X