Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dynamically selecting an ATM strategy from a ninjascript strategy

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

    Dynamically selecting an ATM strategy from a ninjascript strategy

    Hi,

    I have a strategy that may enter positions from three different strategy setups. Call them S1, S2, S3. Each one requires a different ATM strategy. The ATM sample you provide requires the existence of "AtmStrategyTemplate". I need to be able to call from the strategy script the ATM templates "S1", or "S2", or "S3", instead.

    Can this be done, and how?

    Thank you.

    #2
    Hello,
    instead of calling an ATM, with few lines of code, I think you would be able to code those 3 ATM strategies withinn 3 groups of code where you would define the buy and the exits the way you want it.

    I dont know if an ATM can be called with code but I know you can define the buy/short and the sell/buy to close and stop loss with lines of code. That's a way it can be done, for sure.

    Here is all the code examples you could need to code what you want:



    Comment


      #3
      Hello bobperez,

      Thanks for your post.

      When using Atm Strategy Methods in a custom NinjaScript strategy, you would need to call AtmStrategyCreate() and specify the ATM Strategy Template that you want to use for that order.

      For example, in the SampleAtmStrategy sample script we have an ATM Strategy Template created called 'AtmStrategyTemplate' and then we call AtmStrategyCreate() and specify "AtmStrategyTemplate" for the 'string strategyTemplateName' argument in that method. This submits an entry order with the ATM Strategy Template called 'AtmStrategyTemplate' attched.

      If you want to submit an entry order and use an ATM Strategy Template called 'S1', you would need to create that ATM Strategy Template called S1 in say Chart Trader, and then specify that ATM Strategy Template name in the AtmStrategyCreate() method.

      AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "S1", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
      //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
      if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
      isAtmStrategyCreated = true;
      });


      If you want to submit an entry order and use an ATM Strategy Template called 'S2', you would need to create that ATM Strategy Template called S2 in say Chart Trader, and then specify that ATM Strategy Template name in the AtmStrategyCreate() method.

      AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "S2", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
      //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
      if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
      isAtmStrategyCreated = true;
      });


      ATM Strategy Methods: https://ninjatrader.com/support/help...gy_methods.htm
      Using ATM Strategies: https://ninjatrader.com/support/help...strategies.htm

      Or, you could consider doing what Bricolico shared and code your entry/stops/targets/exits within the NinjaScript strategy itself instead of using ATM Strategy Templates.


      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment


        #4
        Originally posted by Bricolico View Post
        Hello,
        instead of calling an ATM, with few lines of code, I think you would be able to code those 3 ATM strategies within 3 groups of code where you would define the buy and the exits the way you want it.

        I don't know if an ATM can be called with code but I know you can define the buy/short and the sell/buy to close and stop loss with lines of code. That's a way it can be done, for sure.

        Here is all the code examples you could need to code what you want:

        https://ninjatrader.com/support/help...injascript.htm
        Thank you Bricolico for your input. The way I have it set up right now is as you suggest. All the trade management is done from within the strategy via user-definable parameters from the properties window. I want to share this strategy with other people and allow them to use the external ATM strategies so they can have more control over the number of contracts plus the excellent functionality that such external ATM strategies Ninja provides.

        By the way, the code example that you referenced took me to this page. Is there a specific code example that I should look for? I do have all of the Educational Resources downloaded to my computer, and they have been very useful.
        Click image for larger version  Name:	image.png Views:	0 Size:	72.2 KB ID:	1266347
        Last edited by bobperez; 08-27-2023, 08:12 PM.

        Comment


          #5
          Originally posted by NinjaTrader_BrandonH View Post
          Hello bobperez,

          Thanks for your post.

          When using Atm Strategy Methods in a custom NinjaScript strategy, you would need to call AtmStrategyCreate() and specify the ATM Strategy Template that you want to use for that order.

          For example, in the SampleAtmStrategy sample script we have an ATM Strategy Template created called 'AtmStrategyTemplate' and then we call AtmStrategyCreate() and specify "AtmStrategyTemplate" for the 'string strategyTemplateName' argument in that method. This submits an entry order with the ATM Strategy Template called 'AtmStrategyTemplate' attched.

          If you want to submit an entry order and use an ATM Strategy Template called 'S1', you would need to create that ATM Strategy Template called S1 in say Chart Trader, and then specify that ATM Strategy Template name in the AtmStrategyCreate() method.

          AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "S1", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
          //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
          if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
          isAtmStrategyCreated = true;
          });


          If you want to submit an entry order and use an ATM Strategy Template called 'S2', you would need to create that ATM Strategy Template called S2 in say Chart Trader, and then specify that ATM Strategy Template name in the AtmStrategyCreate() method.

          AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "S2", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
          //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
          if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
          isAtmStrategyCreated = true;
          });


          ATM Strategy Methods: https://ninjatrader.com/support/help...gy_methods.htm
          Using ATM Strategies: https://ninjatrader.com/support/help...strategies.htm

          Or, you could consider doing what Bricolico shared and code your entry/stops/targets/exits within the NinjaScript strategy itself instead of using ATM Strategy Templates.


          Thank you, Brandon, for your concise explanation. However, I still have a lingering question. If the Ninjascript identifies a trade of type 's1,' it will trigger the 'S1' ATM strategy, following your provided example. Furthermore, this 'S1' strategy must be designated within the Chart Trader panel to be applicable. Now, considering a scenario where a trade of type 'S2' is initiated and generates an order necessitating the 'S2' ATM strategy, it appears that the system won't recognize it due to the active status of 'S1.' Could you kindly confirm whether my understanding is accurate? If so, I'm interested in learning if there exists any workaround to address this situation.

          Comment


            #6
            Hello bobperez,

            Thanks for your post.

            If the strategy calls AtmStrategyCreate() and uses the ATM Strategy Template called "S1", the entry order would be placed with the "S1" ATM Strategy Template. Yes, an ATM Strategy Template would need to be created in Chart Trader and saved with the name "S1".

            If the strategy then calls AtmStrategyCreate() again to place another order but this time uses the ATM Strategy Template called "S2", another entry order would be placed with the "S2" ATM Strategy Template applied. You would also need to have an ATM Strategy Template created in Chart Trader and saved with the name "S2".

            This means that you would need two ATM Strategy Templates saved in Chart Trader. One saved with the name "S1" and one saved with the name "S2".

            See the ATM Strategy Methods help guide page for more information about the available methods for using ATM Strategies in a custom NinjaScript.

            Also, you could view the SampleAtmStrategy reference sample that comes default with NinjaTrader for an example of using Atm Strategy Methods in NinjaScript. To view the script, open a New > NinjaScript Editor window, open the Strategies folder in the Editor, and double-click on the SampleAtmStrategy file.
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              Originally posted by NinjaTrader_BrandonH View Post
              Hello bobperez,

              Thanks for your post.

              If the strategy calls AtmStrategyCreate() and uses the ATM Strategy Template called "S1", the entry order would be placed with the "S1" ATM Strategy Template. Yes, an ATM Strategy Template would need to be created in Chart Trader and saved with the name "S1".

              If the strategy then calls AtmStrategyCreate() again to place another order but this time uses the ATM Strategy Template called "S2", another entry order would be placed with the "S2" ATM Strategy Template applied. You would also need to have an ATM Strategy Template created in Chart Trader and saved with the name "S2".

              This means that you would need two ATM Strategy Templates saved in Chart Trader. One saved with the name "S1" and one saved with the name "S2".

              See the ATM Strategy Methods help guide page for more information about the available methods for using ATM Strategies in a custom NinjaScript.

              Also, you could view the SampleAtmStrategy reference sample that comes default with NinjaTrader for an example of using Atm Strategy Methods in NinjaScript. To view the script, open a New > NinjaScript Editor window, open the Strategies folder in the Editor, and double-click on the SampleAtmStrategy file.
              Thanks again, Brandon. I'm wondering if the ATM template needs to be the currently active one for the strategy to call it, or can it be invoked even if it's created but not currently active?

              Comment


                #8
                Hello bobperez,

                Thanks for your notes.

                No, the ATM Strategy Template does not have to be the currently active/selected strategy in the Chart Trader window. The ATM Strategy Template simply needs to be created and saved on the platform.

                As long as the ATM Strategy Template has been created and saved, it will be triggered when AtmStrategyCreate() is called.

                Please let us know if we may assist further.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment


                  #9
                  Originally posted by NinjaTrader_BrandonH View Post
                  Hello bobperez,

                  Thanks for your notes.

                  No, the ATM Strategy Template does not have to be the currently active/selected strategy in the Chart Trader window. The ATM Strategy Template simply needs to be created and saved on the platform.

                  As long as the ATM Strategy Template has been created and saved, it will be triggered when AtmStrategyCreate() is called.

                  Please let us know if we may assist further.
                  Fantastic! Thank you, Brandon.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Yesterday, 05:17 AM
                  0 responses
                  58 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  133 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  73 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  45 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  50 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X