Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PriorOHLC has a problem with bars ago

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

    PriorOHLC has a problem with bars ago

    Hello programmmers,

    in using the PriorOHLC indicator I am having a problem:

    With (CrossAbove(Close, PriorDayOHLC1.PriorHigh, 3)) the strategy should use the crossover three bars ago - but the result is the same as using (CrossAbove(Close, PriorDayOHLC1.PriorHigh, 1)).

    I tried (CrossAbove(Close[3], PriorDayOHLC1.PriorHigh, 1)), but bar indexes are in this situation do not work, too.

    Is there a special trick or do I having a bug in my system?

    Thank you!

    Best regards,
    Rainbowtrader

    #2
    Hello Rainbowtrader,

    Thanks for your post.

    The PriorDayOHLC indicator returns the prior day's Open, High, Low, and Close prices.

    CrossAbove() conditions detect when a cross above condition occurs over the specified bar look-back period. Note that a look-back period is not the same as bars ago. A look-back period checks if a condition occurs within 'x' number of bars, where 'x' is the look-back period.

    See this help guide page for more information about CrossAbove(): https://ninjatrader.com/support/help...crossabove.htm

    The condition (CrossAbove(Close, PriorDayOHLC1.PriorHigh, 3)) would check if the Close price crosses above the PriorDayOHLC.PriorHigh plot value within the last 3 bars. If the close price had crossed above the PriorDayOHLC.PriorHigh plot value within the last 3 bars then this condition would be true.

    The condition (CrossAbove(Close, PriorDayOHLC1.PriorHigh, 1)). would check if the Close price crosses above the PriorDayOHLC.PriorHigh plot value within the last 1 bar. If the close price had crossed above the PriorDayOHLC.PriorHigh plot value within the last 1 bar then this condition would be true.

    Add prints to the strategy one line above the condition to understand how the logic is evaluating.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    <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
      Hi Brandon,

      thank you for your explainings - I have now understooden, how the parameter works in this.

      If my entry signal is not the close after the cross, rather after the next candle, that is closing higher as the cross-close: how can I solve this? I need a possibility to count backwards. Another possibility would be to work with the current high, but this is not the same. Have you got an idea or a solution for this problem?

      Best regards,
      Rainbowtrader

      Comment


        #4
        Hello Rainbowtrader,

        Thanks for your notes.

        I am not sure I fully understand the condition that you have mentioned.

        Please provide me with an example of what exactly you are trying to accomplish so that I may accurately assist.

        Are you trying to detect if the previous bar's Close price is greater than the previous bar's PriorDayOHLC.PriorHigh plot value and also check if the current Close price is greater than the PriorDayOHLC.PriorHigh plot value?
        <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
          Good morning Brandon,

          thank you for your help.

          Code:
                       // set 1
                      if ((CrossAbove(Close, PriorDayOHLC1.PriorHigh, 1))
                           && (Close[0] > Close[1])
                           && (Close[1] > Close[2]))
                      {
                          EnterLong(Convert.ToInt32(DefaultQuantity), "");
                      }​
          Click image for larger version  Name:	example_prior_ohlc.png Views:	0 Size:	9.6 KB ID:	1269642

          You can see in this picture, that the first green bar, that crosses the prior high, gave the signal ("Kauf" means "Enter long"). That is, what normaly is wished by the most users. And the code for this is okay, too.

          But what I want, is, that the trade is starting one bar later - after the close of the next bar, that is going in the same direction, whose close is higher as the close from the signal bar. So this "waiting bar" has the function of a "confirmation candle". In other words: entry long only, if the confirmation bar closes higher as the signal bar. If the confirmation bar closes lower, then stop the signal process. Then no entry possible. Only under this circumstances an entry is valid.

          Best regards,
          Rainbowtrader
          Last edited by Rainbowtrader; 09-20-2023, 01:12 AM.

          Comment


            #6
            Hello Rainbowtrader,

            Thanks for the clarification.

            If you want your strategy to wait one bar after the crossover occurs to place your trade, you could consider creating a class-level int variable called something like 'barOnCrossover', and in your condition save the CurrentBar to the barOnCrossover variable.

            Then, create a condition that checks if (CurrentBar == (barOnCrossover + 1)) and checks if Close[0] > Close[1] and call your Enter method within this condition.

            For example:

            Code:
            //class level variable
            private int barOnCrossover;
            
            //OnBarUpdate
            if ((CrossAbove(Close, PriorDayOHLC().PriorHigh, 1))
                 && (Close[0] > Close[1])
                && (Close[1] > Close[2]))
            {
                barOnCrossover = CurrentBar;
            }
            
            if ( (CurrentBar == (barOnCrossover + 1)) && Close[0] > Close[1])
            {
                EnterLong(Convert.ToInt32(DefaultQuantity), "LongEntry");
            }​
            Please 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


              #7
              Hello Brandon,

              thank you very much. I will test its.

              I am having a simple solution, that works, too:

              Code:
              if ((Close[0] > PriorDayOHLC1.PriorHigh[0])
                 && (Close[1] > PriorDayOHLC1.PriorHigh[0])
                 && (Close[2] < PriorDayOHLC1.PriorHigh[0]))
              Best regards,
              Rainbowtrader

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              50 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              126 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              69 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              42 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              46 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X