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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    115 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    161 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    83 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    127 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    87 views
    0 likes
    Last Post PaulMohn  
    Working...
    X