Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stopmarket order wait for a number of bars

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

    Stopmarket order wait for a number of bars

    Hello,

    I'm new here. I would like to know how to define the parameters of the enterlongstopmarket such that it waits for a number of bars, after a pattern has been detected, to enter the market.

    Thanks.

    #2
    Hi Prisalice,
    Welcome to the forum :-).
    Here is one idea how to accomplish what you have in mind using the Strategy Builder (no coding in NinjaScript required).
    Step 1: Create a custom series (int), e.g. "TriggerBar".
    Step 2: Create an input parameter (int). e.g. "WaitForBars".
    Step 3: In "Set 1", check if your pattern = trigger occurred. If "YES", set the custom series TriggerBar[0] to the Current bar (number).
    Step 4: In "Set 2", check your pattern. If it did not occur again, set the custom series TriggerBar[0] to the value it had before, TriggerBar[0] =TriggerBar[1]. Otherwise, Step 3 will kick in again.
    Step 5: In "Set 3", check, if the Current bar (number) equals TriggerBar + WaitForBars (Offset). If "YES", enter the market. You had a pattern (trigger) and you waited a number of bars after the last occurrence of the pattern (trigger).
    Alternative: If you don't want a new occurrence of the pattern to update the TriggerBar[0] and delay your entry, consider to only increase TriggerBar[0], if CurrentBar - WaitForBars is greater than TriggerBar[0]. With that, only pattern occurences outside of the waiting period are considered relevant. In other words, you would fire a trade after the first occurrence of the pattern plus 1x waiting period, no matter if the same pattern occurred again.
    Have fun.
    NT-Roland
    Last edited by NT-Roland; 05-16-2021, 02:26 AM. Reason: Clarification that "WaitForBars" is a parameter.

    Comment


      #3
      Hello Prisalice,

      Welcome to the NinjaTrader forums!

      NinjaTrader_PaulH has an example of a bar counter in the Strategy Builder you may find helpful.
      https://ninjatrader.com/support/foru...on#post1078538

      Is this script you are making an unlocked script or something made in the strategy builder?

      NT-Roland, as always solid advice.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thanks Ronald and Chelsea.

        Maybe I didn't explain it well. I want to use this order to enter a long position:

        https://ninjatrader.com/support/help...stopmarket.htm

        Syntax
        EnterLongStopMarket(double stopPrice)
        EnterLongStopMarket(double stopPrice, string signa lName)
        EnterLongStopMarket(int quantity, double stopPrice )
        EnterLongStopMarket(int quantity, double stopPrice , string signalName)


        But I understood that this order will expire at the end of a bar and I would like to know if it is possible to configure this order to expire at the second, third or fourth bar and wait for the price to touch this order.

        Or I could also use this order:

        https://ninjatrader.com/es/support/h...terlongmit.htm

        Syntax
        EnterLongMIT(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double stopPrice, string signalName)

        But using "isLiveUntilCancelled" parameters.

        I would appreciate if you have examples of how to use these commands as I need.

        Thank you again.

        Prisalice.

        Comment


          #5
          Hello Prisalice,

          If you would like an order to remain alive and not automatically expire use true as the isLiveUntilCancelled parameter.

          EnterLongStopMarket(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double stopPrice, string signalName)
          https://ninjatrader.com/support/help...stopmarket.htm

          For example:
          EnterLongStopMarket(0, true, 1, High[0] + 5 * TickSize, "buyStopEntry");


          If you want to later cancel the order use CancelOrder() with the order object assigned to a variable in OnOrderUpdate().
          https://ninjatrader.com/support/help...rderupdate.htm
          https://ninjatrader.com/support/help...ancelorder.htm
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hello,

            Thank Chelsea.

            Prisalice.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by luxurious_04, Today, 10:55 PM
            0 responses
            1 view
            0 likes
            Last Post luxurious_04  
            Started by timmbbo, Today, 10:27 PM
            0 responses
            1 view
            0 likes
            Last Post timmbbo
            by timmbbo
             
            Started by 7robert, Today, 07:48 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_EricB  
            Started by saltminer, Today, 06:32 PM
            0 responses
            6 views
            0 likes
            Last Post saltminer  
            Started by caveat_lector, Today, 06:13 PM
            0 responses
            5 views
            0 likes
            Last Post caveat_lector  
            Working...
            X