• 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

Increase contracts traded

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

    Increase contracts traded

    Hi,

    I got the strategy running and now would like to gradually increase the contracts traded within the script until "X" contracts are traded instead of "all in and all out". Is there an example for me to use as guideline or any suggestions?

    Thanks

    #2
    Hello 2Look4me,

    Thanks for your post.

    You could use Position.Quantity as a means of checking how many orders you have and comparing it to "X".

    if (Your conditions to enter && Position.Quantity < MyTotalContracts) // MyTotalContracts would be an int variable you create/define
    {
    EnterLong();
    }


    Reference: https://ninjatrader.com/support/help.../?quantity.htm

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Paul, "Position.Quantity " is what I needed. In terms of the exit, instead of "all out", I would want the entry that hits the parameters first to exit first. For instance for the second entry to exit first if it hits the stop loss exit and the first entry to continue until it reaches any of the other exit parameters.

      Comment


        #4
        Hello 2Look4me,

        Thank you for your response.

        The Managed Order Approach would need the exits to be assigned a specific 'fromEntrySignal' which is generated from the entries and their 'signalName'. For example:

        Code:
                    if (MyEntryCondition)
                        EnterLong("Entry01");
                    if (MyExitCondition)
                        ExitLong("Entry01");
        Please visit the following link for more details: https://ninjatrader.com/support/help...d_approach.htm

        Please let me know if you have any questions.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Thanks Patrick. Since I'm scaling in, I'm using BarsSinceEntry, but apparently the number of bars counted start from the very first entry and continues counting those bars even after the second entry. What if I would like the BarsSinceEntry starting from the second entry instead of the bars from the very first entry?

          Comment


            #6
            Hello 2Look4me,

            Thank you for your response.

            You can also pass in the 'signalName' to the BarsSinceEntry, for example: BarsSinceEntry(string signalName). With this you would pass through the second signal name you use for the second entry.

            For more information on BarsSinceEntry() please visit the following link: https://ninjatrader.com/support/help...sinceentry.htm

            Please let me know if you have any questions.
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              Thanks Patrick, in essence this is what I'm attempting with the scale in, but still a bit confused about it cuz when I run it, the stored EntryHigh1 and EntryLow2 are out of whack as well as the rest.
              Code:
              if(Position.MarketPosition==MarketPosition.Flat)
                                  {
                                      if( Conditions A)
                                      {
                                          EnterLong("abc");
                                      }
                                  }
                                  if(Position.MarketPosition==MarketPosition.Long)
                                  {
                                      if(BarsSinceEntry("abc")==1 //After first bar ,set first High as EntryHigh1
                                      {
                                          EntryHigh1 = High[1];
                                      }
                                      else if( Conditions B)
                                      {
                                          ExitLong();
                                      }
                                      if(BarsSinceEntry("abc")>=2 && Close[0]>EntryHigh1) //Scale in when Close larger than EntryHigh1
                                      {
                                          EnterLong(2,"xyz");
                                      }
                                      if(BarsSinceEntry("xyz") ==1); //After first bar, set entry low as EntryLow2
                                      {
                                          EntryLow2 = Low{1];
                                      }
                                      else if(BarsSinceEntry("xyz" )>=2 && Close[0]<EntryLow2) //Exit all if Close < EntryLow2
                                      {
                                          ExitLong();
                                      }
                                  }

              Comment


                #8
                Hello 2Look4me,

                Thank you for your response.

                Can you provide further detail on the behavior you are seeing versus the intended behavior?
                Patrick H.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Patrick, I have attached a sample script. Sometimes the "High" that I'm getting doesn't correspond to the "High" of the Long Entry bar, but the bar that follows. And sometimes the "Low" that I'm getting doesn't correspond to the "Low" of the Short Entry bar, but the bar that follows the entry bar. The same happens when I scale in, just that I ddin't include that part of the script. Why is that?
                  Attached Files

                  Comment


                    #10
                    Hello 2Look4me,

                    Thanks for your reply.

                    Are you seeing this on live data, historical data, strategy analyzer historical data or market replay?

                    Please post a screenshot of a chart that demonstrates what you are seeing.

                    Please be sure to post so that we can see the full chart including the instrument, price scale, and timescale.


                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks for the reply Paul. This is based on market replay. The inconsistency happens with Long as well as Short entries

                      Comment


                        #12
                        Hello 2Look4me,

                        Thanks for your reply.

                        With Market replay and using CalculateOnBarClose = false, you are checking to see if the position is long (or short) and then checking to see if BarsSinceEntry() is equal to 1. If you set the BarsSinceEntry to 0 does that resolve the issue?
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          Setting the BarsSinceEntry to "0" will not resolve the issue. It will return the High of the bar prior to BarsSince Entry or at times return the High of the BarsSinceEntry. So it's the same inconsistency that I had when BarsSinceEntry was set to"1".
                          If "Long", I'm looking at the return of the "High" of the BarsSinceEntry or if "Short", the return of the "Low" of the BarsSinceEntry each and everytime.

                          Thanks

                          Comment


                            #14
                            Hello 2Look4me,

                            Thanks for your reply.

                            It looks like the inconsistency relates to the specific timing of the entry, for example, if it should occur at the last tick of the bar the BarsSinceEntry would be based on the following bar instead of the entry bar.

                            What I suggest is in the block of code where you place the order, to save the entry bar number in a variable and then add another block of code based on the condition if(CurrentBar - savedBar == 1) {get the previous bars High and low values}
                            Paul H.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by simonkloot, Today, 04:14 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post simonkloot  
                            Started by percma, Today, 02:00 AM
                            0 responses
                            2 views
                            0 likes
                            Last Post percma
                            by percma
                             
                            Started by antrux, Yesterday, 06:26 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post antrux
                            by antrux
                             
                            Started by kevinenergy, Yesterday, 03:34 PM
                            0 responses
                            16 views
                            0 likes
                            Last Post kevinenergy  
                            Started by Bidder, Yesterday, 01:50 PM
                            1 response
                            9 views
                            0 likes
                            Last Post NinjaTrader_PatrickG  
                            Working...
                            X