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

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 owen5819, Today, 02:24 PM
      0 responses
      5 views
      0 likes
      Last Post owen5819  
      Started by OllieFeraher, 05-09-2024, 11:14 AM
      4 responses
      14 views
      0 likes
      Last Post MisterTee  
      Started by dcriador, Today, 12:06 PM
      0 responses
      10 views
      0 likes
      Last Post dcriador  
      Started by dcriador, Today, 12:04 PM
      0 responses
      6 views
      0 likes
      Last Post dcriador  
      Started by cutzpr, Today, 08:54 AM
      0 responses
      11 views
      0 likes
      Last Post cutzpr
      by cutzpr
       
      Working...
      X