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

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 alifarahani, Today, 09:40 AM
            6 responses
            24 views
            0 likes
            Last Post alifarahani  
            Started by Waxavi, Today, 02:10 AM
            1 response
            17 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by Kaledus, Today, 01:29 PM
            5 responses
            13 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by Waxavi, Today, 02:00 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by gentlebenthebear, Today, 01:30 AM
            3 responses
            17 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X