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

Plotting My Own Lines

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

    Plotting My Own Lines

    This is what i have so far:

    protectedoverridevoid Initialize()
    {
    Add(
    new Line(Color.DarkCyan, PP, "MyPivot"));Add(new Line(Color.DarkCyan, R1, "MyR1"));Add(new Line(Color.DarkCyan, R2, "MyR2"));Add(new Line(Color.DarkCyan, R3, "MyR3"));
    Add(new Line(Color.DarkCyan, S1, "MyS1"));Add(new Line(Color.DarkCyan, S2, "MyS2"));
    Add(new Line(Color.DarkCyan, S3, "MyS3"));
    }

    protectedoverridevoid OnBarUpdate()
    {
    PreHigh = PriorDayOHLC().PriorHigh[
    0];
    PreLow = PriorDayOHLC().PriorLow[
    0];
    PreClose = PriorDayOHLC().PriorClose[
    0];

    PP = (PreHigh + PreLow + PreClose) /
    3;
    R1 =
    2 * PP - PreLow;
    R2 = PP + (PreHigh - PreLow);
    R3 = R1 + (PreHigh - PreLow);
    S1 =
    2 * PP - PreHigh;
    S2 = PP - (PreHigh - PreLow);
    S3 = S1 - (PreHigh - PreLow);

    }

    What i want is to plot the pivots at the values they equal. I would also like to add text on each line to label which one they are.

    #2
    Hi Coby, it isn't recommend to Add lines in the initialize section. Would DrawLine work for you?
    Code:
    // Draws a dotted lime green line from 10 bars back to the current bar  
    // with a width of 2 pixels  
    DrawLine("PP", false, 10, PP, 0, PP, Color.LimeGreen, DashStyle.Solid, 1);
    AustinNinjaTrader Customer Service

    Comment


      #3
      how to draw text to label each line

      Ok I got the pivot lines to show up. Now how do i draw text on each line to label which one is which on the left side of the chart.

      This is what i have:
      DrawText("Pivot", TF,"Pivot", 75, PP, 3, Color.Black, Font., StringAlignment.Center, Color.Black, Color.WhiteSmoke, 1);

      I cannot get it to work. what do I put for the font.
      Last edited by cbart_1; 08-12-2009, 12:34 PM. Reason: Adding more

      Comment


        #4
        Hi Coby, I recently wrote a tip that deals with how to change the font when using DrawText. The tip is located here. Basically, you can do this:
        Code:
        // in variables
        private Font    largeFont = new Font("Arial", 12);        // This  variable holds the large font.
        
        // in OnBarUpdate (or anywhere else)
        DrawText("PP", true, "text that displays on the chart", 1, PP,  Color.Black, largeFont, StringAlignment.Near, Color.Transparent,  Color.Transparent, 0);
        AustinNinjaTrader Customer Service

        Comment


          #5
          My lines went away

          That made my lines go away and no text is diplayed on the chart.

          Comment


            #6
            Are there any errors in the logs (right-most tab in Control Center)?
            AustinNinjaTrader Customer Service

            Comment


              #7
              Yes

              The startBarsAgo is out of valid range. I have it at 50. If I set it to 0 it will work but it puts the text to right side of the chart.
              Last edited by cbart_1; 08-12-2009, 01:06 PM.

              Comment


                #8
                That means the line is trying to be drawn where no bars exist. For example, at the 1st bar it tries to draw a line 50 bars back (-49th bar) which doesn't exist. A simple fix:
                Code:
                protected override void OnBarUpdate()
                {
                // very important this item is first in OnBarUpdate()
                
                if (CurrentBar < 50)
                    return;
                }
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  Ok That worked

                  Thank You!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Aviram Y, Today, 05:29 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post Aviram Y  
                  Started by quantismo, 04-17-2024, 05:13 PM
                  3 responses
                  25 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by ScottWalsh, 04-16-2024, 04:29 PM
                  7 responses
                  34 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by cls71, Today, 04:45 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post cls71
                  by cls71
                   
                  Started by mjairg, 07-20-2023, 11:57 PM
                  3 responses
                  216 views
                  1 like
                  Last Post PaulMohn  
                  Working...
                  X