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

Multi Instrument Add() method crashes NT7

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

    Multi Instrument Add() method crashes NT7

    The following code crashes NT7.0.0.23. I believe the culprit is the 'Add()' method, because when I comment out that line, there is no crash. The code works fine after compilation. To get it to crash, open the indicators dialog, and replace the contents of the 'symbols' field with '6E, GC', then click Ok, upon hitting 'Ok' I get the crash message. The code is simple test code is below. The trace file contains the following:

    2010-12-24 15:30:49:926 ERROR: The indicator 'a1RolloverVolume' has called the Add() method with an invalid instrument. Either 'GC 03-11' does not exist in the Instrument Manager or the specified exchange has not been configured.
    2010-12-24 15:30:49:928 in OnUnhandledThreadException
    2010-12-24 15:30:49:933 ********* exception trapped *********
    2010-12-24 15:30:49:933 Index was outside the bounds of the array.
    2010-12-24 15:30:49:933 at NinjaTrader.Indicator.IndicatorBase.set_BarsArray( Bars[] value)
    at NinjaTrader.Gui.Chart.ChartIndicators.Apply()
    at NinjaTrader.Gui.Chart.ChartIndicators.OnOkButtonCl ick(Object sender, EventArgs e)
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    ------- The Indicator Code is below ------

    using System.Globalization; //### TryParse
    using System.Text.RegularExpressions; //### Regex

    #region Variables

    string str="", symbols = "6E, GC, CL, XXX", report="";

    Match m;
    int month=0, year=0;
    int i=0;

    #endregion

    protected override void Initialize() {
    Overlay = true;
    CalculateOnBarClose = true;

    try {
    //### Get all symbols to monitor
    Regex spaces = new Regex("\\s+"); symbols = spaces.Replace(symbols, " ");
    symbols = symbols.Trim();
    string[] split = symbols.Split(new char[] {','});
    i = 0;

    //### Default Expiry
    m = Regex.Match(Instrument.FullName, "(\\d+)-(\\d+)");
    if (m.Success) {
    Int32.TryParse(m.Groups[1].Value, out month);
    Int32.TryParse(m.Groups[2].Value, out year);
    }

    if ( String.IsNullOrEmpty(symbols) ) {
    report = "No symbols specified.";
    }
    else {
    foreach (string s in split) {
    if ( !String.IsNullOrEmpty(s) ) {
    str = s.Trim();
    //### Symbol
    string symbol="";
    m = Regex.Match(str, "^(.*?)(\\s|,|$)");
    if (m.Success) {
    symbol = m.Groups[1].Value +" " +month.ToString("00") + "-" +year.ToString("00");
    Print (" Adding: " +symbol);
    Add(symbol, PeriodType.Day, 1);
    }
    }
    }
    }
    } //try
    catch (Exception ex){
    Print("Exception: " + ex.Message);
    } //catch
    }

    protected override void OnBarUpdate(){
    }
    Last edited by monpere; 12-24-2010, 02:48 PM.

    #2
    You should initialize the Add(), like this...
    Code:
        protected override void Initialize() 
        { 
          //Initialize multi-Instrument, multi-timeframe BarsArray[] DataSeries...
          Add(PeriodType.Minute,60);
          my_60m_bar = 1;
          Add(PeriodType.Day,1);
          my_1d_bar = 2;
          Add("$COMPQ", PeriodType.Minute, 5);
          my_COMPQ_5m_bar = 3;
          Add("$COMPQ", PeriodType.Minute, 60);
          my_COMPQ_60m_bar = 4;
          Add("$COMPQ", PeriodType.Day, 1);
          my_COMPQ_60m_bar = 5;
     
          //Detect trade triggers intra-bar ...
          CalculateOnBarClose = false;
          //Set Stop Loss at -2%
          SetStopLoss(CalculationMode.Percent,0.02);
        }

    Comment


      #3
      Hello,

      If you replace the Add methods to be hard coded like what Borland suggested does this error go away? AS your using some unsupported NinjaScript code here.


      Let me know if I can be of further assistance.

      Comment


        #4
        Originally posted by NinjaTrader_Brett View Post
        Hello,

        If you replace the Add methods to be hard coded like what Borland suggested does this error go away? AS your using some unsupported NinjaScript code here.


        Let me know if I can be of further assistance.
        I am not using unsupported NT code, the affected line of code is the following:

        "Add(symbol, PeriodType.Day, 1)" where symbol is a "string" variable. Is that unsupported?

        Comment


          #5
          Hello,

          This is the part here:

          if ( String.IsNullOrEmpty(symbols) ) {
          report = "No symbols specified.";
          }
          else {
          foreach (string s in split) {
          if ( !String.IsNullOrEmpty(s) ) {
          str = s.Trim();
          //### Symbol
          string symbol="";
          m = Regex.Match(str, "^(.*?)(\\s|,|$)");
          if (m.Success) {
          symbol = m.Groups[1].Value +" " +month.ToString("00") + "-" +year.ToString("00");
          Print (" Adding: " +symbol);
          Add(symbol, PeriodType.Day, 1);


          Your dynamically changing the Initialize call with unsupported c# logic. If you take this out and manually specify the Add() do you still run into issue is the question here. If so then dynamic setting of the Add() symbol is the issue and you will need to look into this. Unfortunaley since this is unsupported I'm unable to offer any input here as the only supported method of doing this. To get the regex / dynamic setting here you would need to manually troubleshoot this.

          Let me know if I can be of further assistance.

          Comment


            #6
            Originally posted by NinjaTrader_Brett View Post
            Hello,

            This is the part here:

            if ( String.IsNullOrEmpty(symbols) ) {
            report = "No symbols specified.";
            }
            else {
            foreach (string s in split) {
            if ( !String.IsNullOrEmpty(s) ) {
            str = s.Trim();
            //### Symbol
            string symbol="";
            m = Regex.Match(str, "^(.*?)(\\s|,|$)");
            if (m.Success) {
            symbol = m.Groups[1].Value +" " +month.ToString("00") + "-" +year.ToString("00");
            Print (" Adding: " +symbol);
            Add(symbol, PeriodType.Day, 1);


            Your dynamically changing the Initialize call with unsupported c# logic. If you take this out and manually specify the Add() do you still run into issue is the question here. If so then dynamic setting of the Add() symbol is the issue and you will need to look into this. Unfortunaley since this is unsupported I'm unable to offer any input here as the only supported method of doing this. To get the regex / dynamic setting here you would need to manually troubleshoot this.

            Let me know if I can be of further assistance.
            There's nothing wrong with the code, the error occurs as long as the instrument argument of the Add() method is a variable and not a constant. Once you go into the indicators dialog and change that variable to a significantly different size, the error occurs. This is an issue with the NT architecture. I suspect it is a memory allocation issue. I will leave it as a 'design feature' and figure out a different way to implement the code.

            Comment


              #7
              Monpere,

              All series must hard coded. This includes the instrument, interval type, and interval used. We do not support changing these through a variable or input. Since you're working with C#, there is a lot more you can do than is supported. We are unable to assist with issues that come up when using unsupported code techniques.
              Ryan M.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by FrazMann, Today, 11:21 AM
              2 responses
              6 views
              0 likes
              Last Post NinjaTrader_ChristopherJ  
              Started by rjbtrade1, 11-30-2023, 04:38 PM
              2 responses
              80 views
              0 likes
              Last Post DavidHP
              by DavidHP
               
              Started by Spiderbird, Today, 12:15 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_ChristopherJ  
              Started by lorem, Yesterday, 09:18 AM
              5 responses
              18 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by cmtjoancolmenero, Yesterday, 03:58 PM
              12 responses
              42 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X