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

Error account selection from indicator to strategy

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

    Error account selection from indicator to strategy

    Hello NinjaTrader Team,

    I am trying to incorporate an indicator into my strategy that copies orders from a master account to other accounts. I would like to be able to call this indicator from within the strategy and select the accounts.

    I have attempted to implement this in various ways, but I always encounter the same error: "Error on getting value for property for NinjaScript: Object reference not set to an instance of an object."





    I want to be able to access the properties of the indicator from my strategy and select the master account and the other accounts to copy (up to 9 accounts). I believe the issue stems from the null reference of the indicator, which is causing the error since initially no account is selected.

    Click image for larger version

Name:	image.png
Views:	33
Size:	59.7 KB
ID:	1304911


    Is there any way to resolve this error?



    i attach the indicator, also here the code I made:


    Code:
    public class PRUEBAS : Strategy
        {
            
    
            #region Indicators
    
            private NinjaTrader.NinjaScript.Indicators.TRADINGNASDAQ.SimpleTradeCopier ReplicatorTN1;
            
            #endregion
    
            
            protected override void OnStateChange()
            {
    
                if (State == State.SetDefaults)
                {
                    ****CODE****
                    
                }
                        
                #region Configure Indicators
                
                else if (State == State.Configure)
                {
                    ****CODE****
                }
                
                else if (State == State.DataLoaded)
                {                                
                   ****CODE****
                }
                
            protected override void OnBarUpdate()
            {
                Cuenta_Master = SimpleTradeCopier.MasterAccount_name;
                Cuenta_1 = SimpleTradeCopier.Accountname_1;
                Cuenta_2 = SimpleTradeCopier.Accountname_2;
                Cuenta_3 = SimpleTradeCopier.Accountname_3;
                Cuenta_4 = SimpleTradeCopier.Accountname_4;
                Cuenta_5 = SimpleTradeCopier.Accountname_5;
                Cuenta_6 = SimpleTradeCopier.Accountname_6;
                Cuenta_7 = SimpleTradeCopier.Accountname_7;
                Cuenta_8 = SimpleTradeCopier.Accountname_8;
                Cuenta_9 = SimpleTradeCopier.Accountname_9;
                
    
    
    
            }
            
            #region Properties
    
    
            #region 10. Replicator / Replicadora
            
            [RefreshProperties(RefreshProperties.All)]
            [Display(Name="Active Replicator / Activar Replicadora", Description="Determine if Replicator is active / Determina si Replicadora está activo.", Order=1, GroupName="10. Replicator / Replicadora")]
            public bool Replicator
            { get; set; }
            
            [NinjaScriptProperty]
            [Display(Name="Copy from this Account ",                                 Order=2, GroupName="10. Replicator / Replicadora")]
            [TypeConverter(typeof(NinjaTrader.NinjaScript.AccountNameConverter))]
            public string Cuenta_Master { get; set; }
            
            [NinjaScriptProperty]
            [Display(Name="To Account 1",                                             Order=3, GroupName="10. Replicator / Replicadora")]
            [TypeConverter(typeof(NinjaTrader.NinjaScript.AccountNameConverter))]
            public string Cuenta_1 { get; set; }
            
            [NinjaScriptProperty]
            [Display(Name="To Account 2",                                             Order=4,  GroupName="10. Replicator / Replicadora")]
            [TypeConverter(typeof(NinjaTrader.NinjaScript.AccountNameConverter))]
            public string Cuenta_2 { get; set; }
            
            [NinjaScriptProperty]
            [Display(Name="To Account 3",                                             Order=5,  GroupName="10. Replicator / Replicadora")]
            [TypeConverter(typeof(NinjaTrader.NinjaScript.AccountNameConverter))]
            public string Cuenta_3 { get; set; }
            
            [NinjaScriptProperty]
            [Display(Name="To Account 4",                                             Order=6,  GroupName="10. Replicator / Replicadora")]
            [TypeConverter(typeof(NinjaTrader.NinjaScript.AccountNameConverter))]
            public string Cuenta_4 { get; set; }
            
            [NinjaScriptProperty]
            [Display(Name="To Account 5",                                             Order=7,  GroupName="10. Replicator / Replicadora")]
            [TypeConverter(typeof(NinjaTrader.NinjaScript.AccountNameConverter))]
            public string Cuenta_5 { get; set; }
            
            [NinjaScriptProperty]
            [Display(Name="To Account 6",                                             Order=8,  GroupName="10. Replicator / Replicadora")]
            [TypeConverter(typeof(NinjaTrader.NinjaScript.AccountNameConverter))]
            public string Cuenta_6 { get; set; }
            
            [NinjaScriptProperty]
            [Display(Name="To Account 7",                                             Order=9,  GroupName="10. Replicator / Replicadora")]
            [TypeConverter(typeof(NinjaTrader.NinjaScript.AccountNameConverter))]
            public string Cuenta_7 { get; set; }
            
            [NinjaScriptProperty]
            [Display(Name="To Account 8",                                             Order=10,  GroupName="10. Replicator / Replicadora")]
            [TypeConverter(typeof(NinjaTrader.NinjaScript.AccountNameConverter))]
            public string Cuenta_8 { get; set; }
            
            [NinjaScriptProperty]
            [Display(Name="To Account 9",                                             Order=11,  GroupName="10. Replicator / Replicadora")]
            [TypeConverter(typeof(NinjaTrader.NinjaScript.AccountNameConverter))]
            public string Cuenta_9 { get; set; }
    
            #endregion​

    #2
    Hello tradingnasdaqprueba,

    Thank you for your post.

    I believe the issue stems from the null reference of the indicator, which is causing the error since initially no account is selected.
    Can you confirm that these are the exact lines of code causing the object reference error by testing?

    You can confirm by commenting these lines out, then testing if you are still getting the error. Uncomment the lines, then see if the error returns.

    Checking for Null References - https://ninjatrader.com/support/help...references.htm
    Gaby V.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by sofortune, Today, 02:31 AM
    0 responses
    6 views
    0 likes
    Last Post sofortune  
    Started by sofortune, Today, 01:55 AM
    1 response
    5 views
    0 likes
    Last Post sofortune  
    Started by cls71, Today, 01:37 AM
    0 responses
    6 views
    0 likes
    Last Post cls71
    by cls71
     
    Started by WHICKED, 06-27-2023, 12:07 PM
    63 responses
    763 views
    1 like
    Last Post Leeroy_Jenkins  
    Started by rtwave, Today, 12:10 AM
    0 responses
    5 views
    0 likes
    Last Post rtwave
    by rtwave
     
    Working...
    X