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 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 judysamnt7, 03-13-2023, 09:11 AM
          4 responses
          57 views
          0 likes
          Last Post DynamicTest  
          Started by ScottWalsh, Today, 06:52 PM
          4 responses
          36 views
          0 likes
          Last Post ScottWalsh  
          Started by olisav57, Today, 07:39 PM
          0 responses
          7 views
          0 likes
          Last Post olisav57  
          Started by trilliantrader, Today, 03:01 PM
          2 responses
          19 views
          0 likes
          Last Post helpwanted  
          Started by cre8able, Today, 07:24 PM
          0 responses
          9 views
          0 likes
          Last Post cre8able  
          Working...
          X