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

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.
    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.
          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#.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by GLFX005, Today, 03:23 AM
              0 responses
              1 view
              0 likes
              Last Post GLFX005
              by GLFX005
               
              Started by XXtrader, Yesterday, 11:30 PM
              2 responses
              11 views
              0 likes
              Last Post XXtrader  
              Started by Waxavi, Today, 02:10 AM
              0 responses
              6 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by TradeForge, Today, 02:09 AM
              0 responses
              14 views
              0 likes
              Last Post TradeForge  
              Started by Waxavi, Today, 02:00 AM
              0 responses
              3 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Working...
              X