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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            566 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            330 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            547 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            548 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X