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

Plotted S/R Lines on chart now need to be extended outward til nxt one's are plotted

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

    Plotted S/R Lines on chart now need to be extended outward til nxt one's are plotted

    From Strategy Builder I made the SineWave plot the crosses for S/R onto chart. I unlocked the code to make the adjustment in the OnBarUpdate to extend the lines outward only until the next s/r line plots.

    Right now, in the code I also have the Ray line but that will need to be removed from the code.

    In the screenshot you can see the s/r lines are really small, it's those lines that I want to extend outward only up to the next s/r line that plot.


    I manually drew a few lines out & stopped at the start of next line that plotted.


    #2
    Hello trdninstyle,

    Thank you for your post.

    It seems as though the screenshot did not come through; please try sharing the screenshot again and also include a snippet of your current logic to draw the lines so we may better understand and assist you.
    • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
    • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.
    ​I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Hi Emily!

      I'll try it again real quick. I use Greenshot let's see if it comes through this time. I won't place it inside the text area this time.
      Attached Files
      Last edited by trdninstyle; 12-29-2023, 06:27 PM.

      Comment


        #4
        Originally posted by trdninstyle View Post
        Hi Emmily!

        I'll try it again real quick. I use Greenshot let's see if it comes through this time. I won't place it inside the text area this time.
        They came through this time, thank you! I see you are using the following syntax for Draw.Line() in your script:
        Draw.Line(NinjaScriptBase owner, string tag, bool isAutoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush, DashStyleHelper dashStyle, int width)

        Calling Draw.Line() with the same tag in OnBarUpdate() will update the object being drawn. What you might need to consider doing is using the same tag for each line that needs to continue on, saving the start bar where you want the line to start, and then using that to calculate the startBarsAgo being used. You can then keep the endBarsAgo to 0 (like you have it) up until you want the line to end. This means that the next line to be drawn should use a different tag so a new line is drawn rather than updating the existing line.

        For example, you currently have the following Draw.Line() in your CrossBelow condition:
        Draw.Line(this, @"SW Line_1" + Convert.ToString(CurrentBars[0]]), false, 1, High[0], 0, High[0], Brushes.White, DashStyleHelper.Soli, 2);

        The startBarsAgo is 1 and the endBarsAgo is 0, so the line is only being drawn for the length of 1 bar. If you instead save the CurrentBars[0] value to a variable (let's call it savedCrossBelowBar for this example) then when the cross condition happens, you could calculate the startBarsAgo as CurrentBars[0] - savedCrossBelowBar. You would also need to keep the same tag, so it could be something like "SW Line_1" + savedCrossBelowBar.ToString() to keep modifying the same line for each new bar until a new crossover is detected, resulting in a new saved bar index and tag name.

        Please let us know if we may be of further assistance.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          .................
          Last edited by trdninstyle; 12-29-2023, 05:12 PM.

          Comment


            #6
            Originally posted by trdninstyle View Post
            It seems to be pretty a simple fix, doesn't it. Here's my screenshot of the changes, only did the CrossBelow. Thank you as always.
            You have to be sure to save the CurrentBars[0] value to the variable when the crossover happens. I don't see where you are saving the value to savedCrossBelowBar. I suggest adding prints to better understand the start and end values used in your Draw.Line() method to see where adjustments are needed:


            Please let us know if we may be of further assistance.
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              [QUOTE=NinjaTrader_Emily;n1284199]

              I don't see where you are saving the value to savedCrossBelowBar


              I don't know, you lost me. I didn't type it correctly in the right areas then.

              if (CurrentBars[0]- savedCrossBelowBar < 1) This part of it, is incorrect?

              Did I do the Tag right?
              Draw.Line(this, @"SW Line_1 " + savedCrossBelowBar.ToString(CurrentBars[0]), false, 1, High[0], 0, High[0], Brushes.White, DashStyleHelper.Solid, 2);

              Comment


                #8
                I know what you mean now by saving the value, I still have the startBarsAgo as 1 and the endBarsAgo as 0. I didn't remove that variable.It's still going to draw for one bars space.

                I have it contradicting, saying one thing and telling it to do another.

                Attached Files
                Last edited by trdninstyle; 12-29-2023, 01:35 PM.

                Comment


                  #9
                  If you instead save the CurrentBars[0] value to a variable... then when the cross condition happens, you could calculate the startBarsAgo as CurrentBars[0] - savedCrossBelowBar

                  I initially put in your example 'savedCrossbelowBar' but thats an example not an actual example that would work. So, I came up with SaveAllDialog, I searched 'saved' in the NT help guide. I see a lot of examples what I could write in, tried a bunch of things. You could just type in an actual incident that would work without writing my code for me and be in some kind of violation.

                  if (CurrentBars[0] - SaveAllDialog)
                  return;

                  I tried without the < 1, I don't know? I tried a bunch of stuff. I hypothetically understand what you were saying but actually typing it in is another thing.


                  You would also need to keep the same tag,
                  I made sure to stay consistent with the same tag and removed the 1 and 0 on the startBarsAgo and the endBarsAgo.
                  Last edited by trdninstyle; 12-29-2023, 06:43 PM.

                  Comment


                    #10
                    Hello trdninstyle,

                    Thank you for your patience.

                    Please see the attached SampleMACrossoverDrawLinesExample I created. I modified the existing Sample MA Crossover strategy so that it draws a line that starts at the high price of the bar of each crossover and continues until the next crossover is detected, where the line stops and a new line is drawn.

                    Please feel free to reach out with any additional questions or concerns.
                    Attached Files
                    Emily C.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank you, Emily, for this.
                      I compared it to how I was trying to fit in the pieces with what I already had. No wonder it kept telling me that it's not in context. Way up there in private, private int, private string, private double is where I have to begin and on down, then it will be in context.

                      I'll work on it soon. Thanks again, Happy New Year. Go Maize and Blue
                      Last edited by trdninstyle; 01-02-2024, 12:32 PM. Reason: lol I typed it backwards, maize and blue

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Haiasi, 04-25-2024, 06:53 PM
                      2 responses
                      16 views
                      0 likes
                      Last Post Massinisa  
                      Started by Creamers, Today, 05:32 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post Creamers  
                      Started by Segwin, 05-07-2018, 02:15 PM
                      12 responses
                      1,785 views
                      0 likes
                      Last Post Leafcutter  
                      Started by poplagelu, Today, 05:00 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post poplagelu  
                      Started by fx.practic, 10-15-2013, 12:53 AM
                      5 responses
                      5,407 views
                      0 likes
                      Last Post Bidder
                      by Bidder
                       
                      Working...
                      X