Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw with a button

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

    Draw with a button

    Hello,

    I am coding an indicator and, in addition to executing an order to enter to the market, I would like to draw a "Risk / Reward" but I get this error: "Unhandled exception: Index was out of range. Must be non-negative and less than the size of collection. Parameter name: index"

    Why is not it working this? How could I do it?

    PHP Code:
    protected void Button1_Click(object sender, RoutedEventArgs e)
            {
                   Draw.RiskReward(this, "tag1", true, 0, High[0], 10, Low[1], 1, true);
            } 
    
    Thanks!

    #2
    Hello rafaelmarcos,

    Thank you for the post.

    You must make sure that you have the event set up properly.

    See this public link on a mouse event capture sample.



    This post also describes how to add and remove the event handler properly:



    Please let me know if you have any questions.

    Comment


      #3
      Hello NinjaTrader_ChrisL,

      Thanks for your help. The example you give me is for an Add-on and what I am coding is an Indicator. The goal is not to press the button to start a drawing tool and then customize it. The objective is to place the order in the market, and without any further action, let the element "Risk / Reward" be drawn with certain values previously calculated. Could you give me an example please?

      Thank you very much!

      Comment


        #4
        Hello rafaelmarcos,

        Thanks for the reply.

        Below is a sample that adds buttons for drawing tools. I now see you do not want to draw it yourself, just activate the drawing, so this example should get you in the right direction.



        Please let me know if I can assist further.

        Comment


          #5
          hahaha no, just the oppposite! "Risk / Reward" drawn with certain values previously calculated. I want that when pressing the button it puts the order in the market and leaves automatically marked where the stop and profit should be located

          Comment


            #6
            Hello rafaelmarcos,

            Thanks for the reply.

            The only order entry methods are in the Strategies and Addons namespaces. The same example logic from my previous post can be used to create a strategy or addon that will place an order on command.

            Note that you can use SetStopLoss() and SetProfitTarget() to set a stop and target automaticaly in a strategy.

            Please let me know if I can assist further.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            571 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            330 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            548 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            549 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X