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 setprofittarget based on candle open

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

    How to setprofittarget based on candle open

    Hello! Need help setting the profit target to candle open vs entry price. Can someone provide the code for that? Thank you!

    #2
    Hello Edress714,

    Thanks for your post.

    To clarify, are you using the Strategy Builder window or the NinjaScript Editor window to create your strategy?

    When you mention "candle open vs entry price" are you trying to submit a profit target order to the current Open price when an entry order is filled?

    Or, are you trying to set the profit target a set distance away from the Open price when the entry is filled?

    We look forward to assisting further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Bryan.

      I'm trying to set the profit target a set distance away from the Open price when the entry is filled. Using editor
      Last edited by Edress714; 02-25-2024, 02:20 PM.

      Comment


        #4
        Hello Edress714,

        Thanks for your notes.

        You could call SetProfitTarget() in OnBarUpdate() in an unlocked script, set the CalculationMode property to CalculationMode.Price, and assign a price value of the Open[0] offset by a set number of ticks using TickSize.

        For example, the code below would place the profit target 10 ticks above the current Open price.

        Code:
        double ptPrice = Open[0] + 10 * TickSize;
        SetProfitTarget(CalculationMode.Price, ptPrice);
        EnterLong();
        SetProfitTarget(): https://ninjatrader.com/support/help...ofittarget.htm

        Here is a reference sample from the help guide demonstrating modifying the price of stop/target orders which you might also find helpful: https://ninjatrader.com/support/help...of_stop_lo.htm
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thank you. This works! However, it is based on previous candle close, not the current one that initiated the trade.

          Comment


            #6
            Hello Edress714,

            Thanks for your notes.

            If you are running the strategy using Calculate.OnBarClose, this means the strategy will only process logic at the close of each bar. Meaning that Open[0] would refer to the Open price of the bar that just closed.

            To have your strategy process logic intrabar, you would need to set the Calculate mode in your strategy to Calculate.OnPriceChange or Calculate.OnEachTick.

            Calculate.OnPriceChange means OnBarUpdate() logic would process for each change in price. Calculate.OnEachTick means OnBarUpdate logic would process for each incoming tick.

            When using Calculate.OnPriceChange() or Calculate.OnEachTick, Open[0] would refer to the Open price of the currently forming bar.

            See this help guide page for more information about Calculate: https://ninjatrader.com/support/help.../calculate.htm
            Brandon H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by burtoninlondon, Today, 12:38 AM
            0 responses
            9 views
            0 likes
            Last Post burtoninlondon  
            Started by AaronKoRn, Yesterday, 09:49 PM
            0 responses
            14 views
            0 likes
            Last Post AaronKoRn  
            Started by carnitron, Yesterday, 08:42 PM
            0 responses
            11 views
            0 likes
            Last Post carnitron  
            Started by strategist007, Yesterday, 07:51 PM
            0 responses
            13 views
            0 likes
            Last Post strategist007  
            Started by StockTrader88, 03-06-2021, 08:58 AM
            44 responses
            3,983 views
            3 likes
            Last Post jhudas88  
            Working...
            X