Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Recognizing additional DataSeries

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

    Recognizing additional DataSeries

    // Set 32
    if ((Position.MarketPosition == MarketPosition.Long)
    && (LongTrades == true)
    && (BarsInProgress == 0)
    && (CurrentBars[4] > 1)

    && (((TRAdjEMAD[1] > EMAD[1])
    && (TRAdjEMAD[0] < EMAD[0]))

    || (Closes[4][0] <= EMAD[0])

    || ((Closes[4][1] > TRAdjEMAD[1])
    && (Closes[4][0] < TRAdjEMAD[0])))

    && (Closes[4][0] < Opens[4][0]))

    {
    PerBarExitONEmade = true;
    ExitLong(Convert.ToInt32(Position.Quantity), @"ExitL TEM", @"Long6");
    ExitLong(Convert.ToInt32(Position.Quantity), @"ExitL TEM", @"Long7");
    }


    this is a part of strategy that has multiple data series, I cannot get this part to trigger the exits

    I am sure the issue is with BarsinProgress , CurrentBars[4] or something else to do with needing to recognize that the set needs to be reading DataSeries[4] ie Closes[4]
    The indicators used in the condition set are created using Closes[4] as well

    TRAdjEMAD[0]
    EMAD[0]

    as shown below

    TRAdjEMAD = TRAdjEMA(Closes[4], 20, 20, 5);
    EMAD = EMA(Closes[4], 20);


    ************************************************** *****

    any help appreciated

    #2
    Hello DTSSTS,

    Thanks for your post.

    I do not see anything specific in the code you shared that would prevent the Exit methods from firing.

    Generally, if the Exit methods are not being placed then the condition to place those orders are not becoming true.

    Have you added prints to the script that print out each value in the condition that is used to place the Exit orders?

    If not, please add prints to the strategy that print out each value used in your condition to place the Exit orders to see exactly how the script is evaluating and to see if all the conditions to place the orders are becoming true.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Also, enable TraceOrders which will let you know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.

    https://ninjatrader.com/support/foru...121#post791121

    You could view this help guide page to get a good understanding about working with Multi-Timeframe/Multi-Instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.htm

    Let us know if we may assist further.​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      I think I do not have the BarsInProgress and CurrentBars coded correctly in the upper part of the code, I have never quit understood how this should be, if I am trigger my entries with the 4th dataseries as I have the code, then I would think I could trigger my exits, even though they show in my backtesting to be functioning they are not in live trading


      protected override void OnBarUpdate()
      {



      if(BarsInProgress == 0)
      {

      }

      if(BarsInProgress == 1)
      {

      }

      if(BarsInProgress == 2)
      {

      }

      if(BarsInProgress == 3)
      {

      }


      if(BarsInProgress == 4)
      {

      }


      if (CurrentBars[0] < 30
      || CurrentBars[1] < 5
      || CurrentBars[2] < 5
      || CurrentBars[3] < 5
      || CurrentBars[4] < 5)

      return;​


      I know what I have is likely not correct format, but a few years ago when I added the code this was the entries functioned as desired, but the exits only really work as expected on the Primary Dataseries

      thanks

      Comment


        #4
        Hello DTSSTS,

        Thanks for your note.

        The CurrentBars conditions should be added to the top of your OnBarUpdate() logic before any BarsInProgress conditions. This allows the script to ensure there are enough bars processing for each data series added to the script before performing actions on those added series.

        See this help guide page for more information about CurrentBars: https://ninjatrader.com/support/help...urrentbars.htm

        And, see this help guide page about making sure you have enough bars in the data series you are accessing: https://ninjatrader.com/support/help...nough_bars.htm

        Ultimately, to understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

        In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

        Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.

        https://ninjatrader.com/support/foru...121#post791121​​

        Please let me know if I may assist you further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          OK now I have this

          protected override void OnBarUpdate()
          {



          if (CurrentBars[0] < 30
          || CurrentBars[1] < 5
          || CurrentBars[2] < 5
          || CurrentBars[3] < 5
          || CurrentBars[4] < 5)

          return;​​


          if(BarsInProgress == 0)
          {

          }

          if(BarsInProgress == 1)
          {

          }

          if(BarsInProgress == 2)
          {

          }

          if(BarsInProgress == 3)
          {

          }


          if(BarsInProgress == 4)
          {

          }

          ​******************************************

          should i have another

          return;​

          below the BarsInProgress

          my backtest with Stategy Analyzer tested with same results, I have began live testing again not

          Thanks for the help

          Comment


            #6
            Hello DTSSTS,

            Thanks for your note.

            You should not need to add another return; statement at the end of the script.

            Based on the code you shared in post # 5 I do not see where you are calling any Exit methods. This simply checks if the primary series has at least 30 bars processing and if the added series have at least 5 bars processing before calculating logic. Then, you have a BarsInProgress check for the primary series and added series but no code within those added series. There is not much else I could further advise on based on this code.

            Generally, if a script is not placing trades as expected it is because the condition to place those trades is not becoming true.

            If the strategy is not placing orders as expected when running the script on realtime data you would need to add prints to the script on the line(s) above the condition that print out each value being used in each condition that places Exit orders to see how exactly the logic for that condition is evaluating. You should also add a print inside the condition to confirm if the logic is being fired when the condition becomes true.

            A simple example of using prints would be something like this:

            Print("Close[0] > Open[0]: " + (Close[0] > Open[0]) + " | BarsInProgress index: " + BarsInProgress + " | CurrentBar: " + CurrentBar + " | Time: " + Time[0]);
            if (Close[0] > Open[0] && BarsInProgress == 0)
            {
            EnterLong();
            Print("Condition to place EnterLong order is true.");
            }


            Below is a link to a forum post that demonstrates how to use prints to understand behavior.

            https://ninjatrader.com/support/foru...121#post791121

            If you are referring to the Exit orders you mentioned in post # 1, you would need to add prints to the script that print out each value used in that condition to place those Exit orders to see how the conditions are evaluating.

            Let me know if I may assist further.​
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              I confused about one item you stated above

              YOU STATED

              The CurrentBars conditions should be added to the top of your OnBarUpdate() logic before any BarsInProgress conditions. This allows the script to ensure there are enough bars processing for each data series added to the script before performing actions on those added series.

              ABOVE CurrentBars should be at the top, But below is a Strategy created by the Strategy builder and Never unlocked and the CurrentBars are listed after the BarsInProgress statement

              SO does that mean that my strategy will not perform correctly?

              Also when using Strategy Builder, is the away to state BarsInProgress in condtion sets?

              BELOW is from view code of using Strategy Builder created Strategy
              Thanks

              protected override void OnBarUpdate()
              {
              if (BarsInProgress != 0)
              return;

              // Set 1
              if (BarsSinceExitExecution(0, "", 0) > 0)
              {
              PerBarExitONEmade = false;
              }

              // Set 2
              if (
              // Per Bar Trade ONE Reset from Entry
              ((PerBarTradeONEmade == true)
              && (BarsSinceEntryExecution(0, "", 0) == 1))
              // Per Bar Trade ONE Reset from Exit
              || ((PerBarTradeONEmade == true)
              && (BarsSinceExitExecution(0, "", 0) > 0)))
              {
              PerBarTradeONEmade = false;
              }

              if (CurrentBars[0] < 3
              || CurrentBars[1] < 5)
              return;

              Comment


                #8
                Hello DTSSTS,

                Thanks for your note.

                "But below is a Strategy created by the Strategy builder and Never unlocked and the CurrentBars are listed after the BarsInProgress statement

                SO does that mean that my strategy will not perform correctly?

                Also when using Strategy Builder, is the away to state BarsInProgress in condtion sets?"

                The Strategy Builder adds BarsInProgress != 0 at the top of the script to check that the BarsInProgress value processing is the primary data series. If the BarsInProgress value is not the primary series (BarsInProgress 0) the script calls return. This is because you cannot use added series BarsInProgress conditions in a Strategy Builder strategy.

                Added series BarsInProgress conditions could only be defined in an unlocked strategy.

                In a multi-instrument/multi-timeframe strategy, the CurrentBars condition checks should be added to the top of the OnBarUpdate() logic to make sure that each added series in the script has enough bars processed before the strategy calculates logic in each BarsInProgress condition.

                See the help guide documentation below demonstrating this concept for multi-timeframe/multi-instrument NinjaScripts.

                True Event Driven OnBarUpdate() method: https://ninjatrader.com/support/help...arupdateMethod
                Accessing Price Data in a Multi-Bars NinjaScript:https://ninjatrader.com/support/help...arsninjascript
                Entering, Exiting, and Retrieving Position Information: https://ninjatrader.com/support/help...ionInformation

                It is important to thoroughly review this help guide page to fully understand how Multi-TimeFrame/Multi-Instrument NinjaScripts function: https://ninjatrader.com/support/help...nstruments.htm

                Please let me know if I may assist further.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment


                  #9
                  In a multi-instrument/multi-timeframe strategy, the CurrentBars condition checks should be added to the top of the OnBarUpdate() logic to make sure that each added series in the script has enough bars processed before the strategy calculates logic in each BarsInProgress condition.

                  So the strategy builder puts the CurrentBars in the incorrect place in the Locked Code, so if you unlock the code you need to move the CurrentBars above the BarsinProgress ??

                  Comment


                    #10
                    Hello DTSSTS,

                    Thanks for your note.

                    After unlocking the script from the Strategy Builder you should remove the 'if (BarsInProgress != 0) return;' code and add the CurrentBars condition check at the top of OnBarUpdate() when referencing additional series BarsInProgress values in an unlocked multi-timeframe/multi-instrument NinjaScript strategy.

                    The example code seen in the help guide documentation linked in post # 8 demonstrates how CurrentBars and BarsInProgress should be used in a multi-timeframe/multi-instrument NinjaScript.

                    Please let me know if I may assist further.​
                    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    55 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    132 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    73 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    45 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    49 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X