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

Chart Cosmetics

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

    Chart Cosmetics

    I wish to draw a series of horizontal lines as part of a chart template.

    I have used the manual to create the formulas

    DrawHorizontalLine("",false,3689,Color.Black,DashS tyle.Dash,1); DrawHorizontalLine("",false,3682,Color.Black,DashS tyle.Dash,1); DrawHorizontalLine("",false,3675,Color.Black,DashS tyle.Dash,1); DrawHorizontalLine("",false,3668,Color.Black,DashS tyle.Dash,1); DrawHorizontalLine("",false,3661,Color.Black,DashS tyle.Dash,1); DrawHorizontalLine("",false,3654,Color.Black,DashS tyle.Dash,1); DrawHorizontalLine("",false,3647,Color.Black,DashS tyle.Dash,1); DrawHorizontalLine("",false,3640,Color.Black,DashS tyle.Dash,1);

    I am not sure where I put this in the ninja editor

    Also I wish to use backgroung colour to highlight specific bar times on a 1 minute chart. Is this code correct
    if (ToTime(Time[0]) = 74500)
    {
    BackColor = Color.PaleGreen;
    }
    I am not sure where I put this in the ninja editor either.

    Thanks

    Craig

    #2
    Hello,

    You want to put DrawHorizontalLine() within the OnBarUpdate() block.
    Use a unique name for all of the lines otherwise they will overwrite eachother.

    You can also Add() lines in the intialization. This link will help:


    I have attached a very simple BackColor indicator you can use as a reference.
    Your code looks OK for the BackColor except that you need to change "=" to "==" so it loks like this:
    ToTIme(Time[0]) == 74500

    You want to put it in the OnBarUpdate() block.
    Attached Files
    DenNinjaTrader Customer Service

    Comment


      #3
      Cosmetics2

      Hi Ben
      Thanks for you help
      The code now works well
      if(ToTime(Time[0]) == 75200)
      BackColor = Color.PaleGreen;
      How can I add text to the bar high lighted by this code as I am not sure how to use time with DrawText function.

      The DrawHorizontalLine() works well in the OnBarUpdate() block.
      As I understand your email I can use Add(new DrawHorizontalLine())
      (Is this how you would write code)
      under the initialization block as an alternative. Am I correct in thinking that the advantage of this is that the values of the line are stored and so can be used with other code?
      Craig

      Comment


        #4
        Hello,


        >>How can I add text to the bar high lighted by this code as I am not sure how to use time with DrawText function.

        There are a few ways you could do this.

        You could do something like this assuming you want to draw the text on the the current bar after your condition:
        DrawText("my tag", "my text", 0, High[0], Color.Black)

        Or you could use GetBar(Time[some_int]) to return the bar of the time want:
        http://www.ninjatrader-support.com/HelpGuideV6/GetBar.html

        Also, you may want to use HighestBar() to get the highest bar for a certain look back:
        http://www.ninjatrader-support.com/HelpGuideV6/HighestBar.html


        >>As I understand your email I can use Add(new DrawHorizontalLine())
        (Is this how you would write code)
        under the initialization block as an alternative. Am I correct in thinking that the advantage of this is that the values of the line are stored and so can be used with other code?


        This is one way you could include it in the Initialized() method:
        Add(new Line(Color.Gray, some_value, "line_name"));

        You will want to use some_value, in this example, to determine were the line is. No, you cannot access this line via other scripts.
        DenNinjaTrader Customer Service

        Comment


          #5
          Line Properties

          Hi Ben

          The Initialized() block is for things you want permanently on the chart from the start. Is this correct?
          Would Add(new Line(Color.Gray, some_value, "line_name"));
          use less computer resources than DrawHorizontalLine() in the OnBarUpdate() block. I want to draw quite a few lines on the chart from the start.
          With Add(new Line(Color.Gray, some_value, "line_name"));
          how would you add DashStyle.Dash or any other line style?

          Thanks

          Craig

          Comment


            #6
            Hello,


            Yes, anything you put in the Initialize() block will remain unchanged while the script is running.

            Generally speaking, if you will not be altering something and you have the option to put it in the Intialize() block you are usually better off putting it in the Intialized() block so your computer doesn't have to re-evaluate the code you have in OnBarUpdate() each time a bar is updated.


            This link has information on Initialize():



            To change the first Add(new Line(...)); to dashed, put this after the Add()'s:

            Lines[0].Pen.DashStyle = DashStyle.Dash;

            This link will help:
            DenNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            57 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Today, 06:52 PM
            4 responses
            36 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Today, 07:39 PM
            0 responses
            7 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Today, 03:01 PM
            2 responses
            19 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Today, 07:24 PM
            0 responses
            9 views
            0 likes
            Last Post cre8able  
            Working...
            X