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

Prior Day Fibonnaci Retracement Indicator

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

    Prior Day Fibonnaci Retracement Indicator

    I'm working on programming an indicator to draw a fib retracement from the previous day's high to the previous day's low. I have a couple questions:

    first, is there a way to call yesterday's high and yesterday's low
    second, is there a way to call yesterday's open and yesterday's close so as to determine which way to draw the fib, for example, if yesterday was a down day, the start of the fib drawing would be on yesterday's low and be drawn to yesterday's high.

    Thank you

    #2
    For accessing the prior day High and Low, you can use - http://www.ninjatrader.com/support/h...r_day_ohlc.htm

    It would give you access to the open and close as well, so you could determine from there the day direction.

    The price info accessed will be based on the applied session template on your chart.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thank you very much. I seem to be having trouble with DrawFibonacci command. If i want the command to draw from the start of today's trading session to the current time, what would be the x inputs for that? 16:00 my time to 15:59 the following day (or just keep printing until it needs to be updated when a new day bar is made)

      What is wrong with this code:

      double high = PriorDayOHLC().PriorHigh[1];
      double low = PriorDayOHLC().PriorLow[1];
      double close = PriorDayOHLC().PriorClose[1];
      double open = PriorDayOHLC().PriorOpen[1];

      if (CurrentBar == 0) return;


      if (close<open)
      {
      DrawFibonacciRetracements("tag1",false,10,low,1,hi gh);
      }
      else
      {
      DrawFibonacciRetracements("tag2",false,10,high,1,l ow);
      }
      Last edited by jmflukeiii; 02-03-2012, 10:39 AM.

      Comment


        #4
        Originally posted by jmflukeiii View Post
        Thank you very much. I seem to be having trouble with DrawFibonacci command. If i want the command to draw from the start of today's trading session to the current time,
        Start of today's trading session is start bars ago = Bars.BarsSinceSession

        Current time is end bars ago = 0.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          EDIT: I found another code snippet on here and got it to draw, for today. I'm not sure if its going to draw then when the day turns over....

          But one other question. Can I set certain things in the script like where the text is positioned on the retracement?

          This code doesn't do anything and I don't understand why? I've tried all sorts of things and I can't even make it draw fib retracement from anywhere to anywhere, let alone the places I want it to be drawn from. What am I doing wrong?

          protected override void OnBarUpdate()
          {
          // Use this method for calculating your indicator values. Assign a value to each
          // plot below by replacing 'Close[0]' with your own formula.

          // Use this method for calculating your indicator values. Assign a value to each
          // plot below by replacing 'Close[0]' with your own formula.
          double yhigh = PriorDayOHLC().PriorHigh[1];
          double ylow = PriorDayOHLC().PriorLow[1];
          double yclose = PriorDayOHLC().PriorClose[1];
          double yopen = PriorDayOHLC().PriorOpen[1];




          IFibonacciRetracements fib1 = DrawFibonacciRetracements("tag2",false,Bars.BarsSi nceSession,yhigh,0,ylow);







          }
          Last edited by jmflukeiii; 02-03-2012, 01:13 PM.

          Comment


            #6
            Originally posted by jmflukeiii View Post
            EDIT: I found another code snippet on here and got it to draw, for today. I'm not sure if its going to draw then when the day turns over....

            But one other question. Can I set certain things in the script like where the text is positioned on the retracement?

            This code doesn't do anything and I don't understand why? I've tried all sorts of things and I can't even make it draw fib retracement from anywhere to anywhere, let alone the places I want it to be drawn from. What am I doing wrong?

            protected override void OnBarUpdate()
            {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.

            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.
            double yhigh = PriorDayOHLC().PriorHigh[1];
            double ylow = PriorDayOHLC().PriorLow[1];
            double yclose = PriorDayOHLC().PriorClose[1];
            double yopen = PriorDayOHLC().PriorOpen[1];




            IFibonacciRetracements fib1 = DrawFibonacciRetracements("tag2",false,Bars.BarsSi nceSession,yhigh,0,ylow);







            }
            What error is in your log?

            Comment


              #7
              Hadn't thought of checking that, thank you.

              It says I am accessing an index with a value that is invalid since its out of range.

              Comment


                #8
                Got it!

                Got it! I was using the priorday command but inputting a value of 1. By changing that to 0, it used the day before and started drawing. I'll post it in case anyone wants it when I finish. I'm going to work on extensions next. This is supposed to be similar to the SpudFibo indicator for MT4.

                If anyone could tell me how to align the text to the right (from the script), I'd much appreciate it. Also, if there is a way to either remove the anchor line all together or at least select a color for it so it matches the background, that would be great also.
                Last edited by jmflukeiii; 02-03-2012, 01:42 PM.

                Comment


                  #9
                  Here it is, with extensions on both sides. I colored the anchors black manually in this picture, but it would be great if that could be done from the script itself. Also, if I could move the text to the right or possibly just color the lines differently if that's an option.

                  Thank you
                  Attached Files

                  Comment


                    #10
                    Great you were able to sort it out. Unfortunately DrawFibonacci() does not offer the controls you are looking for. Only the parameters you see in these two available overloads are available:

                    DrawFibonacciRetracements(string tag, bool autoScale, int startBarsAgo, double startY, int endBarsAgo, double endY)
                    DrawFibonacciRetracements(string tag, bool autoScale, DateTime startTime, double startY, DateTime endTime, double endY)
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by jmflukeiii View Post
                      Here it is, with extensions on both sides. I colored the anchors black manually in this picture, but it would be great if that could be done from the script itself. Also, if I could move the text to the right or possibly just color the lines differently if that's an option.

                      Thank you
                      Drawings are in the first instance done with the Default Template for the drawing type, so set up your default template the way you want it to be, and your drawings will be correctly done. There are not many properties of the object that are exposed, other than through the XML template. Those that are exposed, you can change programatically. Intellisense exposes most of any such properties. Typically the ones that I have used to force action regardless are:

                      FibObject.Showtext
                      FibObject.ExtendRight, (I typically do not use ExtendLeft).
                      FibObject.SeparateZOrder

                      where, of course FibObject is declared as being of type IFibonacciRetracements. Those properties are all of type bool.

                      Comment


                        #12
                        Ryan... so if I can't move the text to the right, I'd like to have the start of the Fib be at yesterday's high, but drawn from, say, 75 bars ago so that the numbers show on my screen. I tried to input 75 for the start x coordinate, but then it prints nothing. Why is this?

                        Koganam.... thank you, but I think you are overestimating my programming abilities. I'm not sure how to use those commands.

                        Comment


                          #13
                          If you check log tab of control center, you're likely getting index out of range errors. This items is described here.

                          Make sure you are returning out from OnBarUpdate() for at last as many "start bars ago" as you defined.

                          if (CurrentBar < 75) return;
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #14
                            Ha, easy enough. Thanks!

                            Here's the new version with a user defined distance to extend the lines back.
                            Attached Files
                            Last edited by jmflukeiii; 02-03-2012, 04:09 PM.

                            Comment


                              #15
                              Koganam -

                              Could you give me an idea of how to put that extend right command into the code below. Then I could just have the start of the fib be x number of bars ago so I can see it on the screen, but I could have the end x value be the same, then extend the lines to the right. This would eliminate the anchor line running through the chart.
                              extendBack is the user defined input for the start of the drawing

                              protected override void OnBarUpdate()
                              {
                              double yhigh = PriorDayOHLC().PriorHigh[0];
                              double ylow = PriorDayOHLC().PriorLow[0];
                              double yclose = PriorDayOHLC().PriorClose[0];
                              double yopen = PriorDayOHLC().PriorOpen[0];

                              if (CurrentBar < extendBack) return;

                              if (yclose<yopen)
                              {
                              DrawFibonacciRetracements("tag1",false,extendBack, yhigh,0,ylow);
                              DrawFibonacciExtensions("tag2",false,Bars.BarsSinc eSession,ylow,Bars.BarsSinceSession,yhigh,extendBa ck,yhigh);
                              DrawFibonacciExtensions("tag3",false,Bars.BarsSinc eSession,yhigh,Bars.BarsSinceSession,ylow,extendBa ck,ylow);

                              }
                              else
                              {
                              DrawFibonacciRetracements("tag2",false,75,ylow,0,y high);
                              DrawFibonacciExtensions("tag2",false,Bars.BarsSinc eSession,ylow,Bars.BarsSinceSession,yhigh,extendBa ck,yhigh);
                              DrawFibonacciExtensions("tag3",false,Bars.BarsSinc eSession,yhigh,Bars.BarsSinceSession,ylow,extendBa ck,ylow);
                              }
                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by The_Sec, Yesterday, 03:37 PM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by vecnopus, Today, 06:15 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post vecnopus  
                              Started by Aviram Y, Today, 05:29 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post Aviram Y  
                              Started by quantismo, 04-17-2024, 05:13 PM
                              3 responses
                              27 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by ScottWalsh, 04-16-2024, 04:29 PM
                              7 responses
                              36 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X