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

Bollinger Strategy Issue

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

    Bollinger Strategy Issue

    Hi all, I try to write a new topic as I have not found anything about it.
    My problem is this: i am developing a strategy based on bollinger bands, it opens a short when the price closes above the high band and opens a long when the price closes below the low band.
    So far everything ok.

    the problem comes when I want the lot to increase only after the price drops 10 ticks, not before. what happens instead, opens new positions every time the price closes above or below the bollinger bands even if it does not exceed 10 ticks.

    how can I do to set up a sort of grid strategy together with the bands?

    thank you so much

    #2
    Hello DanieleC,

    Thank you for your post.

    Please clarify the following: "increase lot size". Are you wanting to scale into a position?

    I suggest checking if you are in a flat position (Position.MarketPosition == MarketPosition.Flat) for your order entry conditions. Then, to "increase lot size" you could check if you are in a Long or Short position (Position.MarketPosition == MarketPosition.Long or Position.MarketPosition == MarketPosition.Short) and check if the price drops 10 ticks from the price you store in a variable.

    See this help guide documentation for more information about creating MarketPosition checks - https://ninjatrader.com/support/help...etposition.htm

    Please let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      hi, thanks for the reply.
      yes what I meant was to open new positions if the price goes negative but only after 10 ticks, I am attaching an image to make it clear that the two short positions are open at 3945 and 3947, and it is not good, instead the second position it should only open after 10 ticks. like a grid.
      thanks

      Comment


        #4
        Hello DanieleC,

        Thank you for your note.

        If you would like to place an order when the price drops 10 ticks below the upper band while you are already in a position, in your order entry condition you could check if you are in a Short position using Position.MarketPosition == MarketPosition.Short and check if the price drops 10 ticks below the upper band in your order entry condition.

        See the help guide documentation in my previous post for more information about Position.MarketPosition.

        Let us know if we may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          maybe I could do that?

          protected override void OnBarUpdate()
          {
          if (Close[0] <= Position.AveragePrice - 10 * TickSize)
          OrderAction.Buy(Position.Quantity, Position.AveragePrice);
          }

          Comment


            #6
            Hello DanieleC,

            Thank you for your note.

            The condition you shared would check if the current Close price is less than or equal to 10 ticks below the average price of your position followed by calling OrderAction.Buy().

            OrderAction.Buy cannot be used as a method. Instead, you should use something like EnterLong() if you are using the managed approach or SubmitOrderUnmanaged() if you are using the unmanaged approach.

            See the help guide documentation below for information about the order methods for the managed approach and unmanaged approach.

            Managed approach - https://ninjatrader.com/support/help...d_approach.htm
            Unmanaged approach - https://ninjatrader.com/support/help...d_approach.htm

            Let us know if we may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              ok thanks then i should change it to >= 10 tick, and i will try EnterLong, thanks a lot

              Comment


                #8
                unfortunately it is not for me, because with the average price it is not good, I need a distance of 10 ticks from the price of the last order

                Comment


                  #9
                  Hello DanieleC,

                  Thank you for your note.

                  You could get the last trade made using TradeCollection. TradeCollection is a collection of Trade objects. You can access a trade object by providing an index value. Trades are indexed sequentially meaning the oldest trade taken in a strategy will be at an index value of zero. The most recent trade taken will be at an index value of the total trades in the collection minus 1.

                  See the example in the help guide documentation below for more information about how to get the last trade made.


                  Alternatively, you could monitor fills in OnExecutionUpdate and then set that price to a variable for future use after the first entry happened. See the SampleOnOrderUpdate example in the help guide documentation below for information about using OnExecutionUpdate methods

                  SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

                  Let us know if we may assist further.
                  Brandon H.NinjaTrader Customer Service

                  Comment


                    #10
                    thanks again but i can't implement this code, but another idea came to mind. if I put 10 ticks since the close of the last candle as a given what code should i use? thank you so much

                    Comment


                      #11
                      Hello DanieleC,

                      Thank you for your note.

                      If you are wanting to create a condition that checks if the current price is equal to the close of the last candle plus 10 ticks, the code would look as follows.

                      if (Close[0] == Close[1] + 10*TickSize)
                      {
                      // do something
                      }

                      Please let us know if you have further questions.
                      Brandon H.NinjaTrader Customer Service

                      Comment


                        #12
                        hi, I still need help. is there anyone who can give me a code example?

                        I would like, once an order has been opened, to increase another every time the price closes beyond 10 ticks.

                        For example, I open a short lot order at 1.17500 on 6E, then when the price exceeds or equals 10 negative ticks (1.17550) I open another short lot order. do this every last order placed.

                        thanks

                        Comment


                          #13
                          Hello DanieleC,

                          Thank you for writing in.

                          Please see the attached example script that demonstrates scaling into a position. Note that in the Strategies Properties window, you would need to set the Entries Per Direction property to the number of total orders you would like your strategy to place when enabling the strategy. For example, if you set Entries Per Direction to 5, the strategy will scale in another order until there are 5 orders placed in a single direction.

                          The way this script works is that we check if the current Close price is less than the current Open price and if we are in a flat position then calls EnterShort() with a signalName of 'myShortEntry". Then we check if we are in a short position and if the current Close price is less than or equal to the previous Close price minus 10 ticks and call EntherShort using the same signalName to scale into that position. Finally, the script checks if we are in a short position and if the current Close price is greater than or equal to the previous Close price plus 10 ticks, and calls ExitShort() using the 'myShortEntry' signalName to exit all short orders placed.

                          See the help guide documentation below for more information.
                          EnterShort() - https://ninjatrader.com/support/help...entershort.htm
                          Position.MarketPosition - https://ninjatrader.com/support/help...etposition.htm

                          Let us know if we may assist further.
                          Attached Files
                          Brandon H.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by George21, Today, 10:07 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post George21  
                          Started by Stanfillirenfro, Today, 07:23 AM
                          8 responses
                          23 views
                          0 likes
                          Last Post Stanfillirenfro  
                          Started by DayTradingDEMON, Today, 09:28 AM
                          2 responses
                          16 views
                          0 likes
                          Last Post DayTradingDEMON  
                          Started by navyguy06, Today, 09:28 AM
                          1 response
                          6 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Started by cmtjoancolmenero, Yesterday, 03:58 PM
                          8 responses
                          32 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Working...
                          X