• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trailing the Low or High of Previous Bars to Exit

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

    Trailing the Low or High of Previous Bars to Exit

    I have some code generated in the Strategy Wizard that I think should trail the low (for longs) or high(for shorts) of x bars back to establish an exit stop. Here is the code for that concept:
    Code:
                // Condition set 3
                if (Position.MarketPosition == MarketPosition.Long)
                {
                    ExitLongStop(Low[BarsBack] + -1 * TickSize, "EBLOut", "EBLong1");
                }
    
                // Condition set 4
                if (Position.MarketPosition == MarketPosition.Short)
                {
                    ExitShortStop(High[BarsBack] + 1 * TickSize, "EBSOut", "EBShort1");
                }
    Where BarsBack can be anything between 1 and 3 in my testing. Here's the problem. I'm using a simple ma crossover to get into the position but the only thing that gets me out is either a stop loss (when I include it in the code) or a cross in the opposite direction. As near as I can tell the code above does nothing. Do you have some reference code for implementing a bar-by-bar trailing stop to preserve profit but exit when things start to turn? If not, can you tell mw what is wrong with the code above? Seems pretty straight forward but doesn't seem to work at all.
    Thanks
    DaveN

    #2
    Hello,

    You may have a reversal orders or SetStopLoss() orders active when you place your Exit's. Here are the 2 reasons it won't work:


    Methods that generate orders to exit a position will be ignored if a strategy position is open and:
    • <LI class=rvps1>An order submitted by an enter method (EnterLongLimit() for example) is active and this entry order is used to open a position in the opposite direction
    • An order submitted by a set method (SetStopLoss() for example) is active
    BenNinjaTrader Customer Service

    Comment


      #3
      What is this: <LI class=rvps1> ?

      Comment


        #4
        AN HTML tag. You can ignore it.

        Originally posted by LarryS View Post
        What is this: <LI class=rvps1> ?

        Comment


          #5
          This old post, but i found a tool to Trailing the Low or High of Previous Bars to Exit

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Vincere, Today, 04:38 AM
          0 responses
          2 views
          0 likes
          Last Post Vincere
          by Vincere
           
          Started by trader_rick, Today, 04:02 AM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_ChrisSch  
          Started by percma, Today, 02:51 AM
          0 responses
          5 views
          0 likes
          Last Post percma
          by percma
           
          Started by Abilene, Today, 01:27 AM
          0 responses
          15 views
          0 likes
          Last Post Abilene
          by Abilene
           
          Started by simjs, Yesterday, 08:11 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_ChrisSch  
          Working...
          X