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

Triggering strategy by movement of price up or down X number of points

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

    #16
    Hello Jeff,

    Thanks for your note.

    If you are wanting to use a negative tick offset, you could set the 'Offset' field to use 'Ticks' and then specify a value of say "-10" to set the offset to -10 ticks.

    When it comes to using user-defined variables, you would need to define the variable value as a negative value, such as setting MovementDownTrigger = -10 in the script, then use the variable for your tick offset.

    If this is a user-defined input, you should set the user-defined input's 'Min' value to a negative value when creating the input on the Inputs and Variables screen and set the input's 'Default' value to a negative number like '-10'. That user-defined input could then be used for your tick offset field. Note the 'Min' values defines the minimum value the input can be set to.

    Let me know if I may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #17
      Thanks! In my strategy builder, once my entry is triggered, I want to wait until after the current bar is closed until I place my entry. I want to get filled at at the open of the next bar. Would I just change from on each tick to on bar close? Previously, my code was using 'on each tick' method. I just switched to 'on bar close'. The intent is that a bar triggers my strategy, it will wait to open the trade only once the next bar is formed rather that entering the trade immediately.


      Also, a trade just entered in the middle of the bar, even though I have 'on bar close'
      Click image for larger version

Name:	image.png
Views:	124
Size:	26.2 KB
ID:	1243000
      ​​
      Last edited by Jdmtrader; 03-27-2023, 11:57 AM.
      Jdmtrader
      NinjaTrader Ecosystem Vendor - JDM Indicators

      Comment


        #18
        Hello Jeff,

        Thanks for your note.

        If you want your entry order to be placed at the open of the next bar you could use Calculate.OnBarClose.

        If your strategy is set to run in the mode of Calculate.OnBarClose which means that the strategy code executes once at the end of each bar and will perform calculations on completed bars. If your strategy determines to enter an order, the order would be placed on the next bar.

        Note that this is for market Entry order methods such as EnterLong() and EnterShort().

        If you are using a limit order, such as EnterLongLimit() or EnterShortLimit(), the order will be filled as soon as the limit order price is reached as this is how they are programmed to function.

        There are no methods or properties available to prevent a limit order from being filled until the next bar forms if the limit order price is reached on the currently forming bar.

        Please let me know if I may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #19
          Its currently on bar close. However, its getting into the trade while the current bar is forming. See screenshot and code below. You can see where it got into the trade where my arrow is pointing, rather than waiting until the next bar formed and getting in there.

          Click image for larger version  Name:	image.png Views:	9 Size:	40.5 KB ID:	1243033


          Last edited by Jdmtrader; 03-28-2023, 03:07 PM.
          Jdmtrader
          NinjaTrader Ecosystem Vendor - JDM Indicators

          Comment


            #20
            Hello Jeff,

            Thanks for your note.

            Are you sure that the strategy enabled on the chart is set to use Calculate mode OnBarClose?

            Please remove the strategy from the chart window, re-add your strategy to the chart, ensure the 'Calculate' mode in the Properties section of the Strategies window is set to 'On bar close', and enable the strategy.

            I have attached a simple example script demonstrating submitting orders using EnterLong() and Calculate.OnBarClose. When we enable the script and the strategy places an order, the entry order marker appears on the next bar since the script is set to use Calculate.OnBarClose.

            See this demonstration video: https://brandonh-ninjatrader.tinytak...MF8yMTIwNDY1Nw

            Let me know if I may assist further.
            Attached Files
            Last edited by NinjaTrader_BrandonH; 03-27-2023, 03:29 PM.
            Brandon H.NinjaTrader Customer Service

            Comment


              #21
              Thanks. I dont see any attached script though.
              Jdmtrader
              NinjaTrader Ecosystem Vendor - JDM Indicators

              Comment


                #22
                Hello Jeff,

                I forgot to include the attachment in my post. I have modified my previous post to include the example script.

                Please let me know if I may assist further.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #23
                  Thanks. I looked up in the forums and it says I need to use liveuntilcancelled if I want to keep limit orders active after the end of end of a bar and not have to re-submit. Is it possible to add in liveuntilcancelled using the strategy builder? I'm not a coder and unlocking my code precludes me from being able to use the strategy builder for other changes.
                  Jdmtrader
                  NinjaTrader Ecosystem Vendor - JDM Indicators

                  Comment


                    #24
                    Hello Jeff,

                    Thanks for your notes.

                    That is correct. To keep a limit order active after the end of a bar, the isLiveUntilCancelled overload would need to be used. This requires unlocking the code from the Strategy Builder using the 'Unlock code' button and manually programming your script.

                    There are no options for using the isLiveUntilCancelled overload for limit orders in the Strategy Builder.

                    We have a reference sample linked here demonstrating how to keep orders alive in an unlocked script using the isLiveUntilCancelled overload: https://ninjatrader.com/support/help...ders_alive.htm

                    Please let me know if I may assist further.
                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #25
                      Im still confused as to how to adjust my script to use liveuntil cancelled. Here is my current script.


                      Last edited by Jdmtrader; 03-28-2023, 03:07 PM.
                      Jdmtrader
                      NinjaTrader Ecosystem Vendor - JDM Indicators

                      Comment


                        #26
                        Hello Jeff,

                        Thanks for your note.

                        The EnterLongLimit()/EnterShortLimit() method with the isLiveUntilCancelled overload seen below would need to be used for your Entry order methods.

                        EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)

                        EnterShortLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)

                        For example, the code for EnterLongLimit() in your script might look something like this:

                        EnterLongLimit(0, true, Convert.ToInt32(DefaultQuantity), Open[0], "");

                        The reference sample linked to in post # 24 could be viewed which demonstrates how to use this EnterLongLimit() method with the isLiveUntilCancelled overload.

                        Please let me know if I may assist further.
                        Brandon H.NinjaTrader Customer Service

                        Comment


                          #27
                          I am getting this error in my logs
                          Strategy 'SupplyDemandTraderV2Custom/282689671': An Enter() method to submit an entry order at '3/23/2023 1:00:10 PM' has been ignored. Please search on the term 'Internal Order Handling Rules that Reduce Unwanted Positions' in the Help Guide for detailed explanation.

                          If I see, does this mean the strategy may not working? Its highlighted in orange in the strategies section. How do I know if the strategy is working properly or not before a trade is actually placed?
                          Last edited by Jdmtrader; 03-28-2023, 10:46 AM.
                          Jdmtrader
                          NinjaTrader Ecosystem Vendor - JDM Indicators

                          Comment


                            #28
                            Hello Jeff,

                            Thanks for your notes.

                            This means that the strategy tried to submit an Entry order method but it was ignored because you are breaking an Internal Order Handling Rule in your script. The Managed Approach Internal Order Handling Rules are linked below.

                            Managed Approach Internal Order Handlin: Rules.https://ninjatrader.com/support/help...antedPositions

                            After re-reviewing the code you shared in post # 25, I see that you are using Set methods (SetProfitTarget) and EnterLongLimit().

                            You would need to modify your script by removing the SetProfitTarget() method from the script and use Exit methods, such as ExitLongLimit(), for your profit target orders.

                            I have attached an example script demonstrating using Exit methods for profit target and stop loss orders you could view.

                            Please let me know if I may assist further.
                            Attached Files
                            Brandon H.NinjaTrader Customer Service

                            Comment


                              #29
                              I updated my script to incorporate exit methods. However, if its highlighted in orange, does this mean its not going to work? I have no existing orders open for the product being traded.

                              Its doesn't appear to be working because its highlighted in yellow in strategies tab and it hasn't triggered any trades yet. below is my script. Is there some sort of log that will show any errors and confirm whether it really is working or will work once its triggered?



                              Last edited by Jdmtrader; 03-28-2023, 03:07 PM.
                              Jdmtrader
                              NinjaTrader Ecosystem Vendor - JDM Indicators

                              Comment


                                #30
                                Hello Jeff,

                                Thanks for your notes.

                                I see you are calling your Entry methods and Exit methods within the same condition.

                                Entry and Exit methods should not be called in the same condition. Entry order and Exit order methods need to be separated.

                                You should place your Exit methods in a separate condition. For example, you could create a new condition that checks if you are in a Long market position and then call your Exit methods within that condition.

                                The code might look something like this:
                                Code:
                                if ((IsRising(Close) == true)
                                && (Position.MarketPosition == MarketPosition.Flat)
                                && (Volume[0] <= MaxVolume)
                                && (Volume[0] >= MinVolume)
                                && (Close[0] > (Open[0] + (MovementUpTrigger * TickSize)) ))
                                {
                                    EnterLongLimit(0, true, Convert.ToInt32(Quantity), Open[0], @"MyEntry");
                                }
                                
                                if (Position.MarketPosition == MarketPosition.Long)
                                {
                                    ExitLongStopLimit(0, true, Convert.ToInt32(Quantity), 0, Low[1], @"MyStop", @"MyEntry");
                                    ExitLongLimit(0, true, Convert.ToInt32(Quantity), (High[0] + (TargetProfit * TickSize)) , @"TakeProfit", @"MyEntry");​
                                }​
                                A similar modification would need to be made for your short position. You would create a new condition that checks if you are in a short market position (Position.MarketPosition == MarketPosition.Short) and call your Exit order methods within that condition.

                                As for the strategy showing as yellow (or orange on some monitors), when a strategy is yellow (or orange) in the Strategies tab of the Control Center, this means that the strategy entered a historical (theoretical) position in the historical data that has been loaded.

                                It also means that you have "Wait until flat" selected for the 'Start behavior' option in the strategy parameters.

                                This means that once the strategy has finished processing the historical data and has transitioned to real-time, it will wait until there is a real-time order submission that will cause the strategy to become flat. This also includes changing from a long position to a short position or vice versa as the position would pass through flat.

                                This also applies to secondary instruments if there are added series to the script. All positions must be flat before real-time orders will begin.

                                You can change the start behavior to "Immediately submit" in the parameters of the strategy. Immediately Submit automatically submits working orders from when the strategy processed historical data, and assumes the strategy position and account position are where you want it when you enable the strategy. This is typically used to have a strategy resume a position after disabling/enabling. If the strategy already had live orders running, the orders will resume with the new enablement of the strategy if they match the historically calculated orders. If the orders calculated from historical data do not match the live working orders, the live working orders will be cancelled and replaced by those calculated from historical data.

                                Sync Account Positions is an additional option that has NinjaTrader submit an order to sync the account position to the position calculated by the strategy. (Not the other way around.)

                                If you do not want the strategy to calculate a position from processing historical data. Simple add if (State == State.Historical) return; to the top of your strategy logic so historical processing is skipped. The strategy will then always start from a flat position because it has not calculated any orders.

                                See the help guide documentation below for more information.
                                Strategy vs. Account Position — https://ninjatrader.com/support/help..._account_p.htm
                                Start Behaviors — https://ninjatrader.com/support/help..._positions.htm

                                Additional information could be found in this forum thread - https://ninjatrader.com/support/foru...ion#post811541

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

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by kujista, Today, 06:23 AM
                                5 responses
                                15 views
                                0 likes
                                Last Post kujista
                                by kujista
                                 
                                Started by f.saeidi, Today, 10:19 AM
                                0 responses
                                3 views
                                0 likes
                                Last Post f.saeidi  
                                Started by traderqz, Yesterday, 09:06 AM
                                2 responses
                                16 views
                                0 likes
                                Last Post traderqz  
                                Started by traderqz, Today, 12:06 AM
                                3 responses
                                6 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Started by RideMe, 04-07-2024, 04:54 PM
                                5 responses
                                28 views
                                0 likes
                                Last Post NinjaTrader_BrandonH  
                                Working...
                                X