Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unwanted mtultiple position entries/exits in one bar

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

    Unwanted mtultiple position entries/exits in one bar

    Hello,

    recently I have noticed unwated behavior of my strategy. I think it is connected to the changes in code which solved my previous problem within this thread some months ago: http://www.ninjatrader.com/support/f...ad.php?t=68028

    The problem is that now it can happen that multiple trades are executed within the same day even though the strategy is intended to execute orders only at the beginning of each trading day.

    Please see attached print screen from the executions and also the whole strategy script.

    Could you please advice me how to adjust the script so that only 1 position per day will be permitted, but at the same time I would like to prevent the problem from previous thread to occur once again.

    Should you need additional information from me, please let me know.

    Thank you and regards,
    Waldo
    Attached Files
    Last edited by Waldo; 01-06-2015, 01:09 PM.

    #2
    Hi Waldo,

    Thanks for your post.

    You will need to add logic to your script to prevent further entries after there has been an entry.

    For example:
    In #region Variables:
    private bool tradeExecuted = false;

    In OnBarUpdate():
    if (Bars.BarsSinceSession == 0)
    tradeExecuted = false;

    if (tradeExecuted == true)
    return;

    Within the namespace:
    protected override void OnExecution(IExecution execution)
    {
    if (execution.Order.OrderAction == OrderAction.Buy)
    tradeExecuted = true;
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for a fast reply. I have tried to add the code into the script, but unfortunately the result is the same. Please find attached the adjusted script. Could you please check if it was added in the correct sections and if not then edit it accordingly? I have marked the respective rows with comment "// ADDED" within the code.

      With regards,
      Waldo
      Last edited by Waldo; 01-06-2015, 01:09 PM.

      Comment


        #4
        Hi Waldo,

        I'd like schedule a call with you to investigate on your end.

        I'm testing on my end and only getting one trade per day so it does appear to work OK. (Even though this should allow for multiple trades at the beginning of the session and then not again until the next session, I am not actually getting multiple trades at the beginning of the session)

        Please send an email to platformsupport [at] ninjatrader [dot] com. In the email please add a link to this forum thread.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Waldo,

          Thanks for the time on the phone.

          For anyone reading this thread, I did not understand the goal.

          The goal was not to allow 1 trade per instrument at the beginning of the session, the goal was to allow only 1 instrument 1 trade per session.

          To do this, instead of changing the bool to true in OnExecution, change the bool to true in each condition that allows for an order to be placed.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hello Chelsea,

            I have added the change of bool to each condition as discussed, but the result is still the same. Any further ideas or support will be appreciated.

            With regards,
            Waldo

            Comment


              #7
              Hi Waldo,

              Please send me an email when you would like me to give you a call back.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi Waldo,

                Running this on a Daily chart exposed that the Bars.BarsSinceSession is always 0 and causing the tradeExecuted bool to always be reset.

                To correct this we added code to require a new session and a new primary bar for the reset to occur.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Chelsea,

                  thank you once again for the support. This has done the trick, therefore you can close the thread.

                  With regards,
                  Waldo

                  Comment


                    #10
                    Hello ChelseaB, I would like to have just one trade per day. Is there a way to use the Ninja Wizard strategy builder to make my automated strategy make just one trade per session or day? I know how to use the wizard but not so good with scripting.

                    Comment


                      #11
                      Hello CactusMo,

                      You can use a User Variable instead of a bool if you are using the wizard and you do not want the user to be able to change the bool.

                      After the first order is placed set Variable0 to 1. Then use the Misc -> Session break to reset to this to 0 on the new session. Only allow for orders if Variable0 is 0.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello Chelsea, I tried following your instructions as you so kindly relied, but I keep getting an error message after clicking the "Compile" button. Here is what I did.

                        Clicked: "User variables" then "Variable0" then "==" then "Misc" then "Numeric value" then change value from "0" to "1"
                        Clicked: "Session break" then "==" then "Misc" then "Numeric value" then left value at "0"
                        This is how I understand your instructions, but I am sure I have not executed your instructions properly. I did not include the rest of my code since it works just fine. The only problem is it executes more than one trade per day or per market session.

                        Comment


                          #13
                          Hello CactusMo,

                          Attached is an example.

                          Follow these steps to import the NinjaScript:
                          1. Download the script to your desktop, keep it in the compressed .zip file.
                          2. From the Control Center window select the menu File > Utilities > Import NinjaScript
                          3. Select the downloaded .zip file
                          4. NinjaTrader will then confirm if the import has been successful.

                          Critical *Note that on any files that say "File already exists on your PC" that start with an "@" symbol are the ones that came preloaded inside of NinjaTrader so you would say "No" so that you do not override those files.
                          Attached Files
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Hello Chelsea, works perfect. Thanks!

                            Comment


                              #15
                              Is `if(FirstTickOfBar)` the same alternative? i use that to reset, and is that different that your solution?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rmicalet, Today, 07:10 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post rmicalet  
                              Started by cincai, Today, 07:02 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post cincai
                              by cincai
                               
                              Started by AlexsOptions, Today, 05:42 PM
                              2 responses
                              17 views
                              0 likes
                              Last Post AlexsOptions  
                              Started by philli4093, Today, 05:20 PM
                              2 responses
                              8 views
                              0 likes
                              Last Post philli4093  
                              Started by memonolog, Today, 04:58 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post memonolog  
                              Working...
                              X