Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get price of a horizontal line

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

    How to get price of a horizontal line

    I have drawn a horizontal line at the opening of trading day. I need a variable to represent the price at that line. "double closePrice = Bars.GetClose(barIndex);" at the exact time of starting trading would seem applicable but does not compile. Any suggestions?

    #2
    Hello Pete77,

    What is the compile error you are getting?

    Is barIndex defined as an integer and holding a value of the CurrentBar number when Bars.IsFirstBarOfSession is true?


    To get the price of a horizontal line:
    private HorizontalLine myLine;

    myLine = Draw.HorizontalLine(this, "myHLine" + CurrentBar, Close[0], Brushes.Blue);
    Print(myLine.StartAnchor);

    Below is a link to the help guide.
    https://ninjatrader.com/support/help...zontalline.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Many thanks! I will work on that. I obviously went at it wrong. I got the compile error when I inserted wrong code.

      Comment


        #4
        I have been looking for days for information on your statment: "Is barIndex defined as an integer and holding a value of the CurrentBar number when Bars.IsFirstBarOfSession is true?" Can you give me little help on this? My code now compiles but does not draw the line nor output any print statement.
        (Myname should now be Pete99 instead of 77).

        Comment


          #5
          Hello Pete77,

          What is barIndex?
          Where is this defined?
          What is the value of barIndex?
          Where is this value assigned?
          Is this value assigned any where?

          Provide output from prints.

          Print the time of the bar and all values in the condition that causes the object to be drawn, and print the y value the object is being drawn at.

          Below is a link to a forum post that demonstrates using prints to understand behavior.
          https://ninjatrader.com/support/foru...121#post791121
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            I realize I have a lot to learn. May I show you where I am at?

            In both indicator and strategy I have been able to draw a horizontal line at 8:30, using "Close[0] of the 8:30 bar. I have used Close[0] as the Y value for adding other horizontal lines like Close[0] + 30 ticks. But Close[0] at 8:30 does not work for me for other objects like CrossAbove, Instantiate the line, etc. and printing Close[0] just gives me assorted numbers on the output window that mean nothing.

            Obviously, I must make the index value stick at 8:30. "Define the index as integer". How to do this is where I am stuck.

            Comment


              #7
              Hello Pete77,

              int is short for Integer.

              To define a variable as an integer:
              Code:
              private int myVariable;
              To assign myVariable a value:
              Code:
              myVariable = 5;
              To print the value of myVariable:
              Code:
              Print(myVariable);
              To use myVariable which has a value of 5 as an index:
              Code:
              if (CurrentBar > myVariable)
              {
              Print(Close[myVariable]);
              }
              Below I am providing a link to a forum post with helpful information about getting started with C#.
              https://ninjatrader.com/support/foru...040#post786040
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by AidanLawrence, Today, 10:03 PM
              0 responses
              1 view
              0 likes
              Last Post AidanLawrence  
              Started by butt_toast, Today, 09:47 PM
              0 responses
              1 view
              0 likes
              Last Post butt_toast  
              Started by GaryOz, Today, 06:54 PM
              0 responses
              3 views
              0 likes
              Last Post GaryOz
              by GaryOz
               
              Started by 2inthebush, Today, 06:27 PM
              0 responses
              19 views
              0 likes
              Last Post 2inthebush  
              Started by harr5754, Today, 03:08 PM
              2 responses
              9 views
              0 likes
              Last Post harr5754  
              Working...
              X