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 Touch-Ups, Today, 10:36 AM
          0 responses
          5 views
          0 likes
          Last Post Touch-Ups  
          Started by geddyisodin, 04-25-2024, 05:20 AM
          8 responses
          61 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by jxs_xrj, 01-12-2020, 09:49 AM
          4 responses
          3,289 views
          1 like
          Last Post jgualdronc  
          Started by Option Whisperer, Today, 09:55 AM
          0 responses
          5 views
          0 likes
          Last Post Option Whisperer  
          Started by halgo_boulder, 04-20-2024, 08:44 AM
          2 responses
          24 views
          0 likes
          Last Post halgo_boulder  
          Working...
          X