Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Last lines in Strategy not working with Position.MarketPosition

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

    Last lines in Strategy not working with Position.MarketPosition

    I have a strategy that places Long orders using this line of code once conditions are met:

    Code:
    AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, limitPriceLong,0 , TimeInForce.Day, orderId, "ATM1", atmStrategyId);
    No issues, works all day long. My last lines of code under OnBarUpdate are:

    Code:
    if (Position.MarketPosition == MarketPosition.Long)
                        
                        {Print (" You are LONG ");}    
                else if (Close[0]> 1) // for testing only
                {Print (" You should not be seeing this line if you are in a Long Position");}
    Once I am in the LONG Position I expected to see "You are LONG" but I am not. It prints "You should not be seeing this line if you are in a Long Position" after every bar, period. Any idea what I am doing wrong? I thought the example I was following from another post was pretty straight forward...please point me in the correct direction.

    #2
    Originally posted by sarasotavince View Post
    I have a strategy that places Long orders using this line of code once conditions are met:

    Code:
    AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, limitPriceLong,0 , TimeInForce.Day, orderId, "ATM1", atmStrategyId);
    No issues, works all day long. My last lines of code under OnBarUpdate are:

    Code:
    if (Position.MarketPosition == MarketPosition.Long)
                        
                        {Print (" You are LONG ");}    
                else if (Close[0]> 1) // for testing only
                {Print (" You should not be seeing this line if you are in a Long Position");}
    Once I am in the LONG Position I expected to see "You are LONG" but I am not. It prints "You should not be seeing this line if you are in a Long Position" after every bar, period. Any idea what I am doing wrong? I thought the example I was following from another post was pretty straight forward...please point me in the correct direction.
    ATM Strategies cannot be backtested, because they only work in real time. The literature clearly says so.

    ref: http://www.ninjatrader.com/support/h...strategies.htm

    Comment


      #3
      Hello sarasotavince,

      Thanks for your post and question.

      When using ATM's with a strategy, you must use the methods associated with ATMs. In this case use of "GetAtmStrategyMarketPosition" will get the market position while in an ATM.

      Here is a link to that method in the help guide: http://www.ninjatrader.com/support/h...etposition.htm

      Here is the link to the list of all ATM strategy methods available: http://www.ninjatrader.com/support/h...gy_methods.htm

      Finally, koganam's assertion is correct although you didn't state if you were backtesting.

      Please let me know if I can be of further assistance.

      Comment


        #4
        You are correct Paul, I am not back testing. I am trading this strategy LIVE everyday and want to continue to fine tune it, so to speak.

        I will check out the links you have provided. I guess I was mixing apples and oranges as I am definitely using the ATM at this time.

        Comment


          #5
          You are correct Paul, I am not back testing. I am trading this strategy LIVE everyday and want to continue to fine tune it, so to speak.

          I will check out the links you have provided. I guess I was mixing apples and oranges as I am definitely using the ATM at this time.

          Comment


            #6
            Unfortunately I am still moving in circles and would like to request additional assistance. I looked at the examples and could not get anything to work with my present code.

            Here are the relevant variables:

            Code:
             private string      atmStrategyId = string.Empty;
             private string      orderId = string.Empty;
             private string      status;
            Here is how I enter a Long Order:

            Code:
            if ( 
                            orderId.Length == 0  
                            && atmStrategyId.Length == 0
                )
                                    
                                {        
                                
                                        atmStrategyId = GetAtmStrategyUniqueId();
                                        orderId = GetAtmStrategyUniqueId();
                                        AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.Limit, limitPriceLong,0 , TimeInForce.Day, orderId, "ATM1", atmStrategyId);        
                                        barNumberOfOrder = CurrentBar;
                                        orderBar = CurrentBar;
                                    
                                }
            Now I want to use the output window to monitor the trade. I have tried several variations of the code below and always can COMPILE but always get an error once the bar updates. Most common error is: **NT** GetAtmStrategyEntryOrderStatus() method error: orderId 'orderId' does not exist.


            Code:
            string[] entryOrder2 = GetAtmStrategyEntryOrderStatus("orderId");
             
                // Check length to ensure that returned array holds order information
                if (entryOrder2.Length > 0)
                {
                     Print("Average fill price is " + entryOrder2[0].ToString());
                     Print("Filled amount is " + entryOrder2[1].ToString());
                     Print("Current state is " + entryOrder2[2].ToString());
                }
            Why is "orderId" messing me up?

            Comment


              #7
              Hello sarasotavince,

              Thanks for your post.

              As I can't see your entire code it is difficult to say for sure but the error message leads one to wonder if there is anything else in your coding that may have changed or reset the string orderID?

              If you would like I could review your entire code and advise any observations. If you want to do that, please send an e-mail to support at NinjaTrader dot com with your strategy code, atten: Paul and reference ticket #1099250.

              I look forward to your reply

              Comment


                #8
                Paul,

                Thanks again... Upon review, I found a section of code that resets the orderId if an order is filled, rejected, or cancelled (thus setting up for the next order). I feel a little like Dr. Frankenstein because I lift and borrow and modify different pieces of code and I don't always fully understand it at the time or forget it's there...but with helpful folks like yourself I am trying to learning--even if I have a long way to go.

                Comment


                  #9
                  Hello sarasotavince,

                  Good job on debugging! Glad to hear it worked out.

                  Please let us know if we can be of further assistance.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  639 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  366 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  107 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  569 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  572 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X