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

AtmStrategyCreate

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

    AtmStrategyCreate

    Let me start by saying, I'm trying to help a friend with their strategy that won't compile.
    First, this is the code that was added to the strategy:

    Click image for larger version

Name:	Screenshot (23).png
Views:	173
Size:	153.9 KB
ID:	1271454Click image for larger version

Name:	Screenshot (22).png
Views:	160
Size:	102.0 KB
ID:	1271455

    This next part was included as a separate file like an Indicator.zip
    Click image for larger version

Name:	Screenshot (24).png
Views:	147
Size:	159.0 KB
ID:	1271456

    It won't compile and keeps throwing errors.

    I was thinking this next part was left out of the helper.file and maybe that's why it won't compile but IDK:

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {

    The only sample I have to go off of is this:
    [ATTACH]n1271457[/ATTACH]
    And it's not exactly the same structure/format as what we are trying to accomplish.

    If anyone can help us that would be greatly appreciated this is starting to look like spaghetti to me lol
    Thank You​

    #2
    Hello Fbraun378,

    Thanks for your post.

    This is not the supported way to call AtmStrategyCreate() in a custom NinjaScript strategy.

    AddProfitTarget() and AddStopLoss() are not supported methods documented in the NinjaTrader help guide. Further, the CreateOrder() method is used to create an order to submit to a specific account using the Account class (<Account>.CreateOrder()), not how to create an an Atm Strategy order.

    <Account>.CreateOrder(): https://ninjatrader.com/support/help...reateorder.htm

    I suggest that you use the supported Atm Strategy Methods seen in the SampleAtmStrategy reference sample that comes default with NinjaTrader. You would have to create and save an ATM Strategy Template in an order entry window such as Chart Trader or the SuperDOM. Then, you could call the AtmStrategyCreate() method as it is seen in the NinjaTrader help guide and pass in the name of the ATM Strategy Template you saved for the string strategyTemplateName argument when calling AtmStrategyCreate().

    AtmStrategyCreate(): https://ninjatrader.com/support/help...tegycreate.htm
    Atm Strategy Methods: https://ninjatrader.com/support/help...gy_methods.htm
    Using ATM Strategies in NinjaScript: https://ninjatrader.com/support/help...strategies.htm

    This forum thread will be open for other community members to share their insights on unsupported code.

    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thank You as always BrandonH
      Your answer is similar to what I was thinking. Some of it was in NT7 coding and there was an attempt at an indicator that was called to the strategy. It was a heck of a job to try to debug it.

      One more question please, the SampleAtmStrategy that comes with NT8, what areas do I fill out exactly? Sorry if I sound like a junior member. Most of the logic looks okay and I'm not completely familiar yet with the proper NT8 formatting. So I name my ATM Template, in chart trader, for example ATMHelper. Can I then just add it to the strategy like this:


      private string ATMHelper;

      protected override void OnStateChange()


      -> Is there anything below that I would need to adjust from the basic Strategy Builder format? Objects etc?? Like OrderId or atmStrategyId


      protected override void OnBarUpdate()

      (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0])
      {
      isAtmStrategyCreated = false;
      atmStrategyId = GetAtmStrategyUniqueId();
      orderId = GetAtmStrategyUniqueId();
      AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "ATMHelper", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {

      if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
      isAtmStrategyCreated = true;
      });
      }

      And then on the strategy itself order handling would be? Is this format also incorrect??

      {
      int quantity = CONTRACTS;
      double limitPrice = 0;
      double stopPrice = 0;
      _atmStrategy.CreateOrder(0, OrderAction.Buy, OrderType.Limit, quantity, limitPrice, stopPrice); //Changed OrderAction.BuyToOpen
      }​


      Also do I need to change 'Entry Handling' from "All Entries" to "Unique Entries" ??​

      Thank You Again
      FrankB
      Last edited by Fbraun378; 10-05-2023, 11:00 AM.

      Comment


        #4
        Hello FrankB,

        Thanks for your notes.

        First, you would need to make and save an ATM Strategy Template in say Chart Trader.

        ATM Strategy Templates: https://ninjatrader.com/support/help...gement_atm.htm

        Then, you would pass in the name of the ATM Strategy Template you created for the strategyTemplateName parameter when calling AtmStrategyCreate().

        For example, if the name of the ATM Strategy Template is 'ATMHelper' then the code might look like the code you shared seen below.

        AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "ATMHelper", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
        if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
        isAtmStrategyCreated = true;
        });


        ​The SampleAtmStrategy reference sample that comes default with NinjaTrader demonstrates this. The strategy uses an ATM Strategy Template named 'AtmStrategyTemplate' in its code.

        Please review the SampleAtmStrategy reference sample by opening a New > NinjaScript Editor window, open the Strategies folder, and double-click on the SampleAtmStrategy file.

        Atm Strategy Methods: https://ninjatrader.com/support/help...gy_methods.htm

        "protected override void OnStateChange()
        -> Is there anything below that I would need to adjust from the basic Strategy Builder format?​"


        No, you would likely not need to change anything in OnStateChange(). This could be seen in the SampleAtmStrategy reference sample noted above.

        "And then on the strategy itself order handling would be? Is this format also incorrect??"

        Yes, this is incorrect. You cannot call CreateOrder() to create an Atm Strategy. AtmStrategyCreate() must be used to submit an entry order that has an ATM Strategy Template attached.

        See this help guide page about AtmStrategyCreate(): https://ninjatrader.com/support/help...egycreate.htm:

        "Also do I need to change 'Entry Handling' from "All Entries" to "Unique Entries" ??​"

        This would ultimately be up to you. EntriesPerDirection and EntryHandling could be used to control the maximum number of entries allowed per direction while a position.

        If you set Entry Handling to EntryHandling.AllEntries, NinjaScript will process all entry order methods up to the maximum allowable entries set in the EntriesPerDirection property. For example, if you set EntriesPerDirection to 3 and use EntryHandling.AllEntries, up to a total of 3 entry orders will process.

        If you set Entry Handling to EntryHandling.UniqueEntries, NinjaScript will process order entry methods up to the maximum allowable entries set by the EntriesPerDirection property for each uniquely named entry. For example, if you have two entry order methods using unique signal names ("entry1" and "entry2"), set EntriesPerDirection to 3, and use EntryHandling.UniqueEntries, a maximum number of 3 entry orders will process for each uniquely named entry order (up to 3 orders for "entry1" and 3 orders for "entry2").

        See the help guide documentation below for more information.

        EntriesPerDirection: https://ninjatrader.com/support/help...rdirection.htm
        EntryHandling: https://ninjatrader.com/support/help...ryhandling.htm
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thank You Brandon
          You answered and confirmed all of my concerns! I have a bit of experience with .js & .py programming and .cs is definitely about following the supported code structure.
          Last edited by Fbraun378; 10-06-2023, 09:44 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by SaltyCoffee, Today, 01:13 AM
          0 responses
          5 views
          0 likes
          Last Post SaltyCoffee  
          Started by FishTrade, 05-13-2024, 11:11 PM
          3 responses
          13 views
          0 likes
          Last Post FishTrade  
          Started by Graci117, Yesterday, 09:02 PM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by ETFVoyageur, Yesterday, 07:55 PM
          0 responses
          10 views
          0 likes
          Last Post ETFVoyageur  
          Started by janio973, Yesterday, 07:24 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X