Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi instrument sell and buy

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

    Multi instrument sell and buy

    Hallo,

    I have got a multi instrument strategy and the following code snippet:

    protected override void OnBarUpdate()
    {
    // Is this necessary to verify the instrument 1 and 2??
    if (BarsInProgress == 0)
    {
    double beta = SpreadPlot2(10,1,10,Symbol2).Beta;
    double betage = Math.Round(beta,2);
    double factor = betage*10;
    int factorint = Convert.ToInt32(factor);
    // Condition 1
    if (CrossBelow(SpreadPlot2(10, 1, 10, Symbol2).Value, Variable0, 1))
    {
    string ausgabe = string.Format("Beta = {0}",beta);
    Print(ausgabe);
    Print(factorint);
    // EnterLong(int barsInProgressIndex, int quantity, string signalName) e.g. EnterLong(0, 100, "BUY MSFT");
    // Sell 10 x instrument 1
    EnterShort(0,10,"SELL $NZDUSD");
    // Buy factorint x instrument 2
    EnterLong(1,factorint, "Buy $USDCAD");
    }
    // Condition 2
    else if (CrossAbove(SpreadPlot2(10, 1, 10, Symbol2).Value, Variable1, 1))
    {
    Print("CrossAbove -2");
    EnterLong(0,10,"BUY $NZDUSD");
    EnterShort(1,factorint, "Sell $USDCAD");

    }
    }
    }

    There happens nothing but the following error occurs:

    **NT** Error on calling 'OnBarUpdate' method for strategy 'Residual/': 'EnterLong': 'barsInProgressIndex' parameter out of valid range 0 to 0, was 1

    What I have to change?
    Thank you in advance for your effort.
    Best regards
    Benjamin

    #2
    bascher,

    Could you also post your "Initialize()" section here? It would be helpful so I can assist you further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      My "Initialize()" section:

      protected override void Initialize()
      {
      SpreadPlot2(10, 1, 10, Symbol2).Plots[0].Pen.Color = Color.Green;
      Add(SpreadPlot2(10, 1, 10,Symbol2));
      CalculateOnBarClose = true;
      }

      Comment


        #4
        bascher,

        You aren't adding a second series here so OnBarUpdate() will not be called with a BarsInProgress index other than 0. You would need to add the second series you are trading in order for this strategy to work.

        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Hallo Adam,

          thank you for your advise. The problem now is that in the output window occur an additional value. I don´t know where it comes from and what it are representing.
          I only wrote:

          Add(Symbol2, PeriodType.Minute, 1);

          where Symbol2 is a property in the follwing way:

          [Description("Symbol 2")]
          [GridCategory("Parameters")]
          // Force this parameter to be displayed first
          [Gui.Design.DisplayName("\tSymbol 2")]
          public string Symbol2
          {
          get
          {
          if ((symbol2 == "") && (ChartControl != null) && (Instruments != null))
          for (int i = 0; i < ChartControl.BarsArray.Length; i++)
          if (ChartControl.BarsArray[i].Instrument.FullName != Instruments[0].FullName)
          {
          symbol2 = ChartControl.BarsArray[i].Instrument.FullName;
          break;
          }
          return symbol2;
          }
          set { symbol2 = value.ToUpper(); }
          }

          Without the add statement everything works.

          Any hints?
          Thank you in advance.
          Benjamin

          Comment


            #6
            Hello,

            Thanks for your patience while I reviewed.

            Unfortunately dynamic properties are not supported and I really do not have a hint for you here.

            -Brett
            BrettNinjaTrader Product Management

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, Yesterday, 10:06 AM
            0 responses
            17 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            16 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            14 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            9 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            38 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X