Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TrailingStopLosses - SetStopLoss

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

    TrailingStopLosses - SetStopLoss

    I'm trying to build my own trailstop logic...

    I have an idea of how to do it in my head, but I'm just not sure how to approch it in NinjaScript.

    I'd like to use the SetStopLoss function for my trialing stop, so the orders are always at the exchange.

    What I'm thinking is, if there was someway to "get" the current value for the stoploss placed by SetStopLoss, then increment it each tick I'm deeper into profit...

    What command can I use to pull the current stop loss value each time the bar updates?

    Regards,

    Brian

    #2
    Hi Brian, have you tried using the SetTrailStop? It will amend the trailing stop on a tick by tick basis.

    For an idea how to code a trailing stop with the SetStopLoss in the OnBarUpdate, you can take a look at this reference sample - http://www.ninjatrader-support2.com/...ead.php?t=3222
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Yea... I should have been more specific in my first post.

      What I'm trying to do is raise my stop 5 points once I have one point in profit, then use trial tick by tick. As you already know - and have mentioned in other threads - you can't do that with SetTrailStop.

      Against my better judgement, I tried something like this, but it didn't work:


      // If a LONG position is open and we have a profit, modify stop loss
      else if ( invoketrailstoploss == false && usetrailingstop == true && Position.MarketPosition == MarketPosition.Long )
      {
      // Once the price is greater than entry price, adjust stop loss
      if (High[0] >= Position.AvgPrice + (trailstopprofitpoints * 4) * TickSize)
      {
      SetStopLoss(CalculationMode.Price, (Position.AvgPrice - (stoppoints - trailraisestoppoints)));
      invoketrailstoploss = true;
      }

      if (invoketrailstoploss == true)
      {
      OrderType.StopLimit == trailingstopvalue;
      SetTrailStop()

      }

      Comment


        #4
        heyligerb,

        You cannot add the SetTrailStop into the mix. You will have to stay with SetStopLoss() and trail it yourself. Every time you see a higher price, raise the stop loss. If the price goes lower, don't move the stop loss.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Right... which is why I'm asking how I can determine the current stop price.

          If I use SetStopLoss, and say it sets the stop to X based on my logic. How can I determine what X is in the script? Once I know what X is I can mimic a trialing stop.

          OnBarUpdate
          X++

          Brian

          Comment


            #6
            You would have to code it out yourself, a good example of a custom trailstop logic can be found here - http://www.ninjatrader-support2.com/...7&postcount=11
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bortz, 11-06-2023, 08:04 AM
            47 responses
            1,607 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            9 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            19 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            6 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            16 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X