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

enter order and atmstrategy start

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

    enter order and atmstrategy start

    hi,
    I am trying to enter long/short, but when it executes that, I am trying to start a selected atmstrategy. currently I am using AtmStrategy.StartAtmStrategy(), but its not starting atm strategy. Can you pls advise?

    #2
    Hello asmmbillah,

    Thanks for your post.

    If the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true or the order is being ignored for other reasons.

    To understand why the script is behaving as it is, such as placing orders or not placing orders or when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Below is a link to a forum post that demonstrates using prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    Also, see the SampleAtmStrategy script that comes default with NinjaTrader for an example of using Atm Strategy templates in a NinjaScript strategy. To view SampleAtmStrategy, open a New > NinjaScript Editor window, open the Strategies folder, and select the SampleAtmStrategy file.

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

    Comment


      #3
      It is placing the entry order but, not starting the atm strategy. I have tested with prints, it returns the correct atm name, but does not start. see the code below:
      AtmStrategy.StartAtmStrategy(atm.SelectedAtmStrate gy, EnterLong(Convert.ToInt32(OrderQty), @"Long"));

      Comment


        #4
        Hello asmmbillah,

        Thanks for your note.

        Please see the attached example script which demonstrates using StartAtmStrategy() to submit an entry order with an ATM strategy. The example script checks if the account is not null, then we assign account.CreateOrder() to our entryOrder object create our entry order. Once the entry order is created, we call AtmStrategy.StartAtmStrategy("template name", entryOrder) to submit our entry order with an ATM strategy.

        Also, see this help guide page for more information: https://ninjatrader.com/support/help...tmstrategy.htm

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

        Comment


          #5
          Thanks for your reply. It does help with syntax. But now I am facing another problem. even though I am checking for position to be flat, still its keep placing orders. See my codes below:
          Code:
          if (atm.SelectedAtmStrategy.Name != "None" && Position.MarketPosition == MarketPosition.Flat)
          {
          if (account != null)
          {
          Order entryOrder = account.CreateOrder(this.Instrument, OrderAction.Buy, OrderType.Market, TimeInForce.Gtc, OrderQty, 0, 0, string.Empty, "Entry", null);
          AtmStrategy.StartAtmStrategy(atm.SelectedAtmStrate gy, entryOrder);
          }
          }
          And also I would appreciate, if you could advise how to exit that entry position ie syntax. I have tried many from your help guide, no success.
          Last edited by asmmbillah; 07-01-2021, 06:55 AM.

          Comment


            #6
            Hello asmmbillah,

            Thanks for your note.

            Since orders are being submitted directly to the account, you would need to check if PositionAccount.MarketPosition == MarketPosition.Flat instead of checking Position.MarketPosition. (Strategy positions are separate from Account positions).

            PositionAccount: https://ninjatrader.com/support/help...ionaccount.htm

            Since you are submitting an entry order with an ATM template, you would need to exit the entry order using the ATM template's Profit Target and Stop Loss. If you do not want to use the ATM template to exit the position, you would need to submit an entry order without the ATM template and then submit an exit order to exit the open position.

            Let us know if we may assist further.

            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Thanks for that. But I am not clear about when you said 'submit an entry order without the ATM template and then submit an exit order to exit the open position.' So do you want me to create and entry order first. Ok I can do that. But I am not sure what you mean by submit an exit order. Can you please point me to the right direction here? And, I wanted to close the atm template as well, but will it close after the exit execution?
              Last edited by asmmbillah; 07-01-2021, 08:55 AM.

              Comment


                #8
                Hello asmmbillah,

                Thanks for your note.

                If you submit an entry order with an ATM template by using StartAtmStrategy(), you would need to use the Profit Target/Stop Loss made by the ATM template to exit the entry order.

                Otherwise, you could use CreateOrder() to create your entry order (ex: a buy order) and Submit() to submit that entry order to the account. This will submit an entry order without an ATM template. Then, you could use CreateOrder() to create an exit order (ex: a sell order) and Submit() to submit that order to the account to exit the entry order.

                See the help guide documentation below for more information.

                CreateOrder() - https://ninjatrader.com/support/help...reateorder.htm

                Submit() — https://ninjatrader.com/support/help...t8/?submit.htm

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

                Comment


                  #9
                  Thanks, but its not what actually my question. As you said, if I submit order with atmtemplate using StartAtmStrategy(), which I am and now I am exiting by creating an order to exit. But my atmtemplate remains active after the exit. Is there anyway to close the atm template or is there any other way to submit order with atmtemplate without using StartAtmStrategy(), if that is restricting me? I am can see atmstrategyclose(), is that something related? Looking forward to your guidance.
                  Last edited by asmmbillah; 07-01-2021, 09:13 AM.

                  Comment


                    #10
                    Hello asmmbillah,

                    Thanks for your note.

                    Are you submitting an order outside of the ATM template to exit an entry position? ATM templates cannot be combined with any other order submission approaches.

                    Using ATM templates will place a Profit Target and Stop Loss order attached to the entry order you submitted. Then when the Target/Stop is filled, the other is canceled and the ATM template will stop. If you are submitting an order outside of the ATM template to exit a position, this may prevent the ATM template from working correctly. Only the Target/Stop made by the ATM template should be used to exit the entry order that was placed with an ATM template.

                    That said, please review the SampleAtmStrategy script that comes default with NinjaTrader to see how ATM strategy templates are used in a custom NinjaScript. To view the script, open a New > NinjaScript Editor window, open the Strategies folder, and select the SampleAtmStrategy script.

                    NinjaScript Strategy approach ATM methods (seen in SampleAtmStrategy) will provide more functionality and customization than AddOn approach ATM methods such as checking the status of an ATM. Note that AtmStrategyClose() would have to be used while the ATM template is active and before the targets fill/disable.

                    Also, see this help guide page about the NinjaScript Strategy approach ATM methods: https://ninjatrader.com/support/help...gy_methods.htm

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

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Aviram Y, 08-09-2023, 09:04 AM
                    10 responses
                    298 views
                    0 likes
                    Last Post MrHump
                    by MrHump
                     
                    Started by jpapa, Today, 07:22 AM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by kevinenergy, 02-17-2023, 12:42 PM
                    116 responses
                    2,758 views
                    1 like
                    Last Post kevinenergy  
                    Started by franatas, 12-04-2023, 03:43 AM
                    7 responses
                    106 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by Jltarrau, Today, 05:57 AM
                    3 responses
                    9 views
                    0 likes
                    Last Post Jltarrau  
                    Working...
                    X