Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with stoploss code

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

    Problem with stoploss code

    Hi,

    I am writing a code for a dynamic stoploss as attached. However, upon entry, the stoploss is wrongly set at the entry price. This results in the position being closed immediately.

    My original intention is to enter a stoploss that will only be removed after I close my position. Is there any way to rectifiy this problem?
    Attached Files

    #2
    Hello ggcow,
    Thanks for your post and I am happy to assist you.

    The ATR[0] value can be say .1 or say 1.2. If you set the CalculationMode to Ticks, then you are setting a 0 tick or 1 tick stop. As such your stops will be run at no time. Please assign a more realistic stop, like,
    Code:
    SetStopLoss(“”,CalculationMode.Ticks, 10, false); // a 10 tick stop
    Also, you can set the stop when the market position is flat, and later adjust it as needed.

    Please refer to this reference sample to modify stop/target price http://ninjatrader.com/support/forum...ead.php?t=3222

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Now I get it. Thanks.

      Can you tell me how to code ATR[0] multipled by 1000?

      Comment


        #4
        Hello ggcow,
        Glad you could figure out the issue.

        The code will be
        Code:
        ATR[0] * 1000
        If you are trying to do the same from the strategy wizard, then please use the Offset field for the same (see attached picture).

        Please let me know if I can assist you any further.
        Attached Files
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Hi,

          Thanks man. May have to bother you again.

          Pls see the attachment. My intention of my stoploss code is to submit it once without changing it until I exit my position. However, as the bars get updated, the stoploss get shifted.

          In my case, the Stoploss get shifted after 2 bars. Is there a way to improve my code to ensure that my initial stoploss do not get shifted?

          Thanks man.
          Attached Files

          Comment


            #6
            Hello ggcow,
            Thanks for your post and I am happy to assist you.

            The conditions 5, 6, 7 and 8 are resubmitting the SetStopLoss as per the conditions. You need to remove them so that the SetStopLoss do not get reassigned.

            If you want to set the stop once, and you are coding via the strategy wizard, then just assign the Stop via the Stops and Target (last step, please see attached screenshot).

            Please let me know if I can assist you any further.
            Attached Files
            JoydeepNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            648 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            573 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            575 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X