Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Call profit target in OnBarUpdate()?

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

    Call profit target in OnBarUpdate()?

    I am working on a strategy and I would like to submit a sell order only if the current price of the instrument is above the target price. I don't want to issue a sell order as soon as the price reaches the profit target, I want to use a crossover to trigger a sell order IF the current price is above the Profit Target price.

    Currently, I am using the percentage mode to set the profit target.

    #2
    Hello herbnderby,

    Thank you for your post.

    I'd recommend using an exit order in lieu of a profit target in that case. You can set a condition to say if the current price is above whatever price you've determined as the profit target price, then submit a market order to exit. If you're using SetProfitTarget, that would execute when the order price is hit.

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

    Comment


      #3
      Hello Kate,

      Thank you for the quick response.

      Is there a way I can set the profit target price as a function of the entry price? Like, ProfitTargetPrice = 1.08 * entryPrice

      Thank you

      Comment


        #4
        Hello herbnderby,

        Thank you for your reply.

        Sure, you could certainly do that, you'd just want to then use that ProfitTargetPrice variable in your condition for entry to compare against the current close to see if the close price has exceeded it.

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

        Comment


          #5
          Can you elaborate a bit further? What does the code look like to call the entry price of a strategy?

          Comment


            #6
            Hello herbnderby,

            Thank you for your reply.

            You can get the average entry price for the position by using Position.AveragePrice.

            So you could do something like this (we're assuming you're in a long position here):

            Code:
            double ProfitTargetPrice = 1.08 * Position.AveragePrice;
            if(Close[0] > ProfitTargetPrice)
            {
                 ExitLong();
            }
            Please let us know if we may be of further assistance to you.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            46 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            126 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            66 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X