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

set take profit on a price that is built by indicator itself

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

    set take profit on a price that is built by indicator itself

    Hi all,

    in strategy builder I have defined a strategy which I want to add a take-profit and stop-loss. I'd like to put them on the price level of a plot that exists in that indicator. Imagine something like the Supertrend where I want to put my stop-loss exactly at that current price level of supertrend indicator. I tried by assigning the condition "if close of current bar equals or greater than indicator plot A then exit position". But I always get an error.

    How can I put the stop-loss on an indicators plot?

    any help appreciated. Thank you in advance.
    Patricia

    #2
    Hello patricia70,

    Thank you for your reply.

    What is the error you got when trying to use the condition "if close of current bar equals or greater than indicator plot A then exit position"? That should work if it's set up correctly, dependent on the indicator you want to use. Could you provide screenshots of the logic that isn't working for you?

    Also, if you're using, say, an Exit() type order, like ExitLongLimit or ExitLongStopMarket for your exit, you can use the price an indicator is at to set those prices for those exits. I would suggest checking that the current indicator value is on the proper side of the market for the order type you are submitting before submitting.

    Thanks in advance; I look forward to assisting you further.

    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate and thanks for coming back to my question. The error that is shown in Control Center -> Log is:
      Strategy 'myStrategy/212092928': Calculated target order price was smaller/equal 0. No target order placed
      my target in strategy builder is defined as following:

      Profit target
      Misc:
      From entry signal: empty (because I use default 1 quantity)
      Mode: price
      Value: Set --> Indicator --> Plot on chart=enabled

      the plot of this indicator is a horizontal line and drawn by following code:
      Code:
      yS1H = chartScale.GetYByValue([B]PreSessionStop1High[/B].GetValueAt(lastPlotCalcIndex));
      startPointDX = new SharpDX.Vector2((float)firstX, (float)yS1H);
      endPointDX = new SharpDX.Vector2((float)lastX, (float)yS1H);
      RenderTarget.DrawLine(startPointDX, endPointDX, Plots[13].BrushDX, Plots[13].Width, Plots[13].StrokeStyle);
      Print("CurrentBar: " + CurrentBar + " PreSessionStop1High: " + PreSessionStop1High[0]);
      I inserted the last print line for debugging purposes and the output is 0. But I don't understand the reason ?

      Last edited by patricia70; 12-08-2020, 02:26 AM.

      Comment


        #4
        Hello patricia70,

        Thank you for your reply.

        What's the indicator that you're using? Not all indicators may be used in the Strategy Builder. If they don't expose the value you need as an actual Plot() or an exposed variable, you may not be able to get the price of that line. I'd need to test on my end to see if it would be feasible to use in the Builder if possible.

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hi Kate,

          before digging into complicated code, I just did simple test. I am going long and I want to have set my target profit at the EMA(14) line. So I did choose the EMA indicator as profit target and entered period=14 with type=PRICE. Am I doing something wrong? it does not work as expected, the buy fill and take-profit fill occur always on the same bar and I don't understand why. Trace fills is enabled and I watch the output console, but nothing helpful information here.

          Can you show me a simple strategy where it enteres a position and chooses an indicator plot line as a target profit, please?

          thank you.
          Patricia

          Comment


            #6
            Hello patricia70,

            Thank you for your reply.

            I've created a simple example Strategy Builder strategy that will enter long if the EMA(14) is at least 10 ticks above the current price. It will then submit a stop market stop loss at 10 ticks below the entry price which stays there, and a profit target limit order that will trail the EMA price as long as the EMA stays above the current price. If the EMA dips below it will remain at the current price.

            Please let us know if we may be of further assistance to you.

            Attached Files
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              no, you misunderstood. The position is entered by any other logic. The TAKE PROFIT (target) should be at the price level of the EMA(14) and move towards it.

              Comment


                #8
                Hello Patricia,

                Thank you for your reply.

                In the example we check to ensure that the price of the EMA is greater than 10 ticks above the current price before entering since for a long entry a profit target limit order must be placed above the current price. 10 ticks is simply an arbitrary number of ticks that was chosen so the profit target doesn't immediately fill. The profit target that gets set then is placed at the current EMA price and then follows the EMA, only stopping if the EMA is below the current price (as moving the order below the current price would cause a rejection since it would be on the wrong side of the market. This is an example only and if would be expected that you would revise it with your own logic.

                Please let us know if we may be of further assistance to you.
                Kate W.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Kate,

                  I downloaded the example you attached to see how this works. Thanks for your effort and assistance. After looking at your file with the strategy builder first I was puzzled because I didn't know we can also set the stop-loss and take-profit in the [Conditions and Actions] configuration. I used the [Stops and Targets] configuration before.

                  1st question)
                  when do we have to use [Conditions and Actions] or [Stops and Targets] tab? is there best practice or how do you suggest to handle them?

                  2ndquestion)
                  In the actions list I see there are five different options we can choose to exit a short or long position. In the example of long positions these are:
                  1. Exit long position
                  2. Exit long position by a limit order
                  3. Exit long position by a MIT order
                  4. Exit long position by a stop limit order
                  5. Exit long position by a stop order

                  When and how do the fills occur for these options, can you explain in detail please? I guess something like that ...
                  1. closing actual long position (Sell Market), the position is liquidated immediately without the need of any price level set
                  2. placing a Sell Limit order at a defined price level which is higher than the current price
                  3. placing a Sell Limit MIT order at a defined price level which needs to be higher than the current price. When level is touched, order will be converted to a Sell Market
                  4. placing a Sell Stop order (the classical stop-loss order) at a defined price level which needs to be lower than the current price. Order will get filled at or better than the defined stop level.
                  5. placing a Sell Stop order (the classical stop-loss order) at a defined price level which needs to be lower than the current price. When stop level is reached, order is converted to Sell Market
                  I remember to have read somewhere on the forum that a MIT order requires attention: if not filled on the bar it is placed it would be automatically canceled. I'm not sure about if understood correctly, maybe you can give some more insight to that.

                  Conclusion ?
                  In case I'm in a long position and I want to set the take-profit (higher than current price) to an indicator that plots a horizontal line, I need to configure this under [Conditions and Actions] and NOT under [Stops and Targets] as originally expected and already tried?

                  Comment


                    #10
                    Hello patricia70,

                    Thank you for your reply.

                    Any time your stop loss or profit target needs to be at a different level based on a changing value depending on the entry, you'd want to use Exit methods instead of Set methods for that stop or target. You can't mix Exit and Set methods, so if you need one to be variable, you'd want to use Exit methods for that.

                    You're right about perfect on that assessment of the different order type. #4 would be a sell stop limit, but otherwise you've basically hit the nail on the head there.

                    As far as if not filled on the bar on which it's placed, that actually would be in regards to Limit orders. By default, a limit order is cancelled if the conditions it was placed under are no longer true. However, these may be kept alive and then canceled manually if need be. This would require manual programming. An example of keeping limit orders alive may be found in our help guide here:



                    And finally, yes, I'd recommend using the kind of approach in my example with the Exit orders using the Conditions and Actions rather than the Stops and Targets.

                    Please let us know if we may be of further assistance to you.
                    Kate W.NinjaTrader Customer Service

                    Comment


                      #11
                      much appreciate your reply dear Kate. Helped a lot. THANK YOU!

                      Comment


                        #12
                        Originally posted by NinjaTrader_Kate View Post
                        Hello patricia70,

                        Thank you for your reply.

                        I've created a simple example Strategy Builder strategy that will enter long if the EMA(14) is at least 10 ticks above the current price. It will then submit a stop market stop loss at 10 ticks below the entry price which stays there, and a profit target limit order that will trail the EMA price as long as the EMA stays above the current price. If the EMA dips below it will remain at the current price.

                        Please let us know if we may be of further assistance to you.
                        hi I am new here I download the file I put in ninjatrade add on where I need to go , how this works to see this example?

                        Comment


                          #13
                          Hello alasdeaguila,

                          Thank you for your reply.

                          Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

                          Note — To import NinjaScripts you will need the original .zip file.

                          To Import:
                          1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
                          2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
                          3. Select the downloaded .zip file
                          4. NinjaTrader will then confirm if the import has been successful.
                          Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

                          Once installed, you may add the strategy to a chart by:
                          • Right-click your chart > Strategies... > Select the Strategy from the 'Available' list on the left > Add > Check enabled checkbox > OK
                          The strategy logic may be viewed by opening a new Strategy Builder window and selecting its name in the dropdown on the first page. You can then use the navigation buttons to advance through and view the strategy logic.

                          Here is a short video demonstration of the import process:Please let me know if I can be of further assistance.
                          Kate W.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Philippe56140, 04-27-2024, 02:35 PM
                          7 responses
                          56 views
                          0 likes
                          Last Post kevinenergy  
                          Started by arunkumar3, 08-25-2023, 12:40 PM
                          3 responses
                          169 views
                          0 likes
                          Last Post Trader2024!  
                          Started by DJ888, 04-26-2024, 10:57 PM
                          2 responses
                          17 views
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Started by port119, 04-27-2024, 02:43 PM
                          3 responses
                          31 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by sastrades, 01-31-2024, 10:19 PM
                          13 responses
                          204 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Working...
                          X