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 amousaber, Today, 09:30 AM
            0 responses
            9 views
            0 likes
            Last Post amousaber  
            Started by suraj, Today, 08:51 AM
            0 responses
            6 views
            0 likes
            Last Post suraj
            by suraj
             
            Started by calmcosmia, Yesterday, 03:07 PM
            6 responses
            27 views
            0 likes
            Last Post karenmkrohn  
            Started by sofortune, 05-16-2024, 11:45 PM
            5 responses
            37 views
            0 likes
            Last Post sofortune  
            Started by Likomatervy, Today, 05:35 AM
            0 responses
            9 views
            0 likes
            Last Post Likomatervy  
            Working...
            X