Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

get Reversal bar

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

    get Reversal bar

    how to get reversal bar.

    i want to get first green bar after red or vice-versa

    #2
    Hello yeshujbp,
    Thanks for your post.

    i want to get first green bar after red
    Simply checking the open price and the close price of a bar will create that condition. However, you may need to check more than two bars to qualify something as a "reversal".

    For example, the following snippet would see if the previous candle was "red":
    Code:
    if(Close[1]<Open[1])
    and this would check if the current candle is "green".
    Code:
    if(Close[0]>Open[0])
    Putting them together yields the condition for a candle that is the first green candle after a red candle:
    Code:
    if(Close[0]>Open[0] && Close[1]<Open[1])
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thank you reply
      That condition is run properly when i use property " Calculate=Calculate.OnBarClose" but I changed property "Calculate=Calculate.OnEachTick" That condition

      if(Close[0]>Open[0] && Close[1]<Open[1]) true multi time of each tick
      Any option to get signal final result of condition on Each tick.

      Comment


        #4
        Hello yeshujbp,

        Thanks for your reply.

        Correct, that would be the expected behavior when changing to Calculate.OnEachTick (Or Calculate.OnPriceChange). When using Calculate.OnBarClose, the reference to [0] is to the just completed bar which would not change. When using OnEachTick (Or OnPriceChange) the reference to [0] now points to the currently forming bar which is dynamically changing as each execution of your code could determine the conditions differently as the bar itself changes.

        You can change the bars ago reference to evaluate just the completed bars: if(Close[1]>Open[1] && Close[2]<Open[2]) and the results would not change.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi
          Thanks for your reply above, I have applied the logic to find reversal bar which worked, but I am facing issue when I am trying to find retracement after the reversal.

          Here retracement is a temporary reversal which is not changing the trend but trade get reversed for few moments.

          so we are looking to capture the retracement(Temporary reversal) moments in real time and not after the barclosed.

          //this conditions for reversal
          if ((Close[0] > Open[0] && Close[1] < Open[1]))
          {

          //below is the calculation to get 30% retracement which is used in the retracement logic to compare the value after reversal, once the value goes below this 30% retracement we are looking to //draw a DOT.
          high = High[1]-Low[1];
          flag = true;
          per = high * 30 / 100;
          comp = High[1] - per;

          Draw.Dot(this, "Slave" + comp + "pre=" + per + Close[0], true, 1, Close[0], Brushes.Black);


          }
          //this conditions for retracement
          if(flag)
          {
          if (Low[0] <= comp)
          {
          Draw.Dot(this, "S" + CurrentBar, true, 0, High[0], Brushes.Yellow);
          flag=false;


          }
          }

          Comment


            #6
            Hello yeshujbp,

            Thanks for your reply.

            Glad that solution worked for you.

            You did not state what you are or are not seeing with your latest post, only what you wish to do and have shown some code.

            If your code is not performing as expected, we recommend debugging with print statements to print out the values being used for the conditions that determine when/if to place the dots (if that is your question). Here is a link to our debugging tips: https://ninjatrader.com/support/help...script_cod.htm
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hi
              Thanks for your reply.

              when you run the script the above condition[if ((Close[0] > Open[0] && Close[1] < Open[1]))] becomes true in each tick,that is the main problem .

              I also used a IsFirstTickOfBar property but that not working

              Comment


                #8
                Hello yeshujbp,

                Thanks for your reply.

                Did you consider the comments in my earlier post?, "When using OnEachTick (Or OnPriceChange) the reference to [0] now points to the currently forming bar which is dynamically changing as each execution of your code could determine the conditions differently as the bar itself changes. You can change the bars ago reference to evaluate just the completed bars: if(Close[1]>Open[1] && Close[2]<Open[2]) and the results would not change. ".

                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Hi
                  Thanks for your reply.

                  Sorry I did not mention I used both condition[ if(Close[1]>Open[1] && Close[2]<Open[2]) or if ((Close[0] > Open[0] && Close[1] < Open[1]))] and also used IsFirstTickOfBar but that true multi-times

                  Comment


                    #10
                    Hello yeshujbp,

                    Thanks for your reply.

                    IsFirstTickOfBar can only be true once per bar. Does your script have additional data series (added by using AdddataSetes())?

                    Can you post more of your complete code to better understand what you are working with?

                    Alternatively, if you don't want to post more of your code, you are always welcome to write into PlatformSupport[at]NinjaTrader[dot]com. Please mark the e-mail Atten: Paul and include a link to this thread for reference.

                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi
                      Thanks for your reply.

                      I am sending a script of indicator(Alert.cs) check it also send a BarType (chart) which use that indicator.my main problem is that condition true many times.
                      Attached Files
                      Last edited by NinjaTrader_Jim; 07-05-2019, 06:47 AM.

                      Comment


                        #12
                        Hello yeshujbp,

                        Thanks for your reply.

                        We removed the bars code to protect the bars source code as it appears the licensing had been bypassed.

                        The Bars type you are using is set up to "remove last bar" and as such IsFirstTickOfBar is always set true which confirms your observations: Reference: https://ninjatrader.com/support/help...ttickofbar.htm

                        As you cannot use the system's IsFirstTickOfBar, you will have to create your own logic to detect/determine when you have a new bar if you want to continue working with Calculate.OnEachTick.

                        As a suggestion, you may want to look at the value of Bars.Count which will usually point to 1 bar ahead so Bars.Count-1 would be the current bar (on live data). When Bars.Count changes, the first time, you could set your own bool to indicate the first tick of a new bar. Again this is something you will have to work out and test/verify. This would not work on historical data but it looks like your code is only intended for live data.

                        Paul H.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by habeebft, Today, 07:27 AM
                        1 response
                        11 views
                        0 likes
                        Last Post NinjaTrader_ChristopherS  
                        Started by AveryFlynn, Today, 04:57 AM
                        1 response
                        12 views
                        0 likes
                        Last Post NinjaTrader_Erick  
                        Started by Max238, Today, 01:28 AM
                        4 responses
                        37 views
                        0 likes
                        Last Post Max238
                        by Max238
                         
                        Started by r68cervera, Today, 05:29 AM
                        1 response
                        10 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by geddyisodin, Today, 05:20 AM
                        1 response
                        14 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Working...
                        X