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

trailing stop loss

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

    trailing stop loss

    Hi,
    I'm using this code

    if (Positions[0].GetUnrealizedProfitLoss(PerformanceUnit.Ticks) > 4)
    {
    SetTrailStop(CalculationMode.Ticks, 2);
    }
    To set the trailing stop loss at 2 ticks over my average price, I do the same using :

    if (Positions[0].GetUnrealizedProfitLoss(PerformanceUnit.Ticks) > 2)
    {
    SetTrailStop(CalculationMode.Ticks, 0);
    }

    And it doesn't give me any error and change my stop loss at my avergae price, but if i want to put my stop loss over my BUY position it doesn't change the stop loss.. Am i doing something wrong?
    Notice that at the beginning of the trade i set both take profit and stop loss

    #2
    Hello AlessioCianini12,

    Thank you for your reply.

    In my testing I note that when I try to initially set the trailing stop to 2 ticks below the entry point and then move it to the average entry price later, it immediately tries to submit the stop to the same price as the entry and gets rejected. I will need to do some digging to see if this is expected, but it's the very end of my day today and I will check on that first thing tomorrow.

    Thanks in advance for your patience.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply, the thing is I'd like to have that when my position goes in profit by 2 ticks to put the stop loss at the entry price, so if the price goes down I just break even, and then if the profit goes to 4 id like to put the stop loss in profit of 2 ticks. I think that using the calculation mode ticks itnever put your stop lossin a price that'sin profit for your positions, maybe i should use the calculation mode price? thanks.

      Comment


        #4
        Hello AlessioCiani,

        Thank you for your reply.

        If you initially place a Trail Stop 2 ticks below the entry price, when 2 ticks of profit are reached it would already be at breakeven as it will tick upwards by 1 tick for each tick of profit. There wouldn't be the need to change it - it will automatically trail towards the market price as ticks in profit are reached and does not move away from the current market price if the price reverses back towards it.

        With SetTrailStop() CalculationMode.Price is useless as this is a set value that never changes so it will not "trail' the current market price, thus CalculationMode.Price cannot be used.

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          There is another problem, if i do it in playback it moves the stoploss at 0, if i do it with the simulated account no, the code is just this:

          And both the condition where filled since the ticks arrived at 6
          if ( BarsInProgress == 0)
          {
          if(Position.MarketPosition != MarketPosition.Flat)
          {
          if (Positions[0].GetUnrealizedProfitLoss(PerformanceUnit.Ticks) > 3)
          {
          SetStopLoss(CalculationMode.Ticks, 0);
          }


          }

          }

          Comment


            #6
            Hello AlessioCianini12,

            Thank you for your reply.

            I would try using a variable to set the stop loss value and then resetting that variable back to the initial value once the position returns to flat. I'd take a look at the example my colleague Chelsa provided on this forum post:

            In the documentation it states: "Should you call this method to dynamically change the trail stop price in the strategy OnBarUpdate() (https://ninjatrader


            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by GLFX005, Today, 03:23 AM
            0 responses
            1 view
            0 likes
            Last Post GLFX005
            by GLFX005
             
            Started by XXtrader, Yesterday, 11:30 PM
            2 responses
            11 views
            0 likes
            Last Post XXtrader  
            Started by Waxavi, Today, 02:10 AM
            0 responses
            6 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by TradeForge, Today, 02:09 AM
            0 responses
            14 views
            0 likes
            Last Post TradeForge  
            Started by Waxavi, Today, 02:00 AM
            0 responses
            3 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Working...
            X