• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Wolf1, Today, 08:26 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post Wolf1
                  by Wolf1
                   
                  Started by pparmley, Today, 04:30 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post pparmley  
                  Started by tonynt, Today, 04:21 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post tonynt
                  by tonynt
                   
                  Started by williamzz, Today, 03:44 PM
                  1 response
                  12 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by Miguel_88, Yesterday, 06:41 PM
                  2 responses
                  26 views
                  0 likes
                  Last Post Miguel_88  
                  Working...
                  X