• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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:
                DrawRay("tag1", CurrentBar - startBar, MAX(High, CurrentBar - startBar)[0], 0, MAX(High, CurrentBar - startBar)[0], Color.LimeGreen);
                NT8

                Code:
                Draw.Ray(this, "tag1", CurrentBar - startBar, MAX(High, CurrentBar - startBar)[0], 0, MAX(High, CurrentBar - startBar)[0], Color.LimeGreen);
                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.

                    http://ninjatrader.com/support/helpG...zontalline.htm
                    http://ninjatrader.com/support/helpG...zontalline.htm
                    Jessica P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by James Wallace, Today, 10:38 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post James Wallace  
                    Started by mtamaku, Today, 10:22 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post mtamaku
                    by mtamaku
                     
                    Started by mtamaku, Today, 10:16 AM
                    1 response
                    4 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by hedgeplay, Yesterday, 08:04 PM
                    1 response
                    11 views
                    0 likes
                    Last Post NinjaTrader_Kate  
                    Started by UltraNIX, Today, 12:31 AM
                    6 responses
                    25 views
                    0 likes
                    Last Post UltraNIX  
                    Working...
                    X