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 habeebft, Today, 07:27 AM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_ChristopherS  
            Started by AveryFlynn, Today, 04:57 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by Max238, Today, 01:28 AM
            4 responses
            37 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by r68cervera, Today, 05:29 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by geddyisodin, Today, 05:20 AM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X