Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsInProgress

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

    BarsInProgress

    Hi,
    I used the SampleMultiInstrument to build a strategy but it doesn't work (I get no trades).

    I added two instruments:
    Add("ES 03-09", PeriodType.Minute, 1);
    Add("NQ 03-09", PeriodType.Minute, 1);

    Then in OnBarUpdate() I used (I want to trade only the primary bar object, which in my case is SPY 1min)
    if (BarsInProgress != 0)
    return;

    Then I create my DataSeries (from the two added instruments) and so on (maybe it's here my mistake)?

    The the conditions, for instance:
    if (Signal1[0] < Low && Signal2[0] > 0.5)
    {
    EnterLong(DefaultQuantity, "Long");
    }

    (Signal1 and Signal2 are custom DataSeries generated in OnBarUpdate).

    What is wrong?

    Many thanks

    #2
    stefy,

    Would not know unless you provided more information as to what you think is wrong. What is the behavior you want? What is the behavior you are seeing? Also, if you feel you made the custom DataSeries wrong please post the code in relation to that. Thank you.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      protected override void Initialize()
      {

      Add("ES 03-09", PeriodType.Minute, 1);
      Add("NQ 03-09", PeriodType.Minute, 1);

      CalculateOnBarClose = true;

      fut1fut2 = new DataSeries(this);
      RSI_fut1fut2 = new DataSeries(this);
      Signal1 = new DataSeries(this);
      }

      protected override void OnBarUpdate()
      {
      fut1fut2.Set(BarsArray[1][0] - BarsArray[2][0]);
      RSI_fut1fut2.Set(RSI(fut1fut2, p)[0]);
      Signal1.Set(SMA(RSI_fut1fut2, p)[0]);

      if (BarsInProgress != 0)
      return;

      // Condition set 1
      if (RSI(p)[0] < Low && Signal1[0] > 0.5)
      {
      EnterLong(DefaultQuantity, "Long");
      }

      // Condition set 2
      if (RSI(p)[0] > High && Signal1[0] < -0.5)
      {
      EnterShort(DefaultQuantity, "Short");
      }

      // Condition set 3
      if (Position.MarketPosition == MarketPosition.Long
      && RSI(p)[0] > 0)
      {
      ExitLong("", "Long");
      }

      // Condition set 4
      if (Position.MarketPosition == MarketPosition.Short
      && RSI(p)[0] < 0)
      {
      ExitShort("", "Short");
      }
      }

      Behavior I'm seeing: no trades.
      Behavior I wish to see: trades!

      Comment


        #4
        fut1fut2.Set(BarsArray[1][0] - BarsArray[2][0]);

        You can't use BarsArray like that. You need to say what you want to look at. For instance, close prices would be: Closes[1][0] - Closes[2][0]. If you had an indicator then you could do something like: SMA(BarsArray[1], 10)[0]
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thank you, you're right, such a silly mistake.
          Nevertheless, I keep on getting no trades.

          Comment


            #6
            stefy,

            I am wondering how you got this code to compile.

            RSI(p)[0]

            RSI takes at least two parameters. http://www.ninjatrader-support.com/H...hIndexRSI.html
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by cmoran13, Yesterday, 01:02 PM
            0 responses
            29 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            21 views
            0 likes
            Last Post PaulMohn  
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            160 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            95 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            148 views
            2 likes
            Last Post CaptainJack  
            Working...
            X