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

OCO Orders cancelling at bar close

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

    #31
    Hi ChelseaB,

    Yes, that is correct - there is a difference in order quantities. It is one of the issues that arises when I connect to IB account.

    Below are script extracts with Profit target, Stop loss, and entry order logic (Calculate = OnEachTick). It is just to show how and when I submit orders.

    protected override void OnStateChange()
    {
    else if (State == State.Configure)
    {
    // Creation of data series
    AddDataSeries(Data.BarsPeriodType.Minute, 5);
    AddDataSeries(Data.BarsPeriodType.Minute, 30);
    AddDataSeries(Data.BarsPeriodType.Day, 1);


    if (BarsInProgress == 0)
    {
    // Profit Target and Stop loss definition
    SetProfitTarget(CalculationMode.Currency, xxxx);
    SetTrailStop(CalculationMode.Percent, 0.07);

    protected override void OnBarUpdate()
    {
    // Stop if we don't have enough bars
    if (CurrentBars[0] < 1 || CurrentBars[1] < 2 || CurrentBars[2] < 13 || CurrentBars[3] < daysToCalcAvg)
    return;

    if (BarsInProgress != 0)
    return;
    EnterLongLimit(1, false, Convert.ToInt32(MyQuantity), GetCurrentAsk(0), "");


    I tried to move Set methods to OnBarUpdate section - it did not help.


    Comment


      #32
      Hello Paco0,

      Is the code:
      Code:
      if (BarsInProgress == 0)
      {
      // Profit Target and Stop loss definition
      SetProfitTarget(CalculationMode.Currency, xxxx);
      SetTrailStop(CalculationMode.Percent, 0.07);
      Located inside of OnStateChange() or is this in OnBarUpdate()?

      BarsInProgress should not be used in OnStateChange(). This is something that should be used in OnBarUpdate().

      Are you ensuring that this logic is called when flat before any entry orders are placed?

      Chelsea B.NinjaTrader Customer Service

      Comment


        #33
        Hi ChelseaB,

        It is located in OnStateChange(). BarsInProgress was my last attempt to fix the order quantities, I would not use that normally.

        I am not sure what do you mean by "Are you ensuring that this logic is called when flat before any entry orders are placed?" As soon as Limit order is filled at my broker (fully or partially), OCO orders are submitted so I assume it is always called? OCO order quantities are usually updated as entry order is being filled.

        Comment


          #34
          Hello Paco0,

          If the Set methods are in OnStateChange() they would not be in a condition that checks the BarsInProgress, but would be set before the entry is placed.

          If the code that is being posted is not the code being used, what is the code being used?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #35
            Hi ChelseaB,

            I used code posted above for the last two weeks to see if adding BarsInProgress helps to resolve the quantity issue. Before then I used the very same code, the only difference is that there was no BarsInProgress restriction for Set methods:

            protected override void OnStateChange()
            {
            else if (State == State.Configure)
            {
            // Creation of data series
            AddDataSeries(Data.BarsPeriodType.Minute, 5);
            AddDataSeries(Data.BarsPeriodType.Minute, 30);
            AddDataSeries(Data.BarsPeriodType.Day, 1);

            // Profit Target and Stop loss definition
            SetProfitTarget(CalculationMode.Currency, xxxx);
            SetTrailStop(CalculationMode.Percent, 0.07);

            protected override void OnBarUpdate()
            {
            // Stop if we don't have enough bars
            if (CurrentBars[0] < 1 || CurrentBars[1] < 2 || CurrentBars[2] < 13 || CurrentBars[3] < daysToCalcAvg)
            return;

            if (BarsInProgress != 0)
            return;
            EnterLongLimit(1, false, Convert.ToInt32(MyQuantity), GetCurrentAsk(0), "");

            Comment


              #36
              Hello Paco0,

              We should be discussing the code that you are currently testing and that you have questions about, as different code may have different behavior.

              May I test your script?

              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.


              Once exported, please attach the file as an attachment to your reply.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #37
                Hi ChelseaB,

                I am not comfortable sharing the script. Is there another way we could approach this? I believe Order object print/trace orders along with piece of script I shared should be enough to demonstrate that Managed Approach for order handling is not working as it should be.

                Comment


                  #38
                  Hello Paco0,

                  You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.

                  Can you create an example script with only the necessary code to demonstrate the behavior without any logic that is not directly required for the inquiry?

                  Then export the test script and post with your next post.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #39
                    Hi ChelseaB,

                    I already reached out to a professional NinjaScript Consultant who basically suggested to switch to Unmanaged approach because of Managed approach flaws(specifically with IB). I am just not able to understand why I need to invest additional funds in fixing something which is supposed to be working, when I am already paying for NT license - or why is it not mentioned somewhere when you purchase the license - that Managed approach does not always work and that when you want to report a bug, you need to provide basically whole script (which is quite sensitive in regards to trading if you ask me). I work as a consultant for another software so I do understand how important it is for DEV/TEST to be able to reproduce the issue but at the same time, once the issue is identified, there should be a way to reproduce it without asking for full script.

                    I spent months of coding and learning the software just to understand that I need to spend another couple months or $ to fix something which should have been working in standard.

                    I will try to create a script which I can share. I am suspecting this will not be reproducible in Market Playback as it seems to have to do with order status updates and communication between NT <->IB.

                    Comment


                      #40
                      Hello Paco0,

                      This would be up to you.

                      If you are able to provide a reduced script that demonstrates an issue, I can submit this with a bug report to our development.

                      If you want help with custom logic, I can give you pointers, however I would need to know what the code you are actually using is. The code you have posted is not a complete script.

                      If you already have a developer making your script, I would recommend working with your developer. If you developer needs assistance have your developer send an email to platformsupport [at] ninjatrader [dot] com.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #41
                        Hi ChelseaB,

                        You might be able to reproduce the behavior by creating a script that says buy following stock at following time at following quantity:

                        Date: 12/26/2019
                        Time: 9:46am (16 minutes after market open)
                        Instrument: NLNK
                        Limit order entered (and filled) quantity: 2059 shares (Using EnterLongLimit)

                        SetProfitTarget(CalculationMode.Currency, 160);
                        SetTrailStop(CalculationMode.Percent, 0.07);
                        EnterLongLimit(1, false, Convert.ToInt32(MyQuantity), GetCurrentAsk(0), "");
                        Calculate.OnEachTick

                        I am not using market playback so I cannot tell if it will be reproduced successfully but order quantities are correct in historical backtests(no issues with quantities observed in historical backtest). This makes me believe that the issue lies in IB</>NT communication/ exchanging and processing order updates. Someone from NT would need to connect to IB paper account with realtime data to be able to reproduce the behavior in my opinion.

                        Out of 3 months I paid for by purchasing NT license, so far I spent 2 months fixing and struggling with broken NT Managed order approach, which is unacceptable!! How can debugging and bug reporting be built on client providing full script?!!

                        Comment


                          #42
                          Hello Paco0,

                          Were you able to reproduce the behavior?

                          May I have the reduced test script you used?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #43
                            LOL. This is insane. Have you read my previous post AT ALL?

                            Comment


                              #44
                              Hello Paco0,

                              I'm reading in your post:
                              "I am not using market playback so I cannot tell if it will be reproduced successfully but order quantities are correct in historical backtests(no issues with quantities observed in historical backtest)."

                              If you have an issue that you are able to reproduce and a reduced script that can reproduce it, then we have what we need to move forward.

                              You have also stated:
                              "You might be able to reproduce the behavior by creating a script that says buy following stock at following time at following quantity:"
                              Which sounds like you do not have a reproducible script or steps to reproduce the behavior.

                              Please provide me with a script that is able to reproduce the behavior with all code that is not absolutely necessary to reproduce the behavior, I will test and reproduce, and if I am able to reproduce I will create a bug report and provide the reduced script to our development so this bug may be corrected.

                              Currently, I have made a script and I am not able to reproduce. However, my script may not be testing what your script is testing.

                              Let me know if you want to move forward.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by frslvr, 04-11-2024, 07:26 AM
                              6 responses
                              105 views
                              1 like
                              Last Post NinjaTrader_BrandonH  
                              Started by trilliantrader, 04-18-2024, 08:16 AM
                              6 responses
                              26 views
                              0 likes
                              Last Post trilliantrader  
                              Started by arvidvanstaey, Yesterday, 02:19 PM
                              5 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Zachary  
                              Started by Rapine Heihei, Yesterday, 08:25 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Mongo, Yesterday, 11:05 AM
                              6 responses
                              27 views
                              0 likes
                              Last Post Mongo
                              by Mongo
                               
                              Working...
                              X