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

Draw Extended Line Indicator

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

    #16
    Originally posted by Baruch View Post
    Hi,
    What is the difference btw. DrawLine and DrawExtendedLine?
    It would be a regular line but with infinite endpoints...
    BertrandNinjaTrader Customer Service

    Comment


      #17
      I don't understand. You need to enter the end point so? You can extend regular line with new end point on each bar.
      That how I do it. Picture attached.
      Attached Files

      Comment


        #18
        Code

        Hi Joe, many thanks for taking the time to write the detailed note and for posting that code. That's some impressive code you have managed to come up with. Way better than what I was battling with. I seem to have done something wrong though. I put the parameters in the code and unfortunately could not get a trendline to draw. I've attached the chart and the code. I put in y1 at 25 bars back y2 17 bars back. Is there something I'm missing? I tried changing the bools as well but no luck.

        Also if I wanted to see how mant ticks the current bar was from the trendline, how do I get that value? Is it trendlinevalue - Close [0] ?



        Thanks
        DJ
        Attached Files

        Comment


          #19
          DJ,
          It should be drawing the trendline. I looked and can't see any obvious error. Trendlinedrawn has to == false before it will draw the trendline. Make sure it (the strat) isn't setting this to True before it even calculates the slop. At least that's the first place I'd look. Check that in your output window after adding the Print lines below.
          Would you mind exporting your strategy and sending it to me? I can't read the .cs file. That way it will get all the indicators you are using, which I may not have. It will also insure the strat opens and runs correctly after I import it. I use Ninja 6.5 so I don't know if I can import a Ninja 7 strat.

          In the meantime, print the variables to the output window and make sure they are calculating properly.

          protected override void OnBarUpdate()
          {

          Print("trendlinevalue" + trendlinevalue);
          Print("trendlinevalueset" + trendlinevalueset);
          Print("trendlinedrawn" +trendlinedrawn);
          Print("y1 " + y1);
          Print("y2" + y2);
          Print("m " + m);

          Please send your strat (after exporting it) to [email protected] and then I can test it too.

          There are a lot of times it LOOKS like something should work and doesn't. I get SO FRUSTRATED. Without printing to the Output Window, I'd probably never get some things to work. I only program strats out of necessity, not because I want to. I sure wish I had Josh's knowledge!!
          Joe

          Comment


            #20
            DJ,
            I'm writing a strat that will do what you are looking for. I'm using Swing Highs (and Lows) to draw your channel lines. My code definitely won't work for you since it's based off a bar closing at a certain time and I know the number of bars back that I want it to start the trend line.

            So, now I need to know the number of bars between the Swings. I've never used any Bar Count code so I'll snoop around the forum and see if I can find out how to do it. Once I have that, the rest is a breeze. Wish me luck.
            Joe

            Comment


              #21
              Draw trendline

              Thanks Joe, I really appreciate your help. Let me explain a little more about this as well. If you look at the attached chart it has the two trend lines and the data associated with the lines. I have found it far quicker to manually draw the trend line on the chart and then use the datapoints to work out the slope. So in this case it is start 105.075 and end 108.391. So what I was trying to do was put these in as variables then count the bars between them which is 12 then put those as variables. Then this should calculate the trendline value at the current bar. The reason I need the value not the trendlines is I trade 8 futures instruments and the instrument with the highest probability gets traded. How close the instrument is to trendline support and resistance is a key variable that goes into the probability model where each instrument is ranked on both a medium and long term basis. For example you can see 6E would get a low ranking for this variable as it is right at resistance.

              The other thing is I got your program to draw a trendline after all (See green line) so I think it may work ok if we can change your existing program a little. However to do this I had to put Current bar < 120 in line 50. Also y1 and y2 I put as 0 and didn't seem to do much. I tried putting in the 105.075 and 108.391 in as Y1 and y2 but nothing seemed to change. I am not really sure what this program is doing but I think it is close to getting the value.


              Cheers
              DJ
              Attached Files

              Comment


                #22
                DJ,
                I just wrote a reply, but this forum locked up and it never posted. It's lost. In a nutshell, I think this is doable. It's all in the matter of capturing the number of bars since y2 once you start the strategy. I'll write a strat (if I can get it to work using CurrentBar to calculate the count) and post it.
                Joe

                Comment


                  #23
                  DJ,
                  Here’s a strat that will do what you want it to (I think). I attached several pics to show that it works.
                  BeforeStratRun pic: I opened an ES 60 min chart. I manually drew a trendline (use the Extended Line drawing tool to do this.) Its Blue. I counted the bars between Y1 and Y2, and the bars after Y2. Don’t count the bar that’s printing.

                  ParameterInputs pic: I manually entered Y1, Y2, bars between Y1 and Y2, and bars after Y2.

                  1stCloseAfterStratStart pic: I started the strat running before the bar closed at the arrow in the pic. As soon as that bar closed, the strat drew the trendline over the top of my blue trendline I had drawn. This verifies that the strat is calculating the same trendline I manually drew.

                  VerifyTrendLineValue pic: I let the strat run for about 8 hours (speeded up replay of course – THANK YOU NINJA!!) I checked the trendline value on the bar that my crosshairs are over and compared it to the calculated trendline value in the output window. They match, so everything is calculating properly.

                  Now that you have the trendline value for every bar that prints, you should easily tell your strat to “do something” if the price gets within 5 tics, or whatever, of your trendline.

                  Hope this is what you are looking for. If you don’t want the strat to draw the trendline, just // it out since you know it’s working. The strat’s trendline is invisible and doesn’t care if it shows on the chart or not.

                  Let me know if this is what you needed, or if there’s anything else I might be able to help with.
                  Joe
                  Attached Files

                  Comment


                    #24
                    Incredible!

                    Hi Joe, wow! I can't believe how you did all that and how well explained it is with the charts etc. At first I tried it out and nothing happened. Then I realized I had to wait for the bar to complete then the bar completed and nothing happened. Then I saw some faint green behind my original line and realized it had drawn the trendline perfectly behind my one. Great stuff!

                    I will test it tomorrow thoroughly and also put in some drawtextfixed strings and test them out and report back.

                    Thanks again for the help.

                    Cheers
                    DJ

                    Comment


                      #25
                      Your welcome DJ. This community has taught me so much, and I'm glad to be able to give back a little.
                      Joe

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by andrewtrades, Today, 04:57 PM
                      1 response
                      5 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by chbruno, Today, 04:10 PM
                      0 responses
                      3 views
                      0 likes
                      Last Post chbruno
                      by chbruno
                       
                      Started by josh18955, 03-25-2023, 11:16 AM
                      6 responses
                      436 views
                      0 likes
                      Last Post Delerium  
                      Started by FAQtrader, Today, 03:35 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post FAQtrader  
                      Started by rocketman7, Today, 09:41 AM
                      5 responses
                      19 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Working...
                      X