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

ATM strategy place an order on a secondary data series

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

    ATM strategy place an order on a secondary data series

    Can I have an ATM strategy place an order on a secondary data series in a ninjascript strategy?

    #2
    Hello Lance El Camino,

    I've moved your new inquiry that is not related to forum thread this was posted in to a new forum thread.

    Atm Strategy methods are completely outside of a NinjaScript Strategy. These are not attached to the bars or series. These will not affect the position, and will not trigger any strategy order methods like OnOrderUpdate().

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

    Meaning, you can call an AtmStrategy method at any time, in any series, because the two are not related.


    If instead, you mean placing entry and exit orders using strategy order methods, yes, you can place orders to a secondary series.

    Below is a link to the reference sample that demonstrates.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I'm trying to place an order on a secondary series using ATM:

      if (longOrderId.Length == 0 && longAtmId.Length == 0 && !isLongAtmStrategyCreated)
      {
      longOrderId = GetAtmStrategyUniqueId();
      longAtmId = GetAtmStrategyUniqueId();
      AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Gtc, longOrderId, "ES Tick", longAtmId, (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 == longAtmId)
      isLongAtmStrategyCreated = true;
      });

      AtmStrategyCreate() doesn't have an option to place order on certain Bars In Progress index so is the default the primary BIP? Is there a way to assign AtmStrategyCreate to another BIP?

      Comment


        #4
        Hi Lance, thanks for writing in. You can use the ATM methods when BarsInProgress == 1 to submit the order to the secondary series:

        Code:
        In OnBarUpdate:
        
        if(BarsInProgress == 1)
        {
            //launch the ATM here
        }
        Kind regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          I tried that and it didn't work. Would that be before or after the condition to enter?

          Comment


            #6
            Here's what I have

            // Set 1
            if ((TICKPercent1.PercentUp[0] >= (TICKPercent1.PercentUp[1] + TICKPctChangeLong) && (TICKPercent1.PercentUp[0] >= TICKPercentLevelLong)))
            {
            Print("ATM Long condition at : " + Time[0]);
            // If there is a short ATM Strategy running close it.
            if(shortAtmId.Length != 0 && isShortAtmStrategyCreated)
            {
            AtmStrategyClose(shortAtmId);
            isShortAtmStrategyCreated = false;
            }
            // Ensure no other long ATM Strategy is running.
            if (longOrderId.Length == 0 && longAtmId.Length == 0 && !isLongAtmStrategyCreated)
            {
            longOrderId = GetAtmStrategyUniqueId();
            longAtmId = GetAtmStrategyUniqueId();
            AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Gtc, longOrderId, "ES Tick", longAtmId, (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 == longAtmId)
            isLongAtmStrategyCreated = true;
            });
            }
            }

            Comment


              #7
              Hi Lance, You would run all the ATM code and your price condition within BarsInProgress == 1. I attached my test script for reference "Test Multi Time Frame ATM". Run this on any instrument, and it will submit an order to the added series.

              Kind regards,
              -ChrisL
              Attached Files
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                I'll give it a whirl thanks!

                Comment


                  #9
                  Here's what I have. Nothing prints to output and no entrances. BIP 2 is the ES where I want orders placed. The primary data series is ^TICK where I prefer the OnBarUpdates to take place.


                  if (BarsInProgress == 2)
                  {
                  Print(TICKPercent1.PercentUp[0]);
                  Print(TICKPercent1.PercentDown[0]);
                  Print("tick count:" + Bars.TickCount.ToString() + Time[0]);

                  // Check any pending long or short orders by their Order Id and if the ATM has terminated.
                  // Check for a pending long order.
                  if (longOrderId.Length > 0)
                  {
                  // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements.
                  string[] status = GetAtmStrategyEntryOrderStatus(longOrderId);
                  if (status.GetLength(0) > 0)
                  {
                  // If the order state is terminal, reset the order id value.
                  if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
                  longOrderId = string.Empty;
                  }
                  } // If the strategy has terminated reset the strategy id.
                  else if (longAtmId.Length > 0 && GetAtmStrategyMarketPosition(longAtmId) == Cbi.MarketPosition.Flat)
                  {
                  longAtmId = string.Empty;
                  isLongAtmStrategyCreated = false;
                  }
                  // Check for a pending short order.
                  if (shortOrderId.Length > 0)
                  {
                  // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements.
                  string[] status = GetAtmStrategyEntryOrderStatus(shortOrderId);
                  if (status.GetLength(0) > 0)
                  {
                  // If the order state is terminal, reset the order id value.
                  if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
                  shortOrderId = string.Empty;
                  }
                  } // If the strategy has terminated reset the strategy id.
                  else if (shortAtmId.Length > 0 && GetAtmStrategyMarketPosition(shortAtmId) == Cbi.MarketPosition.Flat)
                  {
                  shortAtmId = string.Empty;
                  isShortAtmStrategyCreated = false;
                  }
                  // End check.

                  // Set 1
                  if ((TICKPercent1.PercentUp[0] >= (TICKPercent1.PercentUp[1] + TICKPctChangeLong) && (TICKPercent1.PercentUp[0] >= TICKPercentLevelLong)))
                  {
                  Print("ATM Long condition at : " + Time[0]);
                  // If there is a short ATM Strategy running close it.
                  if(shortAtmId.Length != 0 && isShortAtmStrategyCreated)
                  {
                  AtmStrategyClose(shortAtmId);
                  isShortAtmStrategyCreated = false;
                  }
                  // Ensure no other long ATM Strategy is running.
                  if (longOrderId.Length == 0 && longAtmId.Length == 0 && !isLongAtmStrategyCreated)
                  {
                  longOrderId = GetAtmStrategyUniqueId();
                  longAtmId = GetAtmStrategyUniqueId();
                  AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Gtc, longOrderId, "ES Tick", longAtmId, (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 == longAtmId)
                  isLongAtmStrategyCreated = true;
                  });
                  }
                  }

                  // Set 2
                  if ((TICKPercent1.PercentDown[0] <= (TICKPercent1.PercentDown[1] + TICKPctChangeShort) && (TICKPercent1.PercentDown[0] <= TICKPercentLevelShort)))
                  {

                  Print("Short condition at " + Time[0]);
                  // If there is a long ATM Strategy running close it.
                  if(longAtmId.Length != 0 && isLongAtmStrategyCreated)
                  {
                  AtmStrategyClose(longAtmId);
                  isLongAtmStrategyCreated = false;
                  }
                  // Ensure no other short ATM Strategy is running.
                  if(shortOrderId.Length == 0 && shortAtmId.Length == 0 && !isShortAtmStrategyCreated)
                  {
                  shortOrderId = GetAtmStrategyUniqueId();
                  shortAtmId = GetAtmStrategyUniqueId();
                  AtmStrategyCreate(OrderAction.SellShort, OrderType.Market, 0, 0, TimeInForce.Gtc, shortOrderId, "ES Tick", shortAtmId, (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 == shortAtmId)
                  isShortAtmStrategyCreated = true;
                  });

                  }
                  }
                  }​

                  Comment


                    #10
                    Hi Lance, please make sure your prints are coming through when the strategy is processing within if (BarsInProgress == 2) {}, The time I can spend reviewing and debugging custom code will be limited, please use the example that I posted earlier as this one is working fine. The best way to debug and see where the code is reaching is to use Prints and also watch the Log tab of the Control Center for any errors.

                    Kind regards,
                    -ChrisL
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      The prints are within BIP ==2.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by rhyminkevin, Today, 04:58 PM
                      3 responses
                      47 views
                      0 likes
                      Last Post Anfedport  
                      Started by iceman2018, Today, 05:07 PM
                      0 responses
                      5 views
                      0 likes
                      Last Post iceman2018  
                      Started by lightsun47, Today, 03:51 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post lightsun47  
                      Started by 00nevest, Today, 02:27 PM
                      1 response
                      14 views
                      0 likes
                      Last Post 00nevest  
                      Started by futtrader, 04-21-2024, 01:50 AM
                      4 responses
                      50 views
                      0 likes
                      Last Post futtrader  
                      Working...
                      X