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 not submitting properly

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

    Trailing Stop not submitting properly

    Hi,

    I place an entry order onBarUpdate with EnterLongStopMarket(quantity, High[0] + (entryOrderBuffer * TickSize), "Long" + Instrument.FullName);

    In State.Configure I have SetTrailStop(CalculationMode.Ticks, trailStopBuffer);

    The price enters at 308.65 (on the close price of today's 5 minute NFLX bar to test). A few seconds after entry the strategy is disabled because a stop cannot be placed above the market. Sell 100 StopMarket @ 330.31.

    I have no idea why SetTrailStop (where trailStopBuffer is set as an input = 20) would cause the trailing stop to be ahead of the price by so much. Please help.


    19/08/2019 14:34:59 Strategy 'Gapper/176824384': Entered internal SubmitOrderManaged() method at 19/08/2019 14:34:59: BarsInProgress=0 Action=Buy OrderType=StopMarket Quantity=100 LimitPrice=0 StopPrice=308.65 SignalName='LongNFLX' FromEntrySignal=''
    Strategy 'Gapper/176824383' submitted an order that generated the following error 'Order rejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself.
    19/08/2019 14:35:34 CancelAllOrders: BarsInProgress=0
    Disabling NinjaScript strategy 'Gapper/176824383'

    As a second question, if I wanted to trail the stop at the previous candle High[0] could I do this onBarUpdate?

    Thanks,
    Stefan
    Attached Files

    #2
    Oops didn't mean to delete the topic!

    Comment


      #3
      Hello stefanjagger,

      Thank you for the post.

      From the given details I would not be certain what may have occurred, was this a realtime trade or is this something which you can see happen again using playback?

      If this is something which is happening commonly and you have some general steps used where this happens, we can dive further into that if you would like to detail the steps used. Could you additionally attach a sample of the logic you used when you saw the error for me to review further?


      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        Hi Jesse,

        Thanks for the quick reply.

        I'm seeing some issues with stops not being triggered in backtest data but the original example was based on live data today. Basically I am trying to:
        1. Check for a gap at the close of the first candle of the session
        2. Place pending order (i'm happy for it to cancel if no fill so no advanced trade mgmt needed)
        3. If the working order fills then place a stop loss at the previous High or Low of previous candle
        4. Move the stop with a buffer behind previous bar
        I plan to use this on IB so i'm not sure if passing things around using OnExecution will work either.

        PS - if you can see anywhere else in the code that could be improved I am always happy to learn!

        Thank you for your assistance.

        Regards,
        Stefan

        Comment


          #5
          Sorry I think I posted twice while the post was pending trying to paste code. Did you see the code?

          Comment


            #6
            Hello stefanjagger,

            Thank you for the post.

            I wanted to check, have you attached the correct file? You mentioned using SetTrailStop in your first post, however this sample does not contain SetTrailStop. Are you referring to a stop you are making trail by logic or is this a different sample? Is this sample related to your comments in post #4, that seems to contain unrelated information to post #1 or a different situation, is that correct?

            If post #4 and beyond is a new question, I would suggest creating a new thread for that question so we can work through the items in post #1 here.


            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              It's ok i've worked out the code is fine, it's the way backtesting is done and the fill price guess work based on OHLC that is causing the results to not be real.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by frslvr, 04-11-2024, 07:26 AM
              9 responses
              121 views
              1 like
              Last Post caryc123  
              Started by rocketman7, Today, 09:41 AM
              4 responses
              15 views
              0 likes
              Last Post rocketman7  
              Started by selu72, Today, 02:01 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_Zachary  
              Started by WHICKED, Today, 02:02 PM
              2 responses
              15 views
              0 likes
              Last Post WHICKED
              by WHICKED
               
              Started by f.saeidi, Today, 12:14 PM
              8 responses
              21 views
              0 likes
              Last Post f.saeidi  
              Working...
              X