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 charlesugo_1, 05-26-2026, 05:03 PM
            0 responses
            60 views
            0 likes
            Last Post charlesugo_1  
            Started by DannyP96, 05-18-2026, 02:38 PM
            1 response
            147 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            161 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 05-10-2026, 08:12 PM
            0 responses
            97 views
            0 likes
            Last Post CarlTrading  
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            284 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Working...
            X