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 pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          149 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Started by mattbsea, Today, 05:44 PM
          0 responses
          5 views
          0 likes
          Last Post mattbsea  
          Started by RideMe, 04-07-2024, 04:54 PM
          6 responses
          33 views
          0 likes
          Last Post RideMe
          by RideMe
           
          Started by tkaboris, Today, 05:13 PM
          0 responses
          5 views
          0 likes
          Last Post tkaboris  
          Started by GussJ, 03-04-2020, 03:11 PM
          16 responses
          3,283 views
          0 likes
          Last Post Leafcutter  
          Working...
          X