Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

plot line curves as a stop out point

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

    plot line curves as a stop out point

    How could I add any plot line (for example an EMA line) to where if it curves back the wrong way, to stop out?
    Like if you are long and you see a upside down V (like ^) then get out.
    I've tried writing some code before based on slope and my code didnt work good.

    Like this:

    Click image for larger version

Name:	sssssssssssssssssssssss.png
Views:	185
Size:	22.7 KB
ID:	1198288

    #2
    Hello ezrollin,

    Thanks for your post.

    To check if a bar is an up bar you would create a condition that compares if the Close[0] price is greater than the Open[0] price.

    To check if a bar is a down bar you would create a condition that compares if the Close[0] price is less than the Open[0] price.

    You could consider, for example, checking if the last 3 bars go up and then down, you could create a condition that checks in the Close price 2 bars ago (Close[2]) is greater than the Open price 2 bars ago (Open[2]) and checks if the Close price 1 bar ago (Close[1]) is greater than the Open price 1 bar ago (Open[1]) and checks if the current Close price (Close[0]) is less than the current Open price (Open[0]). The code would look something like the code below.

    Code:
    if (Close[2] > Open[2] && Close[1] > Open[1] && Close[0] < Open[0])
    {
        //do something
    }
    The above example would determine if there are 2 up bars in a row and then a down bar, causing the candles to form a "^". The opposite would be done to determine if the candles form a "v".

    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
      Thats right.
      I'm sorry maybe I'm misunderstanding. I was asking in reference to a plot line, like an EMA.
      So shouldnt this be tied to an EMA so candle bars affect the EMA which is what we're actually trying to work with?
      Do I not have to do that? thanks!

      Comment


        #4
        Hello ezrollin,

        Thanks for your note.

        To clarify, are you wanting to detect if the current market price is greater than/less than an EMA indicator?

        If so, you could create a condition in your script that checks if the Close price (Close[0]) is greater than/less than say EMA(20).

        This condition could be set up in the Conditions and Actions section of the Strategy Builder. Then, you could click the 'View code' button to see the generated syntax to accomplish this.

        See this help guide for more information: https://ninjatrader.com/support/help...on_builder.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


          #5
          Click image for larger version

Name:	adx.png
Views:	159
Size:	30.0 KB
ID:	1207204
          Code:
          Data.Loaded:
          ADX1 = ADX(Close, 14);
          ADX2 = ADX(Open, 14);
          
          // Set 7
          if ((ADX1[2] > ADX2[2])
          && (ADX1[1] > ADX2[1])
          && (ADX1[0] < ADX2[0]))
          {
          BackBrush = Brushes.CornflowerBlue;
          }

          So I gave up on that idea.
          Now I'm back at it again.
          I'm trying to see if I can paint a vertical line when the ADX turns into a ^ looking plot line.
          Does this make sense? Is it even possible? thanks

          Click image for larger version

Name:	adx.png
Views:	97
Size:	12.0 KB
ID:	1207205

          Comment


            #6
            Hello ezrollin,

            Thanks for your note.

            You would need to create a condition that checks if the ADX value 2 bars ago is Less than the ADX value 1 bar ago, and check if the ADX value 1 bar ago is Greater than the ADX value 0 bars ago. Then, call BackBruses[] with a bars ago value of 1 to color that background at the peak of the ADX.

            By checking if ADX 2 bars ago is Less than ADX 1 bars ago and if ADX 1 bars ago is Greater than ADX 0 bars ago, the ADX 1 bar ago value would be the 'peak' ('^'). So to change the color of that peak, you would need to use BackBrushes[1].

            Note that you would need to unlock your script from the Strategy Builder to use BackBrushes[1] as it is not available to use in the Builder.

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

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

            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
              Im getting some false positives but it does work!
              Is there a way to make it less sensitive? Maybe an offset?

              I dont understand how stuff is supposed to work in real time but it will only paint a brush in the future which is also the past?
              I guess because it needs the ^ condition to complete(in the past) and be confirmed with a new bar? thanks

              Comment


                #8
                Hello ezrollin,

                Thanks for your note.

                Yes, that is correct. Since you are looking for a peak to occur, you would need to check if this occurs historically by checking the ADX values for the previous 3 bars.

                First you determine if the ADX is up by checking if the value 2 bars ago is less than the value 1 bar ago. Then you determine if the ADX is down by checking if the value 1 bar ago is greater than the value of the current bar (0 bars ago). When these are true, it means a peak has formed.

                As for your question regarding adding an offset, this would ultimately be up to you. I would suggest testing the script with offsets and without offsets to determine which results you prefer.

                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

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                70 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                143 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                76 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                47 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                51 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X