Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw horizontal lines to set stop loss and target in a chart &calculate lot quantity

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

    Draw horizontal lines to set stop loss and target in a chart &calculate lot quantity

    Hi there,

    Is there some way to programmatically draw a named (specific tag) horizontal line (unmmanaged) so it can be moved manually to a desired place and use its price (position) to calculate the lot quantity to enter an order?

    Or is there a way to manually draw a horizontal line, which can be used programmatcally to use its position (price) to calculate the lot quantity to enter an order?

    Thank you.

    #2
    Hello robott,

    Thank you for your post.

    You can loop through the Drawing Objects on the chart and search for a Horizontal Line with a specific tag. You would need to ensure you drew the Horiztonal Line and then left click on it and then right click and change it's Tag to the needed tag.

    For information on looping through the Drawing Objects on the chart please visit the following link: https://ninjatrader.com/support/help...rawobjects.htm

    Please let me know if you have any questions.

    Comment


      #3
      Hi Patrick,

      First of all, thank you for your tip, it was helpful. I found this code that helps me draw a horizontal line on a button click and unlock it so i can move it manually to a new price/position.

      Now i need to retrieve the new price where it stands, but i cannot find a "price" or "y" value in its properties/attributes. Any suggestion you can provide to work it out?

      // // If horizontal line "myStopLoss" exists, it moves it to the "Y" position (price).
      // // and unlocks it so i can move it manually
      if (DrawObjects["myStopLoss"] != null && DrawObjects["myStopLoss"] is DrawingTools.HorizontalLine)
      {
      Draw.HorizontalLine(this, "myStopLoss", 0.76130, Brushes.Aqua);
      DrawObjects["myStopLoss"].IsLocked=false;
      }
      else
      {
      // // If horizontal line "myStopLoss" doesn't exist, it creates it at the "Y" position (price).
      // // and unlocks it so i can move it manually
      Draw.HorizontalLine(this, "myStopLoss", 0.76090, Brushes.Purple);
      DrawObjects["myStopLoss"].IsLocked=false;
      // DrawObjects["myStopLoss"].Anchors.; // ONCE MANUALLY MOVED, HOW DO I GET ITS NEW VALUE/PRICE?

      Thank you.

      Comment


        #4
        Hi robott,

        the price can be found in the line's Anchors collection, each ChartAnchor has a Price property: https://ninjatrader.com/support/help...s/?anchors.htm

        Kind regards,
        gurk

        Comment


          #5
          DrawObjects["myStopLoss"].Anchors.First().Price);

          Hi Gurko,

          Thanks a lot for taking the time to respond. It took me some digging into NT8 forums to find exactly how to extract the price from the anchor but i did it thanks to you.

          This is what i found:

          DrawObjects["myStopLoss"].Anchors.First().Price);

          Comment


            #6
            Hi robott, my pleasure. Had the same question earlier when creating a custom line type that would display its price alongside. Your solution looks just fine!

            Kind regards,
            gurko

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by sinpeople, Today, 07:20 AM
            0 responses
            1 view
            0 likes
            Last Post sinpeople  
            Started by Frank1000, Today, 03:05 AM
            0 responses
            3 views
            0 likes
            Last Post Frank1000  
            Started by ntdev, Today, 01:14 AM
            4 responses
            16 views
            0 likes
            Last Post ntdev
            by ntdev
             
            Started by ct, Today, 02:22 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by yodaler, Yesterday, 06:12 PM
            4 responses
            13 views
            0 likes
            Last Post NinjaTrader_Jason  
            Working...
            X