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 use Region Highlight Y as takeprofit Target

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

    How to use Region Highlight Y as takeprofit Target

    Hello, I want to use existing region highight Y drawings if a position is entered. Is it possible to let the strategy check the nearest Y-value (price) in the existing of the opened chart drawings and set takeprofit and stoploss orders?

    #2
    Hello WbrTrader,

    Welcome to the NinjaTrader forums!

    You can assign the drawing object to a variable when you draw this, and then use the anchors for that object to get the .Price of the anchor. The prices will be a double that can be used for order methods limit price and stop price as long as the prices are valid for the order type and direction.

    Below are links to the help guide.



    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      thank you for your answer. I am totally new to this and dont know how to assign the drawing object to a variable. Do you have time to give me some more help? The attached links dont give me the information i need.

      What the strategy should do:

      What the strategy should do:
      As soon as the strategy opens a position in compliance with my rules, a StopLoss or TakeProfit order should be created at the next price mark.
      The price marks required for this should be given by RegionHighlight Y markings that I have entered manually.

      How can I do that exactly?​
      Last edited by WbrTrader; 12-12-2022, 01:05 PM.

      Comment


        #4
        Hello WbrTrader,

        Keep in mind that knowing C# does come pre-requisite to learning NinjaScript.

        Below is a link to a forum post with helpful resources on getting started with C# and NinjaScript.

        Knowing how to assign values to variables, knowing the basic syntax of C#, understanding scope and object types, knowing how branching commands and loops work, should be your first path in learning.

        The first line in the code sample in the help guide I have linked in my previous post shows calling a draw method as assigning the drawing object to a variable.
        Code:
        RegionHighlightY myReg = Draw.RegionHighlightY(this, "tag1", 10, 0, Brushes.Blue);
        The code example then uses the variable to access the drawing object's .AreaOpacity. You need to access the .StartAnchor.Price or .EndAnchor.Price.

        Check the anchor price is a valid price for the order type and direction.

        You can submit an ExitLongStopMarket() / ExitShortStopMarket() from OnExecutionUpdate() or OnOrderUpdate() when the entry order fills.

        Below is a link to an example.
        https://ninjatrader.com/support/foru...269#post802269

        Then use the anchor price as the stopPrice parameter.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi WbrTrader,

          I think I know what you're trying to do. You want to drawn levels/regions on the chart and then you want your strategy to trade those levels.

          Here's what you can do:
          1. Manually raw a line/region/rectangle on the chart.
          2. Right-click on the newly drawn object and select Properties.
          3. Rename the Tag to something your strategy can easily identify using a unique name. (For example, "MyYRegion-01"
          4. Repeat 1-3 for the objects you want on the chart.
          5. In your strategy code, use DrawingObjects, found here: https://ninjatrader.com/support/help...rawobjects.htm
          6. Iterate over the drawing objects, finding the tags you drew above.
          7. Then using the properties to obtain the levels you want.
          For example a Y-Region object has Start Y and End Y for its levels.

          Obviously, the coding is considerably more detailed than this but it should point you the right direction. See the code examples in the link for DrawObjects; that should help.

          Hope that helps!
          Matt

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Segwin, 05-07-2018, 02:15 PM
          14 responses
          1,788 views
          0 likes
          Last Post aligator  
          Started by Jimmyk, 01-26-2018, 05:19 AM
          6 responses
          837 views
          0 likes
          Last Post emuns
          by emuns
           
          Started by jxs_xrj, 01-12-2020, 09:49 AM
          6 responses
          3,293 views
          1 like
          Last Post jgualdronc  
          Started by Touch-Ups, Today, 10:36 AM
          0 responses
          13 views
          0 likes
          Last Post Touch-Ups  
          Started by geddyisodin, 04-25-2024, 05:20 AM
          11 responses
          63 views
          0 likes
          Last Post halgo_boulder  
          Working...
          X