Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Variable Stop Loss and Profit Target

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

    Variable Stop Loss and Profit Target

    I am trying to use Strategy Builder to mark a specific signal bar if certain criteria are made. The order entry will occur either 1 tick above or below that signal bar if prices cross that mark within the next 3 bars. I'd like to take certain info from that signal bar and use it to place my stop loss and profit target. I need the stop loss to be 1 tick above or below the signal bar (not just the previous bar to the order entry). I also want my profit target to be the same size as the signal bar (in ticks). See the attached screenshot to see how I am currently capturing that info. For some reason it doesn't seem to be working. When an order is triggered, it is almost immediately stopped out because the stop loss is placed right next to order entry and not above or below the signal bar. Any idea on what I'm doing wrong?
    Attached Files

    #2
    These are the errors I get when running it.
    Attached Files

    Comment


      #3
      Hi srtrader, thanks for posting.

      It's likely the stop loss is too close to the market price to be effective. Typically if you have a stop loss this close to the market price, you will need error handling logic within OnOrderUpdate in the case where the price moves before the order get submitted and the order is rejected. Having rejection/error handling logic in OnOrderUpdate will let you re-submit an order if it gets rejected.

      First test your strategy by placing your stop loss further away from market price and see if the same error happens.

      Kind regards,
      -ChrisL

      Comment


        #4
        That's the issue I'm having though, the strategy I've written is not putting the stop loss in the correct spot. I'm not sure how to code it differently in the strategy builder. It looks like it should work but it's not.

        Comment


          #5
          Hi srtrader, could you please post some screen shots of the strategy you made? I will need some examples of what your strategy code is doing in order to help futher.

          Kind regards,
          -ChrisL

          Comment


            #6
            No problem here you go. I've attached a screenshot of the chart with an example of the setup and what I'm trying to accomplish and screenshots of the Strategy Builder. The signal bar and order entry seem to work fine, it's just the placement of the stop loss and target that seems to not work properly. Let me know if you need more info or clarification on this. Thanks again so much for the help!
            Attached Files

            Comment


              #7
              Hi srtrader, I appreciate the screenshots. The SetStopLoss and SetProfitTarget methods can not take data from the script while it is running. The stop and target are set up in State.Configure so you can only use hard coded values for the stop and target method. You must use Exit orders within your sets to get a stop and target to function this way. See here for an example:



              Kind regards,
              -ChrisL

              Comment


                #8
                This is great! I think I'm understanding a bit more now. This has been one of the missing links to a few of the strategies I'm developing. Thanks again!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                50 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
                69 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