Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

trailing stop

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

    trailing stop

    Hi

    I would like to put a trailing stop to my script when the market hit 2 ticks below my target, basically, if my target is 50, when the market hit 48, move up the stop to Position.AvgPrice + 2*TickSize

    i calculate my target with 2 times the ATR(10) (average true range) + the Position.AvgPrice, but the value of the ATR when the position is open

    here the part of my script:

    entryOrderAchat = EnterLongLimit(1, Close[0], "divergence haussiere 1");
    atrAchat = CurrentBar;

    }


    if (Position.MarketPosition == MarketPosition.Long && High[0] > Position.AvgPrice + 2*ATR(10)[atrAchat] - 2*TickSize)
    {
    // Checks to see if our Stop Order has been submitted already
    if (stopOrderLong != null && stopOrderLong.StopPrice < Position.AvgPrice)
    {
    // Modifies stop-loss to breakeven + 2 tick
    stopOrderLong = ExitLongStop(0, true, stopOrderLong.Quantity, Position.AvgPrice+2*TickSize, "Trailing Stop div haussiere 1", "divergence haussiere 1");
    }

    it is not working... i don't know if it is because the ATR is everytime a new value after each new bar or if it is anything else... the really weird stuff is that if i remove the 2* before ATR(10)[atrAchat] in the condition, it is look to take the trailing stop but with only 1 atr...

    can you help ?

    #2
    Hello Thomas79,

    So that I may further assist you could you answer the following questions.

    Do you see any error messages in the Log tab of the Control Center?

    Are you checking the values of the ATR to make sure that is the value that you would like set it to? Here is a link to our support forums that goes over how to debug your code which comes in handy if when writing custom code to view the values.
    http://www.ninjatrader.com/support/f...ead.php?t=3418

    Note as well that you can enable TraceOrders to see the status of the orders that you try to submit, for more information see the following link.
    http://www.ninjatrader.com/support/f...ead.php?t=3627

    You can also use the SetTrailStop() method to be able to set a trailing stop so that you would not have to calculate it manually. See our Help Guide on SetTrailStop from the link below.
    http://www.ninjatrader.com/support/h...ttrailstop.htm


    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hi

      it is not working because the script take a different atr at each new bar, it is always take the new value of the ATR indicator... so because i don't find the solution to call the value of the ATR we the position is open...
      is it possible to call the value of the targeroder...

      for example if the targetorder value is 141.73, a way to call the value 141.73... like:

      if (Position.MarketPosition==MarketPosition.Long && High[0] >= "Value of targetorder" - 2*TickSize)

      Comment


        #4
        Hello Thomas79,

        You can create a new variable that will save the value of an order to be able to use it for calculation purposes.

        Alternatively, you can check the limit price of an order inside of OnOrderUpdate() if you would like.
        http://www.ninjatrader.com/support/h...rderupdate.htm


        Let us know if we can be of further assistance.
        Last edited by NinjaTrader_JC; 09-12-2012, 07:11 AM.
        JCNinjaTrader Customer Service

        Comment


          #5
          Hi

          The link than you gave me is the like of this post, is it a mistake ?

          Also, do you have a example to create a new variable that will save the value of an order to be able to use it for calculation purposes ? i don't see how to create this variable to save the value of the the order...

          Comment


            #6
            Hello Thomas79,

            I fixed the link on my previous reply.

            It would be like the atrAchat variable you created for use with the CurrentBar. Here you can see a reference about declaring variables that you may read on our Help Guide.
            http://www.ninjatrader.com/support/h...sic_syntax.htm

            There is also a forum post about creating a user defined variable as well that you may view.
            http://www.ninjatrader.com/support/f...ead.php?t=5782


            Let me know if we can be of further assistance.
            JCNinjaTrader Customer Service

            Comment


              #7
              Hi

              i don't understand where on this link http://www.ninjatrader.com/support/h...rderupdate.htm it is show how to call the level of a exitlonglimit().... if my exitlonglimit is 102.02, i would like to know how to call 102.02

              my problem is that the calculation mode of 102.02 is with an indicator call ATR and i need to use the value of 102.02 for the condition of my trailing stop...

              If i call the value of the ATR when the position is opened, it is not working (as my first post)

              i when i create a variable like double atrAchat = ATR (10)[0] and after that i use atrAchat the script is always take the new value of the atr (what is logical for me)... but i want to call the value of the atr when the position is opened...

              So i would like to either call the value of the atr indicator when the position is opened (so in the past) or the value of the exitlonglimit order... and it is look like not possible

              Comment


                #8
                Hello Thomas79,

                Can you try the following code to get the value of the ATR since the position entry to see if it is going to be what you are looking for.

                Code:
                ATR(10)[BarsSinceEntry()]
                This is a link to our Help Guide that explains what BarsSinceEntry() will return.
                http://www.ninjatrader.com/support/h...sinceentry.htm

                Happy to be of further assistance.
                JCNinjaTrader Customer Service

                Comment


                  #9
                  Hi Ninja Trader JC

                  i find the way to call the limit price

                  targetOrder.LimitPrice

                  thx a lot for your help.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by sjsj2732, Yesterday, 04:31 AM
                  0 responses
                  36 views
                  0 likes
                  Last Post sjsj2732  
                  Started by NullPointStrategies, 03-13-2026, 05:17 AM
                  0 responses
                  287 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  287 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  133 views
                  1 like
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  95 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Working...
                  X