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

Profit Target in R

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

    Profit Target in R

    Hello,

    My stop loss is set as follows (one candle below the high or low of the entry candle depending on the trade direction)

    SetStopLoss(@"Long", CalculationMode.Price, Low[0], false);
    SetStopLoss(@"Short", CalculationMode.Price, High[0], false);​


    How do I set the profit target to let's say 20R?

    Thank you



    #2
    Welcome to the forums!

    What does '20R' mean?

    Comment


      #3
      Thanks!

      20R means 20 risk reward ratio

      So if we enter at 100 and the stop loss is at 90, the profit will be (100-90) * 20 = 200

      Comment


        #4
        Hello TraderBCL,

        To do that you would need to calculate the price and then supply that as the value for the SetProfitTarget method. You would need to calculate the price for the target and call that before submitting the entry:

        Code:
        SetStopLoss(@"Long", CalculationMode.Price, Low[0], false);
        SetStopLoss(@"Short", CalculationMode.Price, High[0], false);​​
        
        double priceForTarget = 100;  // calculate your targets price here
        SetProfitTarget(@"Long", CalculationMode.Price, priceForTarget);
        ​
        EnterLong();
        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello TraderBCL,

          To do that you would need to calculate the price and then supply that as the value for the SetProfitTarget method. You would need to calculate the price for the target and call that before submitting the entry:

          Code:
          SetStopLoss(@"Long", CalculationMode.Price, Low[0], false);
          SetStopLoss(@"Short", CalculationMode.Price, High[0], false);​​
          
          double priceForTarget = 100; // calculate your targets price here
          SetProfitTarget(@"Long", CalculationMode.Price, priceForTarget);
          ​
          EnterLong();
          Hi Jesse - thanks for your answer.

          In my example I gave the example of 100, but obviously this price is subject to change for each trade.

          The formula I would need for Long to calculate the target price is as follows:

          TargetPrice = EntryPrice + ((EntryPrice - StopLossPrice) * RRTargeted)

          RRTargeted being an int variable that I could change, but in this case let's take 20.

          Could you help me write this code, as I'm unsure how to translate this into C?

          Thanks a lot!!

          Comment


            #6
            Hello TraderBCL,

            You can make variables for the various items that you need in your formula, the main take away is that you need to price the target order before you submit the entry so the correct target price is used.

            To learn about NinjaScript concepts like generating user inputs and using variables I would suggest watching the strategy builder webinar as a starting point, that tool is very useful for generating code when you are not sure how to write it or use it. That is a good way to step into NinjaScript development. I have included a link to that video below.

            NinjaTrader's Strategy Builder empowers traders of all levels with point-and-click automated trading strategy development. Create your own advanced automated...


            The code you end up using would actually look fairly similar to what you provided however if you use market orders then you won't know the entry price up front to use the Set methods for the targets. If you want to use the actual average fill price you will need to use OnExecutionUpdate to monitor for filled entry orders and then submit targets based on the entry fills. You can see an example of the code to do that here: https://ninjatrader.com/support/help...tionupdate.htm
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ETFVoyageur, Today, 02:15 AM
            5 responses
            29 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by drnoggin, Today, 12:19 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by synthhokie, Today, 12:00 PM
            1 response
            16 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by moneyexe, Today, 11:22 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by stevec1824, Today, 11:00 AM
            2 responses
            8 views
            0 likes
            Last Post stevec1824  
            Working...
            X