• 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
    DenNinjaTrader 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 mulshah, Yesterday, 11:12 PM
          0 responses
          2 views
          0 likes
          Last Post mulshah
          by mulshah
           
          Started by tvaughan4, Yesterday, 10:46 PM
          0 responses
          0 views
          0 likes
          Last Post tvaughan4  
          Started by digibob, Yesterday, 10:01 PM
          0 responses
          1 view
          0 likes
          Last Post digibob
          by digibob
           
          Started by ptertich, Yesterday, 09:59 PM
          0 responses
          2 views
          0 likes
          Last Post ptertich  
          Started by sledge, Yesterday, 06:11 PM
          1 response
          12 views
          0 likes
          Last Post sledge
          by sledge
           
          Working...
          X