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 develop custom strategy that also manage stop and profit target

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

    How to develop custom strategy that also manage stop and profit target

    Hi,

    Just wonder if there is any good resource on NT site or the web on programing logic to manage stop and profit targets (similar as in strategy builder) in my custom strategy developed via Ninjatrader script coding?

    Appreciate your feedback

    Thanks

    #3
    Thanks Chelsea.

    Actually at this stage I want to develop and back-test strategy. I want the strategy to ONLY give me signal to entry and exit, as I don't have real time feed and wont use NT to really place and execute order.
    I have my strategy already developed by coding but NOT strategy builder. for exit condition, besides my own condition, I want to add code to trigger stop loss and profit target as well. Would like to see if you have some simple example to show me how to do.

    Much Appreciate your help !

    MC
    Last edited by mikechan883; 01-15-2021, 11:51 PM.

    Comment


      #4
      Hi Mike
      If your strategy is not written for NINJA, what you have to do is contact your broker and ask him for the API documentation to connect to it to attach the documentation to develop it. It's not very clear what you want to do.

      Comment


        #5
        Hi mbcito,

        My strategy is already written in ninja script but dont know how to add exit condition for stop loss or profit target on top.
        e.g based on the provided MA cross over strategy that comes with NT8 as an example, how can I add code on top for stop loss or profit target?

        Comment


          #6
          Hello mikechan883,

          In addition to placing orders, when a condition evaluates as true, you can draw a drawing object, write to a text file, send an email, trigger an alert...

          What would you like to do?

          Are you adding prints to ensure the condition is true when you are expecting?
          https://ninjatrader.com/support/foru...121#post791121
          Chelsea B.NinjaTrader Customer Service

          Comment


            #7
            Hi Chelsea

            sorry i think you get me wrong. The strategy in NT8 already indicate when to buy and exit order in the chart when backtesting strategy. what i want is some sample code on how to code on top of my ninjascript code to refine the buy and exit criteria

            eg in a simple ma crossover strategy say
            buy when SMA(10)cross above SMA(50); sell when SMA(10)cross below SMA(50)

            i dont know how to enhance my code say
            buy when SMA(10)cross above SMA(50)or reach 30% already; sell when SMA(10)cross below SMA(50)or already lose 5%

            thanks

            Comment


              #8
              Hello mikechan883,

              Below I am providing a link to a forum post with helpful information about getting started with NinjaScript and C#, and includes videos to help you get started.


              As an example:
              if (CrossAbove(SMA(10), SMA(50), 1)
              {
              EnterLong();
              }
              Chelsea B.NinjaTrader Customer Service

              Comment


                #9
                I know the code for crossover part. How about the ninja script code for the profit and loss condition as marked in bold below

                buy when SMA(10)cross above SMA(50)or reach 30% profit already; sell when SMA(10)cross below SMA(50)or already lose 5%

                Comment


                  #10
                  Hello mikechan883,

                  Included are publicly available links to 3rd party educational sites.

                  The vertical lines are used for OR.
                  if (condition1 == true || condition2 == true)
                  C# logical operators perform logical negation (`!`), conjunction (AND - `&`, `&&`), and inclusive and exclusive disjunction (OR - `|`, `||`, `^`) operations with Boolean operands.


                  Multiply a value by 1.3 to add 30% to the value.
                  There are numerous situations where you might need to add a percentage to a listed price. Figuring tax is probably the most common, but other fees, such as shipping or handling, may also be based on a percent of the list price. The calculation is carried out with some straightforward arithmetic.


                  Multiply a value by .05, then subtract this from the original value to subtract 5% from the value.
                  Many math calculations involve subtracting percentages. Two simple methods allow you to do this.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #11
                    Chelsea,

                    you get me wrong. I know atm strategy sample built by NT8 strategy builder can mange trade to meet profit target, scaling out, and stop loss etc, while other NT8 samples say simple MA Crossover are built by Ninjascript.

                    my question here is very simple: how can i integrate them together in Ninjascript as i said before:

                    buy when SMA(10)cross above SMA(50)

                    exit when one of the following are met
                    1) reach 30% profit already
                    2) SMA(10)cross below SMA(50)
                    2) already lose 5%

                    Sample of ninjascript code will help a lot
                    Last edited by mikechan883; 01-22-2021, 02:35 AM.

                    Comment


                      #12
                      Hello mikechan883,

                      This is Jim responding on behalf of Chelsea who is out of the office at this time.

                      Chelsea has given example code demonstrating how to create the crossover condition and how values can be multiplied to find a percentage difference.

                      If you would like to see when the unrealized PnL of the position has reached 30% profit, you could check some thing like the following in the Strategy Builder and press the View Code button to see the resulting NinjaScript syntax.

                      Click image for larger version

Name:	NinjaTrader_2021-01-22_10-19-53.png
Views:	362
Size:	26.7 KB
ID:	1137950

                      If you would like to see when the unrealized PnL of the position has dropped 5% profit, you could check some thing like the following in the Strategy Builder and press the View Code button to see the resulting NinjaScript syntax.

                      Click image for larger version

Name:	NinjaTrader_2021-01-22_10-20-30.png
Views:	362
Size:	25.9 KB
ID:	1137949
                      These can be tied with OR operators or with separate conditions.

                      Please let us know if you have any questions.
                      JimNinjaTrader Customer Service

                      Comment


                        #13
                        Great, thanks Jim and Chelsea !

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by TraderBCL, Today, 04:38 AM
                        2 responses
                        12 views
                        0 likes
                        Last Post TraderBCL  
                        Started by martin70, 03-24-2023, 04:58 AM
                        14 responses
                        105 views
                        0 likes
                        Last Post martin70  
                        Started by Radano, 06-10-2021, 01:40 AM
                        19 responses
                        607 views
                        0 likes
                        Last Post Radano
                        by Radano
                         
                        Started by KenneGaray, Today, 03:48 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post KenneGaray  
                        Started by thanajo, 05-04-2021, 02:11 AM
                        4 responses
                        471 views
                        0 likes
                        Last Post tradingnasdaqprueba  
                        Working...
                        X