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

output window says ATMID = 0

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

    output window says ATMID = 0

    complete newbie here, so may be asking too much, but in trying to call an ATM strategy in my strategy, i copied the text from the example ATM strategy provided by Ninjatrader. I moved the if(orderID.Length == 0... line to my conditions area and replaced the strategy name with the name of the ATM I have setup, "ES2ctr"

    It doesn't work.. the output file says the following:
    **NT** GetAtmStrategyUnrealizedProfitLoss() method error: AtmStrategyId '3d7c7987ce394ab3b2c34ca1fc119bf6' does not exist
    The current ATM Strategy Unrealized PnL is: 0
    2/16/2016 10:20:24 AM CancelAllOrders: BarsInProgress=0
    **NT** Disabling NinjaScript strategy 'RGESATM/fc32935ead4842cb927e2d357022cb96'
    **NT** Enabling NinjaScript strategy 'RGESATM/fc32935ead4842cb927e2d357022cb96' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=True MaxRestarts=4 in 5 minutes
    **NT** ATM Strategies can't be created on historical data
    **NT** GetAtmStrategyEntryOrderStatus() method error: orderId 'fc906912a689433ea52a3fdd7d114306' does not exist
    **NT** GetAtmStrategyMarketPosition() method error: AtmStrategyId 'f10d5b9c06354a3d91f6c751c8a1bf98' does not exist
    **NT** GetAtmStrategyMarketPosition() method error: AtmStrategyId 'f10d5b9c06354a3d91f6c751c8a1bf98' does not exist
    The current ATM Strategy market position is: Flat
    **NT** GetAtmStrategyPositionQuantity() method error: AtmStrategyId 'f10d5b9c06354a3d91f6c751c8a1bf98' does not exist
    The current ATM Strategy position quantity is: 0
    **NT** GetAtmStrategyPositionAveragePrice() method error: AtmStrategyId 'f10d5b9c06354a3d91f6c751c8a1bf98' does not exist
    The current ATM Strategy average price is: 0
    **NT** GetAtmStrategyUnrealizedProfitLoss() method error: AtmStrategyId 'f10d5b9c06354a3d91f6c751c8a1bf98' does not exist
    The current ATM Strategy Unrealized PnL is: 0


    the strategy text follows as well:

    {
    // Condition set 1 short
    if (orderId.Length == 0 && atmStrategyId.Length == 0
    && Close[0] < Open[0] )
    {
    DrawDot("" + CurrentBar, false, 0, High[0] + 2 * TickSize, Color.Red);
    // Submits an entry limit order at the current low price to initiate an ATM Strategy if both order id and strategy id are in a reset state
    // **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'AtmStrategyTemplate' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK ****

    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Cbi.OrderAction.Sell, OrderType.Market, Close[0], 0, TimeInForce.Day, orderId, "ES2ctr", atmStrategyId);



    // Check for a pending entry order
    if (orderId.Length > 0)
    {
    string[] status = GetAtmStrategyEntryOrderStatus(orderId);

    // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
    if (status.GetLength(0) > 0)
    {
    // Print out some information about the order to the output window
    Print("The entry order average fill price is: " + status[0]);
    Print("The entry order filled amount is: " + status[1]);
    Print("The entry order order state is: " + status[2]);

    // If the order state is terminal, reset the order id value
    if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
    orderId = string.Empty;
    }
    } // If the strategy has terminated reset the strategy id
    else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
    atmStrategyId = string.Empty;


    if (atmStrategyId.Length > 0)
    {
    // You can change the stop price
    if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
    AtmStrategyChangeStopTarget(0, Low[0] - 2 * TickSize, "STOP1", atmStrategyId);

    // Print some information about the strategy to the output window
    Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));
    Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));
    Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId)) ;
    Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId)) ;
    }
    }

    #2
    Hi rsmtrade

    One thing that may throw you off, is that once the entry order is filled, there is a moment where the stop loss and profit target are being submitted and becoming working. In that moment you may get an error message that the atm strategy does not exist, and then right after it will.

    This might be happening in your output. I see:
    **NT** GetAtmStrategyUnrealizedProfitLoss() method error: AtmStrategyId '3d7c7987ce394ab3b2c34ca1fc119bf6' does not exist

    And then right after:
    The current ATM Strategy Unrealized PnL is: 0

    But then all orders from the strategy are cancelled and the strategy is disabled.

    Right now, there is not a way to prevent these errors from appearing but as long as the strategy becomes working they can be ignored.


    Also, keep in mind that Atm Strategy Commands only work in real time and do not work historically.
    **NT** ATM Strategies can't be created on historical data

    Be sure you have an if (Historical) return; in your code.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      it doesn't work on replay data... that's the data i was using that generated the output window

      Comment


        #4
        could it have something to do with this line? orderId.Length == 0 && atmStrategyId.Length == 0


        because i have the strategy drawing a dot at the bars that meet my conditions, and i put the "orderId.Length == 0 && atmStrategyId.Length == 0" before any other conditions

        now the dot doesn't draw either

        Comment


          #5
          Hi rsmtrade,

          The check that the orderId.Length and atmStrategyId.Length being 0, is simply to know that there isn't an order already working.

          From looking at the code you have provided, if these are not 0, this means a previous order was submitted and has not been filled yet.

          After the entry order fills the orderId is set to an empty string (which has no length). This allows for a new entry to be placed.

          Even when you are connected to the market replay, the script will still process historical data before processing real time data. This is the same on a live connection. Historical data is always processed first. Since Atm Strategies do not work historically, this is why it is important that the code is only run when Historical is false.

          If this is run historically and the orderId is generated but the order isn't placed, the order will not fill because it wasn't placed. The orderId won't be an empty string, and no new orders can be placed.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            oh thank you! i now understand the purpose of the historical data check.... i don't believe it's in my script but i'll fix now.

            Comment


              #7
              so now that the ATM is working inside the strategy... i can't figure out how to get it to stop adding positions on each new bar. i don't want it to add any more positions until the current positions are closed.

              i've tried using if (Position.MarketPosition == MarketPosition.Flat)
              i've tried using if (GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Flat)
              i've tried using if (GetAtmStrategyMarketPosition(ES2ctr) == MarketPosition.Flat)

              the output window however, keeps reporting that the ATM Position is flat even after it's just filled and reported that it's filled.

              Comment


                #8
                Hello rsmtrade,

                Where the entry is being placed this is currently checking that orderId.Length is 0.

                If orderId.Length is set to an empty string (with a length of 0) when the order is filled, then a new order can go in.

                You will need to change the logic so that this no longer happens.

                Perhaps you could set the orderId variable to an empty string only if the stop loss or profit target fills or the entry order is cancelled.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  i copied the Ninjatrader code directly from the ATMstrategy example because i'm such a newbie.

                  that output file is telling me this....

                  **NT** GetAtmStrategyMarketPosition() method error: Missing atmStrategyId parameter

                  does this help?

                  Comment


                    #10
                    Hello rsmtrade,

                    That error would occur if the atmStrategyId in 'GetAtmStrategyMarketPosition(atmStrategyId)' was null or an empty string.

                    The SampleAtmStrategy that is included with NinjaTrader prevents this error by checking the length of the string first.
                    Code:
                    else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
                    Have you tested using the SampleAtmStrategy that is included with NinjaTrader?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      thank you... i started over with the Sample ATM and added my conditions... now it works as I want.
                      thanks again.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by algospoke, 04-17-2024, 06:40 PM
                      6 responses
                      48 views
                      0 likes
                      Last Post algospoke  
                      Started by arvidvanstaey, Today, 02:19 PM
                      4 responses
                      11 views
                      0 likes
                      Last Post arvidvanstaey  
                      Started by samish18, 04-17-2024, 08:57 AM
                      16 responses
                      61 views
                      0 likes
                      Last Post samish18  
                      Started by jordanq2, Today, 03:10 PM
                      2 responses
                      9 views
                      0 likes
                      Last Post jordanq2  
                      Started by traderqz, Today, 12:06 AM
                      10 responses
                      19 views
                      0 likes
                      Last Post traderqz  
                      Working...
                      X