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

EntryHandling

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

    EntryHandling

    I would like to go long on a position, then once it moves in the right direction, I want to add to the position when instructed to. Below is the code I am trying, but after the initial long, it doesn't seem to open additional positions when it is supposed to??? By the way, I am using it on the 2 Tick chart, so even thought I tried GetCurrentBid(), it didn't seem to matter. Am I missing something?

    #region Variables
    private int myInput0 = 1;
    double startingPoint = 0;
    #endregion

    protected override void Initialize()
    {
    CalculateOnBarClose = false;
    EntriesPerDirection = 5;
    EntryHandling = EntryHandling.UniqueEntries;
    }

    protected override void OnBarUpdate()
    {
    if(Historical)
    return;


    if (Position.MarketPosition == MarketPosition.Flat)
    {
    EnterLong(1000, "StartingOrder");
    startingPoint = Close[0];
    Print ("StartingPointLong = " + startingPoint);
    }

    // Condition set 1
    if (GetCurrentBid() == startingPoint + 1 * TickSize)
    {
    EnterLong(1000, "BOne");
    }

    // Condition set 2
    if (GetCurrentBid() == startingPoint + 2 * TickSize)
    {
    EnterLong(1000, "BTwo");
    }

    // Condition set 3
    if (GetCurrentBid() == startingPoint + 3 * TickSize)
    {
    EnterLong(1000, "BThree");
    }
    Last edited by edgeliner; 07-30-2012, 10:09 AM.

    #2
    Hello edgeliner,

    Thanks for the note.

    I do not see anything that would cause it not to add a position. You can use the Print() before each condition to ensure that the values you are using are what you want. For example:

    Code:
    Print("Condition 1 -GetCurrentBid(): "+GetCurrentBid());
    Print("Condition 1 -startingPoint: "+(startingPoint + 1 * TickSize));
    http://www.ninjatrader.com/support/f...ead.php?t=3418

    Another thing I wanted to note is your EntriesPerDirection and your EntryHanlding, currently it is going to do 5 entries per UniqueEntries meaning that it will submit 5 "BOne" orders. Is that what you were looking for?
    http://www.ninjatrader.com/support/h...ryhandling.htm

    When seeing how a strategy is handling orders, setting TraceOrders to true helps out as well.
    http://www.ninjatrader.com/support/f...ead.php?t=3627

    Please let me know if I can be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Thanks JC....... This is confusing to me......maybe you could run it and see what happens on your end..... I made it very simple and took out a lot of the additional conditions so that it is simple...(Please see below). The problem is, after opening the original position, the additional orders to go long do not execute? What do you think??? Thanks!

      #region Variables
      // Wizard generated variables
      private int myInput0 = 1;
      private double startingPointBuy;
      // I tried using double startingPointBuy = 0; here but it did not make a difference//
      #endregion

      protected override void Initialize()
      {
      CalculateOnBarClose = false;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.UniqueEntries;
      TraceOrders = true;

      }

      protected override void OnBarUpdate()
      {
      if(Historical)
      return;


      if (Position.MarketPosition == MarketPosition.Flat)
      {
      EnterLong(1000, "StartingOrder");
      startingPointBuy = Close[0];
      Print ("StartingOrder= " + startingPointBuy);
      }


      // Condition set 1
      if (Close[0] == startingPointBuy + 1 * TickSize)

      {
      Print("Current Close = " + Close[0]);
      Print("Price is now 1 more than opening price so.....");
      Print("Should be going long on a second position now");
      EnterLong(1000, "BOne");
      }

      // Condition set 2
      if (Close[0] == startingPointBuy + 2 * TickSize)

      {
      Print("Current Close = " + Close[0]);
      Print("Price is now 2 more than opening price so.....");
      Print("Should be going long on a third position now");
      EnterLong(1000, "BTwo");
      }

      // Condition set 3
      if (Close[0] == startingPointBuy + 3 * TickSize)

      {
      Print("Current Close = " + Close[0]);
      Print("Price is now 3 more than opening price so.....");
      Print("Should be going long on a third position now");
      EnterLong(1000, "BThree");
      }
      Last edited by edgeliner; 07-30-2012, 10:08 AM.

      Comment


        #4
        Hello edgeliner,

        I was able to get filled on all of them. If you go under the Executions tab you can see name of the tag that you placed inside of a Strategy for example "BOne", "BTwo", "BThree", and "Starting Order".

        Few things to note is that you are having the conditions that have to be exactly equal for the condition to be true. With that said, if you use a Print() statement before your if statement you can check the values of them to ensure that those are the conditions that you would like. For example:

        Code:
        Print("Close[0]): "+Close[0]);
        Print("Condition 1 -startingPointBuy: "+(startingPointBuy + 1 * TickSize));
        				
        // Condition set 1
        if (Close[0] == startingPointBuy + 1 * TickSize)
        {(...)}
        That way you can check the values before the statements.

        Please let me know if I can be of further assistance.
        JCNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_JC View Post
          Hello edgeliner,

          I was able to get filled on all of them. If you go under the Executions tab you can see name of the tag that you placed inside of a Strategy for example "BOne", "BTwo", "BThree", and "Starting Order".

          JC.....Well, I couldn't get any of them filled? I did check the Executions tab and did not have any BOne, BTwo, or BThree. Here is something funny though......... When I rewrote the exact strategy going Short instead of going Long, it worked perfectly!!! Isn't that strange?

          Few things to note is that you are having the conditions that have to be exactly equal for the condition to be true. With that said, if you use a Print() statement before your if statement you can check the values of them to ensure that those are the conditions that you would like. For example:

          Code:
          Print("Close[0]): "+Close[0]);
          Print("Condition 1 -startingPointBuy: "+(startingPointBuy + 1 * TickSize));
          				
          // Condition set 1
          if (Close[0] == startingPointBuy + 1 * TickSize)
          {(...)}
          That way you can check the values before the statements.

          Please let me know if I can be of further assistance.
          I have used the Print statement for all of these. The problem is, everything is perfect except the order just does not get placed????? Let me know if you have any other ideas.....

          Thanks!

          Comment


            #6
            Hello edgeliner,

            Can you try resetting a simulation account? Note that this will clear all historical trade data from this account. Please follow the instructions below to reset a simulation account.

            * From the NinjaTrader Control Center window select the menu Tools -> Options
            * Select the "Simulator" tab
            * Press the "Reset" button

            Click here for more information on the Sim101 account

            Happy to be of further assistance.
            JCNinjaTrader Customer Service

            Comment


              #7
              JC......

              I figured it had to be something like that! Actually, I tried the strategy on a different computer and sure enough, it worked perfectly! When I try to reset the sim account on this particular computer (where my actual live account is), it freezes up with a (Not Responding) messsage and when I try to exit out, it closes down the whole Ninja program. Would you recommend I re-install Ninja?

              Comment


                #8
                Hello edgeliner,

                How large is your database file? You can check this by going to (My) Documents -> NinjaTrader 7 -> db and right click on the "NinjaTrader.sdf" file and select properties. (Example: X.XX MB).

                Happy to be of further assistance.
                JCNinjaTrader Customer Service

                Comment


                  #9
                  It is 103 MB.........

                  Comment


                    #10
                    Hello edgeliner,

                    You database size is above the average size for a database, so it may take several minutes for it reset the simulation account(s). Alternatively, you can rename your database with the following steps to manually reset the simulation accounts :

                    * Shutdown NinjaTrader
                    * Select (My) Documents --> NinjaTrader 7 --> db --> NinjaTrader.sdf.
                    * Right click on NinjaTrader.sdf and select "Rename." *Name it "OLDNinjaTrader.sdf."
                    * Then restart the software and NinjaTrader will create a fresh database file to use
                    * Unfortunately the following items stored in the old database will be lost – ATM Strategy templates, Session templates, Instrument Lists / Custom Instruments and historical trade execution data.

                    Happy to be of further assistance.
                    JCNinjaTrader Customer Service

                    Comment


                      #11
                      OK...thanks..... if I rename it, my custom strategies will still be there though correct?

                      Comment


                        #12
                        Hello edgeliner,

                        Yes, your custom Automated Strategies will still be there. The ATM Strategies from the ATM Strategies drop down menu will be the ones lost in renaming the database file.

                        Happy to be of further assistance.
                        JCNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by wuannetraam, Today, 02:40 AM
                        0 responses
                        7 views
                        0 likes
                        Last Post wuannetraam  
                        Started by cyberpete76, 03-27-2023, 12:29 AM
                        7 responses
                        269 views
                        1 like
                        Last Post slightly  
                        Started by renewsaltwater, Today, 01:15 AM
                        0 responses
                        2 views
                        0 likes
                        Last Post renewsaltwater  
                        Started by slightly, Today, 12:49 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post slightly  
                        Started by sdauteuil, 09-23-2021, 10:16 AM
                        4 responses
                        1,211 views
                        0 likes
                        Last Post jacobpescaia44  
                        Working...
                        X