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 stop entry order

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

    Trailing stop entry order

    Would it be possible to use trailing stop entry order aka market entry order which trails the price. Another thing I would like to know is if I could use this kind of order type with SnR levels that I have manually marked down on the chart?
    I'll give an example how the strategy would look:
    1. I mark down a support or resistance level
    2. If price gets as near as 20 ticks from the SnR level, the trailing stop entry order is automatically set 30 ticks behind the price
    3. As price moves closer to SnR level, so is the trailing stop entry moving towards the price
    4. If price turns around and moves 30 ticks in the opposite direction, then the stop entry order is triggered
    5. If price breaks through the SnR level and moves additional 10 ticks, then the trailing stop entry order is canceled and no trade is taken

    #2
    Hello KarlEST,

    Thanks for your post.

    Custom logic could be used to control EnterLongStopMarket(). You could consider checking the DrawObjects collection for a specific line to read the price from the line's anchor, and compare that anchor to the current price to adjust the EnterLongStopMarket() order.

    See the attached example script which demonstrates detecting a manually drawn object.

    And, see the help guide documentation below.
    EnterLongStopMarket(): https://ninjatrader.com/support/help...stopmarket.htm
    DrawObjects: https://ninjatrader.com/support/help...rawobjects.htm

    Let us know if we may assist further.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thank You Brandon, I got the example script working, when I open the chart and add it as an indicator. I get the line's anchor end and start price printed in the output. The only part which is not working is the last line in the script : RemoveDrawObject(globalLine.Tag.ToString()); - It should remove the line from the chart, right? It isn't doing it.

      The bigger problem is that for some reason I can't find this indicator with strategy builder in the "Conditions and Actions" screen. I also tried copying the main logic part of the indicators code directly to my strategy's code, but then it doesn't work and nothing gets printed out in the output.

      The main logic part of the indicator code being:

      // Loops through the DrawObjects collection via a threadsafe list copy
      foreach (DrawingTool draw in DrawObjects.ToList())
      {
      // Finds line objects that are attached globally to all charts of the same instrument
      if (draw is DrawingTools.Line)
      {
      DrawingTools.Line globalLine = draw as DrawingTools.Line;

      //prints its starting price and end price
      Print("Start: " + globalLine.StartAnchor.Price + " End: " + globalLine.EndAnchor.Price);

      RemoveDrawObject(globalLine.Tag.ToString());
      }
      }

      Am I leaving something out when using this code directly in the strategy's code?

      Comment


        #4
        Got it working. Had to use "draw.IsUserDrawn" in the if statement.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by fx.practic, 10-15-2013, 12:53 AM
        5 responses
        5,406 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by Shai Samuel, 07-02-2022, 02:46 PM
        4 responses
        98 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by DJ888, Yesterday, 10:57 PM
        0 responses
        8 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        160 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Yesterday, 09:29 PM
        0 responses
        9 views
        0 likes
        Last Post Belfortbucks  
        Working...
        X