Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

trendline on a chosen timeframe

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

    trendline on a chosen timeframe

    Hi,

    I want the platform to draw me a trendline (ray line) within my chosen timeframe for example if I select between 2am - 4am it would draw a line on the high during that time.

    thanks,
    bdg820

    #2
    Hello Bdg820, and thank you for your question. I am combining code samples from the following pages to accomplish this goal.

    draw me a trendline (ray line)
    http://ninjatrader.com/support/helpG...t7/drawray.htm

    within my chosen timeframe
    http://ninjatrader.com/support/helpG...nt7/totime.htm

    Code:
    private int startBar = 0;
    protected override void OnBarUpdate()
    {
        if (Bars.FirstBarOfSession)
        {
            startBar = 0;
        }
    
        // Only draw between 2:00 AM and 4:00 AM
        if (ToTime(Time[0]) >= 20000 && ToTime(Time[0]) <= 40000)
        {
            // start the ray at the first bar after 2 PM
            if (startBar == 0)
            {
                startBar = CurrentBar;
                return;
            }
    
            // Draws a lime green line on the high through the current bar
            DrawRay("tag1", CurrentBar - startBar, High[CurrentBar - startBar], 0, High[0], Color.LimeGreen);
        }
    }
    Last edited by NinjaTrader_JessicaP; 12-01-2016, 08:48 AM.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Hi Jessica,

      Is it possible for you to send the code as a attachement, I'm having trouble copying the code into ninjascript.

      Thanks,
      Bdg820

      Comment


        #4
        I am happy to. I have included an NT7 and NT8 version.
        Attached Files
        Last edited by NinjaTrader_JessicaP; 12-01-2016, 09:00 AM.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Hi Jessica,

          Sorry I'm still have problems opening this cs.file . Is it possible to receive it in another format.

          thanks,
          bdg820

          Comment


            #6
            Please be aware that if you are using a Microsoft Windows PC, new enough to run NinjaTrader, the built-in Notepad program will open the C# files I sent. You may right-click on these files, select "open with", and then "choose another app", then follow the prompts to select Notepad as the program you open these with each time you double-click on them.

            That said we are always happy to help. I am including the same files renamed with the .txt extension, as well as .zip files that Ninja can import. If neither of these will suit your needs, and you could provide a little information as far as how you are attempting to load and use these files, this will help us give you better help.
            Attached Files
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Hi Jessica,

              Thanks I got it plotted the only thing is that it plots diagonal. I would like it to plot horizontally. For example if I choose 2am - 4am it would pick up the highest point and plot it horizonatal line extended to the right. The I wanted the ray line was so I could the end time.

              Thanks,
              Bdg820

              Comment


                #8
                In order to get this line to draw horizontally at the highest price, you will need to change both the prices passed in to DrawRay (that is, High[CurrentBar - startBar] and High[0]) to MAX(High, CurrentBar - startBar)[0] . That is,

                NT7

                Code:
                [FONT=Courier New]DrawRay("tag1", CurrentBar - startBar, [/FONT][FONT=Courier New][B]MAX(High, CurrentBar - startBar)[0][/B], 0, [/FONT][FONT=Courier New][B]MAX(High, CurrentBar - startBar)[0][/B], Color.LimeGreen);[/FONT]
                NT8

                Code:
                [FONT=Courier New]Draw.Ray(this, "tag1", CurrentBar - startBar, [/FONT][FONT=Courier New][B]MAX(High, CurrentBar - startBar)[0][/B], 0, [/FONT][FONT=Courier New][B]MAX(High, CurrentBar - startBar)[0][/B], Color.LimeGreen);[/FONT]
                Last edited by NinjaTrader_JessicaP; 12-01-2016, 01:51 PM.
                Jessica P.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Jessica,

                  Thanks it worked. Is it possible to plot on the previous days.

                  Thanks,
                  Bdg820

                  Comment


                    #10
                    Yes, but we have reached the scope of the support we can provide here, as this would require developing code to make sure that previous days have already been plotted on your chart. The 2nd argument into the NT7 DrawRay method, and the 3rd argument into the NT8 Draw.Ray method, control how many bars back you start.

                    Perhaps an easier solution would be to draw horizontal lines instead of rays. Those methods are documented here.


                    Jessica P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by prdecast, Today, 06:07 AM
                    1 response
                    4 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by Christopher_R, Today, 12:29 AM
                    1 response
                    13 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by chartchart, 05-19-2021, 04:14 PM
                    3 responses
                    577 views
                    1 like
                    Last Post NinjaTrader_Gaby  
                    Started by bsbisme, Yesterday, 02:08 PM
                    1 response
                    15 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by i019945nj, 12-14-2023, 06:41 AM
                    3 responses
                    60 views
                    0 likes
                    Last Post i019945nj  
                    Working...
                    X