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

Orders OCO being canceled before any execution

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

    Orders OCO being canceled before any execution

    Hi,

    My purpose is to enter Long or Short 1 contract each 2 times for multiple profit target. My strategy is being detected and no problem getting into positions with 2 contracts. My backtest data position and profit taking/ stop loss seems fine. The problem is when I run it live on the simulation, it correctly sends out 4 orders, 2 profit takers and 2 stop loss but it end up being canceled just a few bars either up or down the trade without any execution all 4 OCO orders are canceled leaving me with an full open position and no orders. Below is a snippet of my strategy regarding the orders.




    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class teststrategy : Strategy
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "DarvasBothT2";
    Calculate = Calculate.OnEachTick;
    EntriesPerDirection = 1;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 1;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    EntryHandling = EntryHandling.UniqueEntries;
    DaysToLoad = 3;
    IncludeCommission = true;
    IsInstantiatedOnEachOptimizationIteration = true;

    dRange = 20;


    }
    else if (State == State.Configure)

    {
    }
    else if (State == State.DataLoaded)
    {
    list of AddChartIndicators


    SetProfitTarget("Short1", CalculationMode.Ticks, dRange/2);
    SetTrailStop("Short1",CalculationMode.Ticks, dRange, true);
    SetProfitTarget("Short2", CalculationMode.Ticks, dRange);
    SetTrailStop("Short2",CalculationMode.Ticks, dRange, true);

    SetProfitTarget("Long1", CalculationMode.Ticks, dRange2/2);
    SetTrailStop("Long1",CalculationMode.Ticks, dRange2, true);
    SetProfitTarget("Long2", CalculationMode.Ticks, dRange2);
    SetTrailStop("Long2",CalculationMode.Ticks, dRange2, true);
    }
    }

    protected override void OnBarUpdate()
    {

    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 2)
    return;


    if
    (
    criteria for short
    )
    {
    EnterShort(NumContract, "Short1");
    EnterShort(NumContract, "Short2");
    }

    else if
    (

    citeria for long
    )
    {
    EnterLong(NumContract, "Long1");
    EnterLong(NumContract, "Long2");
    }
    }

    #2
    Hello dragonzx,

    Thank you for the post.

    From what you provided I can't see anything that sticks out as the reason for the targets being cancelled. I do want to check, have you tried not using a simulated stop? does this make a difference in your test?

    I would otherwise need to see more information about the situation, such as a working example that we can test. If you can create a simple script that just enters a position and protects it, then shows the problem we could work with that.

    I would also suggest using TraceOrders to see if any managed order handling rules are the cause, you would see a note in the NinjaScript output if so.

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

    Comment


      #3
      Thank you Jessie for the quick response. I've attached a working example and even with this simple strategy I am still getting the same problem.
      Attached Files

      Comment


        #4
        Hello dragonzx,

        Thank you for providing the file.

        I wanted to check, can you post an image of the result you are seeing? I was unable to see the orders being cancelled, I do see that they were working until filled or the opposing entry happens in which it closes the entry position so the targets are canceled.

        Are you seeing that the cancel happens when the cross condition occurs, or is this just a random amount of bars after the entry?

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

        Comment


          #5
          I can post an image later as I am away from my computer. What I did noticed was that, it maybe hitting my profit target and instead of filling it is canceling, do you think it may be something in my client settings that make this occurrence? Would it beneficial to add a position check as a safety measure of cross condition filling?

          Comment


            #6
            Hello dragonzx,

            Before I try to provide any other steps or details for this question I believe it would be best to first understand what specifically you are seeing happen.

            If the target is being hit, it should be filled not cancelled. From the given details I am not entirely sure what you are seeing here so I think we should try to first focus on what you see first so we can both understand the problem.

            For this question it would be helpful if you can take a picture of the chart to show the problem as you see it. It would also be helpful to take a screenshot of the orders tab so we can see the orders as they happened in the history. This will better help explain what orders were submitted, what was cancelled or filled etc.. Once I can better understand the question or problem better we should be able to find a resolution or at least understand why that's happening.

            One item I did note is that you are using a simulated trailing stop order so that will be reported differently than a usual stop in the control center. Another item to test is using false for the simulated stop, check if this gives you the expected result and if so we can then focus on what differences that causes and why that happens.

            I look forward to being of further assistance.


            JesseNinjaTrader Customer Service

            Comment


              #7
              Hi Jesse,

              Thank you for being patient with me. So there's no problem with my stop being trigger, it is the profit target that is canceling either 2 ticks or 4 ticks away from execution. Here are screen shots in order. I was able to capture the output on the 2nd OCO order being canceled. Here's what it says: Seems like the order is expired or every +$5? But I dont know why? ps. I am using 2 Bar RENKO charts and using MES 6-19 e-micro for this.

              6/11/2019 7:02:55 PM Strategy 'TestEMA/170604630': Amended trail stop order orderId='f5d2c79993a44e2ea9861fe40fecc6fb' account='Sim101' name='Trail stop' orderState=TriggerPending instrument='MES 06-19' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=2884.75 quantity=1 tif=Gtc oco='6208f4a00ee1440caea3ba543a66ec36' filled=0 averageFillPrice=0 onBehalfOf='' id=22 time='2019-06-11 18:58:37' gtd='2099-12-01' statementDate='2019-06-11'
              6/11/2019 7:02:55 PM Strategy 'TestEMA/170604630': Cancelled expired order: BarsInProgress=0, orderId='e5379a217b5d4c86907f2f387465a85e' account='Sim101' name='Profit target' orderState=Working instrument='MES 06-19' orderAction=Sell orderType='Limit' limitPrice=2888 stopPrice=0 quantity=1 tif=Gtc oco='6208f4a00ee1440caea3ba543a66ec36' filled=0 averageFillPrice=0 onBehalfOf='' id=23 time='2019-06-11 18:49:00' gtd='2099-12-01' statementDate='2019-06-11'

              Comment


                #8
                Hello dragonzx,

                Thank you for the update.

                I just wanted to let you know I was able to see the expired order when using the renko, it seems that was the part I needed to see this. I am exploring this further to see why this is happening, once I have more information I will provide another update.


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

                Comment


                  #9
                  Hello dragonzx,

                  I just wanted to provide an update here. It looks like this is only happening with Renko bars currently and a similar issue has been reported for the current release. I was able to test this on the current internal release and see the expected action happening, or that the orders are not expired. It would not be expected for the orders to be expired in this case. The tracking ID for this issue is: NTEIGHT-13574

                  You can use the change log to note when this changes in a future update: https://ninjatrader.com/support/help...ease_notes.htm

                  For the current release to test what you have created you would need to use a different BarsType so that the order is not being expired due to what is happening here.

                  I look forward to being of further assistance.

                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Hello,

                    I just wanted to ask if this has been fixed? I am also using Renko bars and my simulated orders (MIT) are often being Cancelled without any reason or logic behind that. TIF is set to GTC and the strategy doesn't contain any line that Cancels those orders, yet it happens often and out of nowhere. I am running the latest, clean install of NT8 today.

                    Comment


                      #11
                      Hello GLFX005,

                      I see this was marked fixed in 8.0.19.1. Are you seeing the problem using the sample that is in this thread specifically to know we are seeing the same scenario? I would suggest trying that before we look further into the same issue, if you still see a problem using this sample please reply here. If you are otherwise seeing a problem with your script I would suggest to open a new thread and attach a simplified example of the logic you had used so we can review it. If your logic is very similar to the sample here you could link the post to your new thread as well.

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

                      Comment


                        #12
                        I am having a similar problem in NT8. I have 3 positions in my strategy: Target 1, target 2 and trail. Whenever target 1 is being filled, target 2 and trail is being canceled. What could be the reason behind this? I am attaching a screenshot of the order tab and a screenshot of a portion of my codes.


                        Screenshot 1: https://paste.pics/D9UC3
                        • Red = Position 1
                        • Green = Position 2
                        • Aqua = Position 3

                        Screenshot 2: https://paste.pics/D9UCX

                        Comment


                          #13
                          Hello fawzanalim,

                          From the images provided I don''t see what that could be. Have you reviewed the past replies in this thread and created a simplified sample/steps to reproduce the problem? I would need more specific details to know what may be happening or if it relates to this existing post. I would suggest turning off simulated stop/testing the sample linked earlier in the thread. If this is being used on renko, try a different bars type. Once you have further tested and have more specific details on the problem we could review that in this thread if it relates to the thread otherwise we can split that into a new thread if not.

                          Please let me know if I may be of further assistance.



                          JesseNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by frankthearm, Yesterday, 09:08 AM
                          14 responses
                          47 views
                          0 likes
                          Last Post NinjaTrader_Clayton  
                          Started by gentlebenthebear, Today, 01:30 AM
                          2 responses
                          13 views
                          0 likes
                          Last Post gentlebenthebear  
                          Started by Kaledus, Today, 01:29 PM
                          2 responses
                          9 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by PaulMohn, Today, 12:36 PM
                          2 responses
                          17 views
                          0 likes
                          Last Post PaulMohn  
                          Started by Conceptzx, 10-11-2022, 06:38 AM
                          2 responses
                          56 views
                          0 likes
                          Last Post PhillT
                          by PhillT
                           
                          Working...
                          X