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 using Instrument.MasterInstrument.Name

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

    error using Instrument.MasterInstrument.Name

    Need some help...thank you...

    I am getting this error:

    'string' does not contain a definition for 'MasterInstrument' and no extension method 'MasterInstrument' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

    with this code

    #region Variables
    // parameters
    private bool draw = false;

    // user variables
    private bool FirstTime = true;
    private string ThisAlert;

    private string Instrument;
    private string Interval;
    private string Period;

    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    }


    /// <summary>
    /// OnBarUpdate
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (FirstTime)
    {
    FirstTime = false;
    Instrument = Instrument.MasterInstrument.Name;
    Interval = BarsPeriod.Id.ToString();
    Period = BarsPeriod.Value.ToString();

    ThisAlert =
    Instrument.MasterInstrument.Name
    + "."
    + BarsPeriod.Id.ToString()
    + "."
    + BarsPeriod.Value.ToString();

    Print (ThisAlert);
    }
    }

    #2
    Hello Turtle Trader,
    There is already a native object named Instrument in the class. Please change the code as highlighted in red to
    Code:
    private string[B][COLOR="Green"] i[/COLOR][/B]nstrumentName;
    Code:
    [COLOR="green"][B]i[/B][/COLOR]nstrumentName = Instrument.MasterInstrument.Name;

    Code:
    #region Variables
            // parameters
            private bool        draw = false;
            
            // user variables
            private bool        FirstTime = true;
            private    string        ThisAlert;
            
            [COLOR="Red"]private string        Instrument;[/COLOR]
            private string        Interval;
            private string        Period;
            
            #endregion
            
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
            }
    
            
            /// <summary>
            /// OnBarUpdate
            /// </summary>
            protected override void OnBarUpdate()
            {
                if (FirstTime)
                {            
                    FirstTime = false;
                   [COLOR="red"] Instrument = Instrument.MasterInstrument.Name;[/COLOR]
                    Interval   = BarsPeriod.Id.ToString();
                    Period       = BarsPeriod.Value.ToString();
    
                    ThisAlert = 
                        Instrument.MasterInstrument.Name 
                        + "." 
                        + BarsPeriod.Id.ToString() 
                        + "." 
                        + BarsPeriod.Value.ToString();
                            
                    Print (ThisAlert);
                }
            }
    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Duh.....

      it is OK to laugh...

      :-)

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      3 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      238 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      384 views
      1 like
      Last Post Gavini
      by Gavini
       
      Started by oviejo, Today, 12:28 AM
      0 responses
      4 views
      0 likes
      Last Post oviejo
      by oviejo
       
      Started by pechtri, 06-22-2023, 02:31 AM
      10 responses
      125 views
      0 likes
      Last Post Leeroy_Jenkins  
      Working...
      X