Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Conditional Trail Stop

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

    Conditional Trail Stop

    I am trying to have a stop order trail the market after certain conditions apply. I have the following code snippet in the OnBarUpdate section of code:

    if(Position.MarketPosition==MarketPosition.Long && (MAX(High,(Math.Max(0,BarsSinceEntry("LongEntry")) ))[0]) >= Position.AvgPrice + .0050)

    stopOrder = ExitLongStop(1, Position.AvgPrice + (MAX(Low,(Math.Max(0,BarsSinceEntry("LongEntry"))) )[0]) - .0020, "TrailLongTarget", "LongEntry") ;

    Basically what I am trying to do is on each new bar check to see if any high since I entered the long position is > entry price + 50 pips. If so a stop order should be place under the highest low since entry - 20 pips. And then update if a new higher low would occur. I also have a hard stop order placed in the onExecution section. Could the problem be having to different stop orders? If so how do I get around this. Otherwise any ideas on how to make this work. Thanks!

    GT

    #2
    Hello,


    Here are a couple ideas:

    - Instead of using " - .0020" and " + .0050" use "20 * TickSize" and "50 * TickSize".

    - When you enter your LongStop, save your order price as something like my_long_stop_price then do this to exit it:
    ExitLongStop(my_long_stop_price, "LongEntry");

    - You do not show where you are re-entering your Long Stop so I cannot help you with the trailing part.
    DenNinjaTrader Customer Service

    Comment


      #3
      Thanks for your help. I reworked the math and found out the code was adding the entry price and the high price together. Since cannot place sell stop above the market it would never place the order. Thanks again.

      GT

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      569 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      548 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X