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

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.
      with regard to the attached image: Line A is an indicator Line B is the m period MAX of line A Line C is an average of this indicator A Line D is another average of this indicator A is it possible, possibly using the strategy builder, but without adding a temporary variable, to set on the condition: line C crosses below line D


      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:



        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:



        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().

          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hello,

            Thank Chelsea.

            Prisalice.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Mongo, Today, 11:05 AM
            4 responses
            14 views
            0 likes
            Last Post Mongo
            by Mongo
             
            Started by traderqz, Today, 12:06 AM
            7 responses
            14 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by Skifree, Today, 03:41 AM
            5 responses
            13 views
            0 likes
            Last Post Skifree
            by Skifree
             
            Started by traderqz, Yesterday, 09:06 AM
            5 responses
            35 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by guillembm, Today, 11:25 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X