Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Barsinprogress issue

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

    Barsinprogress issue

    hi I want to make sure i am setting up barsinprogress correctly. Currently strategy opens trades in strategy analyzer but not in market replay. I have the following. In my onBarUpate i include barsinrpogress and have all my logic in there. I musht be doing something wrong. What can i do to have strategy work in both strategy analyzer and market replay. I am not doing anything with 1 tick its only for backtesting accuracy

    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Tick, 1);

    }​

    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 0)
    {​
    if (CurrentBars[0] < 10 && CurrentBars[1] < 10)
    return;​

    double atrvalue = atrIndicator[0];

    if (longsOn)
    {
    double ask = GetCurrentAsk();
    double bid = GetCurrentBid();
    if( TrendTradeLong && TrendTrade
    && (Position.MarketPosition == MarketPosition.Flat)
    {
    EnterLong(PositionSize, "TFL");
    }
    } // closing of barsinprogress​
    Last edited by tkaboris; 07-11-2023, 11:01 AM.

    #2
    Hello tkaboris,

    From the given code I cant see what the problem may be. You are executing that code for the primary series, if you tested a 10 minute chart in the backtest you should also be testing a 10 minute chart in playback. The 1 tick series shown is not used in the code provided.
    Last edited by NinjaTrader_Jesse; 07-11-2023, 11:18 AM.

    Comment


      #3
      ok.

      if i want to have two BarsInProgress where I would want to compare the condition from larger timeframe. Would syntax be like this then? In other words whole logic needs to be rewritten for different barsinprogress?

      else if (State == State.Configure)
      {
      AddDataSeries(Data.BarsPeriodType.Tick, 1);
      AddDataSeries(Data.BarsPeriodType.Tick, 1000);
      }​

      protected override void OnBarUpdate()
      {
      if (BarsInProgress == 0)
      {​
      if (CurrentBars[0] < 10 && CurrentBars[1] < 10)
      return;​

      double atrvalue = atrIndicator[0];

      if (longsOn)
      {
      double ask = GetCurrentAsk();
      double bid = GetCurrentBid();
      if( TrendTradeLong && TrendTrade
      && (Position.MarketPosition == MarketPosition.Flat)
      {
      EnterLong(PositionSize, "TFL");
      }
      } // closing of barsinprogress​

      if (BarsInProgress == 2)
      {​
      if (CurrentBars[0] < 10 && CurrentBars[1] < 10)
      return;​

      double atrvalue = atrIndicator[0];

      if (longsOn)
      {
      double ask = GetCurrentAsk();
      double bid = GetCurrentBid();
      if( TrendTradeLong && TrendTrade
      && (Position.MarketPosition == MarketPosition.Flat)
      {
      EnterLong(PositionSize, "TFL");
      }
      } // closing of barsinprogress​​​

      Comment


        #4
        Hello tkaboris,

        Yes you would have two if conditions checking BarsInProgress if you wanted to have a separate set of logic executed for the secondary series.

        Comment


          #5
          I have some indicators loaded and I want to make sure values from EMAs are on the chaart to avoid out of index array error. Is this the right way to code in onBarUpdate?
          else if (State == State.DataLoaded)
          {
          ClearOutputWindow(); //Clears Output window every time strategy is enabled
          fastEMASF = EMA(fastEMAPeriodSF);
          slowEMASF = EMA(slowEMAPeriodSF);
          fastEMASF.Plots[0].Brush = Brushes.Blue;
          slowEMASF.Plots[0].Brush = Brushes.DarkOrange;
          AddChartIndicator(fastEMASF);
          AddChartIndicator(slowEMASF);

          }

          protected override void OnBarUpdate()
          {
          if (BarsInProgress == 0)
          {
          if (CurrentBars[0] < 10 && CurrentBars[1] < 10)
          return;

          if (CurrentBars[0] < fastEMASF[1] || CurrentBars[1] < slowEMASF[1])
          return;​​

          Comment


            #6
            Hello tkaboris,

            The following condition is not needed, you are comparing an indicator price against a bar index which is not a valid comparison.

            Code:
            if (CurrentBars[0] < fastEMASF[1] || CurrentBars[1] < slowEMASF[1])
            return;​​
            You only need the following condition for each series you add and use data from:

            Code:
            if (CurrentBars[0] < 10 && CurrentBars[1] < 10)
            return;
            if you have the following series:
            Code:
            AddDataSeries(Data.BarsPeriodType.Tick, 1);
            AddDataSeries(Data.BarsPeriodType.Tick, 1000);​
            It should look like this if all series should have at least 10 bars:

            Code:
            if (CurrentBars[0] < 10 || CurrentBars[1] < 10 || CurrentBars[2] < 10)
            return;

            ​​​

            Comment


              #7
              Hi I am referencing (BullOrBear[0] == 1) && (BullOrBear[1] == 0 ) in my primary series as my main condition.
              if i print Print(BullOrBear(BarsArray[1])[0]); it cant find it.

              In my strategy i simply included indicator inside the strategy code but now i want to reference BullOrBear Value from larger timeframe. How do i need to do it?




              region Stoch Logics here

              //Define Bullish Reversal Pattern

              if (
              ((EMASFFilter) ? (fastEMASF[0] > slowEMASF[0] && fastEMASF[0] > fastEMASF[1]) : Close[0] > 0)
              && (BullOrBear[0] == 0) && (BullOrBear[1] == 1 )
              // && (Close[1] > Open[1]))
              )

              {
              TrendTradeLong = true;


              }
              else
              {
              TrendTradeLong = false;
              }



              }


              #endregion​


              Attached Files

              Comment


                #8
                Hello tkaboris,

                I would suggest using the strategy builder to generate the code if you are not sure what it should look like.

                In the builder add the additional series you wanted to use
                In a set add a condition which uses the indicator, make sure to select the secondary series as the indicators series.
                Click View code

                That will generate the code and input parameters so you can copy/paste it into your other script.

                Your script would need the AddDataSeries statement for the secondary series and then the generated code and variables for the indicator.

                Comment


                  #9
                  Can i execute bars ingprogress insde another barsinprogress?

                  if (BarsInProgress == 0)
                  {
                  main code
                  and ..
                  if (BarsInProgress == 2)
                  { logic}
                  }

                  Comment


                    #10
                    Hello tkaboris,

                    No, that needs to be inside OnBarUpdate as the parent. Only 1 bars in progress can call OnBarUpdate at a time.

                    Comment


                      #11
                      Hi i couldnt figure out the excact logic usiing strategy builder although it was helpful.
                      I need to execute on main barsinprogress0 and i have a filter, that if selected uses condition from barsinprogress2. So i enter long when line turns green on primary and when line is green on secondary

                      Usually my main logic when used only on one barsinprogress goes like this, where HigherTimeFrame if selected acts as a filter. So
                      if (
                      ((TrendMagicModified1.BullOrBear[1] == 0) && (TrendMagicModified1.BullOrBear[2] == 1))
                      && ((HigherTimeFrame) ? (TrendMagicModified2.BullOrBear[1] == 0) : Close[0] > 0)
                      )

                      {
                      TrendTradeLong = true;
                      }
                      EnterLong();​

                      Can you help me to code the structure below

                      if (BarsInProgress == 0)
                      {

                      if (
                      ((TrendMagicModified1.BullOrBear[1] == 0) && (TrendMagicModified1.BullOrBear[2] == 1))
                      && ((HigherTimeFrame) ? (TrendMagicModified2.BullOrBear[1] == 0) : Close[0] > 0) // DO I NEED THIS LINE IN MAIN SERIES?
                      )

                      {
                      TrendTradeLong = true;
                      }

                      {

                      EnterLong(1, 1, "Long: ");
                      }

                      }

                      else if (BarsInProgress == 2)
                      {
                      WHAT DO I PUT HERE FOR A FILTER? DO I NEED TO ENTER LONG(); DO I NEED THE WHOLE ENTRY CONDITION OR JUST
                      ((HigherTimeFrame) ? (TrendMagicModified2.BullOrBear[1] == 0) : Close[0] > 0)
                      }​

                      Thank you so much

                      Comment


                        #12
                        Hello tkaboris,

                        You would need to put whatever conditions you wanted to check during BarsInProgress 2 in the area you marked. You can add price conditions or other logic like order entry.

                        Comment


                          #13
                          hi, i am confused because how do i describe a condition without a statement after that in secondary series. I only need to check if lilne is green on secondary series. If its true then what? do I need a bool for that?
                          I just need to verify that if HigherTimeFrame is selected then highertimeframe series line is equals to1...


                          if (BarsInProgress == 0)
                          {

                          if (
                          ((TrendMagicModified1.BullOrBear[1] == 0) && (TrendMagicModified1.BullOrBear[2] == 1))
                          && ((HigherTimeFrame) ? (TrendMagicModified2.BullOrBear[1] == 0) : Close[0] > 0) // Do i need this line in main series to reference condition in secondary series? not sure here
                          && ((HigherTimeFrame) ? (bool == true)
                          )
                          {
                          TrendTradeLong = true;
                          }
                          {
                          EnterLong(1, 1, "Long: ");
                          }
                          }
                          else if (BarsInProgress == 2)
                          {
                          if(TrendMagicModified1.BullOrBear[1] == 0)
                          bool = true; // is this would be the logic
                          }​

                          Comment


                            #14
                            Hello tkaboris,

                            The code you put inside bars in progress conditions are only executed when that specific series calls OnBarUpdate. To know where you code belongs would require knowing which series should be executing that code. If you need a condition executed by the primary that would go in BarsInProgress == 0. If you need code executed for a secondary series you would have separate BarsInProgress conditions for those series.

                            Depending on which series needs to execute the code would determine where you put your conditions. You may need to use a combination of conditions, for example you want to execute some code frequently and some code infrequently, the code would be split between the BarsInProgress conditions depending on when it needs executed. If you need to separate the code between BarsInProgress conditions then yes you would need to use variables if the other BarsInProgress condition needs to know something about the other series. ​

                            Comment


                              #15
                              I got this logic but strategy still opens order even though line is not matching on the highertimeframe series.

                              if(BarsInProgress == 0)
                              if (
                              ((EMASFFilter) ? (fastEMASF[0] > slowEMASF[0] && fastEMASF[0] > fastEMASF[1]) : Close[0] > 0)
                              && ((TrendMagicModified1.BullOrBear[1] == 0) && (TrendMagicModified1.BullOrBear[2] == 1))
                              && HTFBull == true

                              )

                              {
                              TrendTradeLong = true;

                              }
                              else
                              {
                              TrendTradeLong = false;
                              }

                              if (
                              ((EMASFFilter) ? (fastEMASF[0] < slowEMASF[0] && fastEMASF[0] < fastEMASF[1]) : Close[0] > 0)
                              && ((TrendMagicModified1.BullOrBear[1] == 1) && (TrendMagicModified1.BullOrBear[2] == 0))
                              && HTFBear == true
                              )

                              {
                              TrendTradeShort = true;

                              }
                              EnterLong();


                              else
                              {

                              TrendTradeShort = false;
                              }

                              }


                              else if(BarsInProgress == 2)
                              {

                              if ((HigherTimeFrame) && (TrendMagicModified2.BullOrBear[1] == 0))
                              {
                              HTFBull = true;
                              }
                              else
                              {
                              HTFBull = false;
                              }
                              if ((HigherTimeFrame) && (TrendMagicModified2.BullOrBear[1] == 1))
                              {
                              HTFBear = true;
                              }
                              else
                              {
                              HTFBear = false;
                              }

                              }​

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, 03-13-2026, 05:17 AM
                              0 responses
                              86 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              150 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              79 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              52 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              59 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X