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

StopMarket cancelled by stoploss before entry

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

    StopMarket cancelled by stoploss before entry

    Hi I am trying to make a strategy where when it reaches a certain price, it would enter a trade. So in my approach, I am using a stop market for entering trades based on the specific price. But when I'm backtesting, I realized that my entry are stopped out by the stop loss before even entering. In my case, I only want stop loss to work after the trade is entered, not when a stopmarket order is submitted. Check the picture that I have attached for references. Thanks
    Attached Files

    #2
    Hello horace chow,

    Thanks for posting.

    To assist we will need more information about your strategy.

    Please post the entry order code you are using as well as the stoploss coding you are using.

    If you are using the Strategy Builder, please post the screenshots of the sets with the entry order and the stop and profit window (if you are using those methods).

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Ignore the print statements, they are for debugging


      SetProfitTarget(CalculationMode.Price, Instrument.MasterInstrument.RoundToTickSize(EntryL ine-1.5*(ShortLimitLine-EntryLine)));
      SetStopLoss(CalculationMode.Price, ShortLimitLine);
      EnterShortStopMarket((int)Math.Round(quantity),Ent ryLine, "Short Entry");

      In this section of code, first I set the profit target, then I set the stop loss. lastly, I submitted a shortstopmarket order. However, before the order is entered(submitted an order but hasn't entered the trade), assuming the price continues to approach and touched my stop loss, the shortstopmarket order will be canceled. I was wondering would there be any better way to approach it. Would it be possible for me to remove my stoploss and set it within OnOrderUpdate() when it's entered into the trade?
      Attached Files

      Comment


        #4
        Hello horace chow,

        Thanks for your reply.

        I see that you have print statements. Can you also print out your entry price as well?

        It looks like you are placing a short stop type entry so this entry would need to be above the current price, I would also print out the current price as a check.


        Paul H.NinjaTrader Customer Service

        Comment


          #5
          the code that I have provided is for entering short, in the example I provided is entering long, it has almost the same layout.

          Comment


            #6
            Hello horace chow,

            Thanks for your reply.

            In both cases, I would use and add to your print statements to determine what the calculated entry price verses the current price.


            Paul H.NinjaTrader Customer Service

            Comment


              #7
              From the example in first comment, I have printed the profit target, entry price, and stop loss

              Quantity = 5.45454545454545 = 1500 / -5.5*50
              Profit target = 3093.75
              Entry price = 3085.5
              Stop loss = 3080

              Comment


                #8
                I have watched the playback very slowly, it seems like after the order has been submitted with EnterShortStopMarket(), once the next bar has been formed, the order was canceled. By any chance this is an error?

                Comment


                  #9
                  Hello horace chow,

                  Thanks for your reply.

                  When you run your strategy, do you see any related error messages in the "log" tab of the control center?

                  Limit type entry orders will be automatically canceled if not filled in the bar they are submitted. Please see the "managed approach" information here: https://ninjatrader.com/support/help...d_approach.htm

                  To keep the order in play, you would need to resubmit the order on each new bar or use the bool IsLiveUntilCanceled in the entry order method.
                  Reference: https://ninjatrader.com/support/help...stopmarket.htm
                  This is the overload: EnterShortStopMarket(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double stopPrice, string signalName)
                  Paul H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Sparkyboy, Today, 10:57 AM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by swestendorf, Today, 11:14 AM
                  1 response
                  2 views
                  0 likes
                  Last Post swestendorf  
                  Started by TheMarlin801, 10-13-2020, 01:40 AM
                  21 responses
                  3,917 views
                  0 likes
                  Last Post Bidder
                  by Bidder
                   
                  Started by timmbbo, 07-05-2023, 10:21 PM
                  3 responses
                  156 views
                  0 likes
                  Last Post grayfrog  
                  Started by Lumbeezl, 01-11-2022, 06:50 PM
                  30 responses
                  812 views
                  1 like
                  Last Post grayfrog  
                  Working...
                  X