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

Order is already filled

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

    Order is already filled

    Hi there.

    I have been running a simple testing strategy and am getting "order is already filled" message/error on some orders and sometimes ninja freezes and I have to restart.

    The strategy is run on each tick not onbarclose. Here is the code. I am not sure why. Is there anything odd in this code that stands out and is there anything I can add to eliminate this issue? I have tried a number of things but to no avail. Thanks in advance.



    if(Ematrendlong==true
    &&Lastbarlong==true
    &&Twobarlong==true
    &&PriceaboveEma==true
    &&timeGap1<Time1
    &&Position.MarketPosition == MarketPosition.Flat
    &&BarsSinceExitExecution() > 1 || BarsSinceExitExecution() == -1
    )

    {
    EnterLongLimit(Convert.ToInt32(DefaultQuantity), Close[1]-Pullbackentry*TickSize, @"Long1");
    EnterLongLimit(Convert.ToInt32(DefaultQuantity), Close[1]-Pullbackentry*TickSize, @"Long2");
    EnterLongLimit(Convert.ToInt32(DefaultQuantity), Close[1]-Pullbackentry*TickSize, @"Long3");
    }

    if (timeGap>Time2&&Position.MarketPosition == MarketPosition.Long&&BarsSinceExitExecution() > 1 || BarsSinceExitExecution() == -1 )

    {
    ExitLong(Convert.ToInt32(DefaultQuantity), @"Long1", @"Long1");
    ExitLong(Convert.ToInt32(DefaultQuantity), @"Long2", @"Long2");
    ExitLong(Convert.ToInt32(DefaultQuantity), @"Long3", @"Long3");
    }

    #2
    Hello djkiwi,

    Is this script collecting ticks or volume?

    If not, it would be much less CPU intensive to use Calculate.OnPriceChange to run in real-time.
    See Tip 1 in the help guide.


    I'm not seeing anything in this specific code that would cause an "order already filled message".

    Is this a TraceOrders message or is this an order error message showing in red on the Log tab of the Control Center.
    Are you certain that is the exact full message and that the message is not slightly different?

    I would expect that if the order filled, then a new order would be substituted until the EntriesPerDirection / EntryHandling is met. Then orders would be ignored and not rejected.

    Is there no other code at all in this script?

    With BarsSinceExitExecution, as you are using signal names, the signal name of a specific order should be provided to this method.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea. This is collecting ticks. On bar close also a problem. I just ran a simple strategy through strategy builder and got the same issue. Please see log. Also have all this other odd database stuff in log going on. I have had a few problems recently so installed whole new copy of ninja from scratch including new DB and no custom indicators but still having problems and same errors. Here is the code in strategy builder with basic stuff but still the same "order already is filled" error. Maybe I am doing something wrong. Also this DB error just keeps going. I tried the onexecution with each signal type in the other strategy as you suggested and actually got worse and put entries on each. I think I am doing something wrong.

      Here is some code

      else if (State == State.Configure)
      {
      SetProfitTarget(@"Long1", CalculationMode.Ticks, Profittarget1);
      SetProfitTarget(@"Long2", CalculationMode.Ticks, Profittarget2);
      SetProfitTarget(@"Long3", CalculationMode.Ticks, Profittarget3);
      SetProfitTarget(@"Short1", CalculationMode.Ticks, Profittarget1);
      SetProfitTarget(@"Short2", CalculationMode.Ticks, Profittarget2);
      SetProfitTarget(@"Short3", CalculationMode.Ticks, Profittarget3);
      SetStopLoss(@"Long1", CalculationMode.Ticks, Stoploss1, false);
      SetStopLoss(@"Long2", CalculationMode.Ticks, Stoploss2, false);
      SetStopLoss(@"Long3", CalculationMode.Ticks, Stoploss3, false);
      SetStopLoss(@"Short1", CalculationMode.Ticks, Stoploss1, false);
      SetStopLoss(@"Short2", CalculationMode.Ticks, Stoploss2, false);
      SetStopLoss(@"Short3", CalculationMode.Ticks, Stoploss3, false);


      protected override void OnBarUpdate()
      {


      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBar<10)
      return;

      Long entry:

      if BarsSinceEntryExecution(@"Long1") > 1 || BarsSinceEntryExecution(@"Long1") == -1
      &&BarsSinceEntryExecution(@"Long2") > 1 || BarsSinceEntryExecution(@"Long2") == -1
      &&BarsSinceEntryExecution(@"Long3") > 1 || BarsSinceEntryExecution(@"Long3") == -1)

      {
      EnterLongLimit(Convert.ToInt32(DefaultQuantity), Close[1]-Pullbackentry*TickSize, @"Long1");
      EnterLongLimit(Convert.ToInt32(DefaultQuantity), Close[1]-Pullbackentry*TickSize, @"Long2");
      EnterLongLimit(Convert.ToInt32(DefaultQuantity), Close[1]-Pullbackentry*TickSize, @"Long3");
      }

      Is this correct?



      Thanks
      Last edited by djkiwi; 12-01-2020, 07:15 PM.

      Comment


        #4
        Hello djkiwi,

        I would not expect a strategy created with the Strategy Builder to be collecting ticks. The Strategy Builder is not capable of this kind of advanced logic and math.

        What code is in your script that is collecting ticks?

        I was not able to confirm my questions in post #2, that information tells us where to look for issues.

        Please answer, is this a TraceOrders message or is this an order error message showing in red on the Log tab of the Control Center?
        Are you certain that is the exact full message and that the message is not slightly different?

        May we have a screenshot of the full error message in either the output window or the Log tab of the Control Center?


        The code you have posted in post #3 and asked if this is correct, depends on the context of how this is used in the script?
        What is EntryHandling set to?
        What is EntriesPerDirection set to?

        Is there any other code in the script?

        If EntryHandling is AllEntries and EntriesPerDirection is 1, I would expect the Long2 and Long3 entry orders to be ignored.

        There is no code at all in the script for short entry orders, so there is no need for Short1, Short2, Short3 at all.

        The line
        Long entry:

        This would cause an error as needs to be a comment.
        //Long entry:

        Other than that, I would expect one long order to possibly be placed and one stop loss and one profit target should appear when the entry fills, and the other orders to be ignored.


        As a tip, to export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
        1. Click Tools -> Export -> NinjaScript...
        2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
        3. Click the 'Export' button
        4. Enter a unique name for the file in the value for 'File name:'
        5. Choose a save location -> click Save
        6. Click OK to clear the export location message
        By default your exported file will be in the following location:
        • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
        Below is a link to the help guide on Exporting NinjaScripts.
        http://ninjatrader.com/support/helpG...-us/export.htm
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chelsea.

          I am not sure what you mean about collecting ticks but it works on each tick rather than barclose.

          Here is the complete script. Running on replay at Max getting that already is filled affected order a bit. Would you mind checking it out? It used to work without errors. You will see that quite a few orders are processed on the next bar as I am testing some things.

          Attached Files

          Comment


            #6
            Hello djkiwi,

            A script that collects ticks is adding them up or adding the volume up. This could be collecting volume from OnMarketUpdate(), or incrementing a value on each tick to count the number of ticks in OnBarUpdate().

            Below is a link to a script that looks at volume from each tick in OnMarketUpdate().


            And an example script that collects ticks from OnBarUpdate().
            NYSE Advancing Issues/Declining Issues Uses historical tick data to calculate the ^ADV index minus the ^DECL index to give a simulation of the ^ADD index. Requires a data feed that supports indexes and provides data for the ^ADV (NYSE Advancing Issues) and ^DECL (NYSE Declining Issues). Update June 16th, 2020 &#8211; Corrected stroke attributes to [&#8230;]


            I don't think your script collects any volume or collects ticks. This means you should run the script with Calculate set to On price change instead of using On each tick.
            Please let me know if this does not clarify.


            May I have a screenshot of the error message you are seeing?

            To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.
            Click here for instructions

            Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.
            Click here for detailed instruction
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            44 views
            0 likes
            Last Post jeronymite  
            Started by Barry Milan, Yesterday, 10:35 PM
            7 responses
            20 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by AttiM, 02-14-2024, 05:20 PM
            10 responses
            179 views
            0 likes
            Last Post jeronymite  
            Started by ghoul, Today, 06:02 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by DanielSanMartin, Yesterday, 02:37 PM
            2 responses
            13 views
            0 likes
            Last Post DanielSanMartin  
            Working...
            X