Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I get this error in when I try to compile my strategy

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

    I get this error in when I try to compile my strategy

    HTML Code:
    The type or namespace name "Positions" does not exist in the namespace "Ninjatrader.NinjaScript"
    I am using this line:

    Code:
    using NinjaTrader.NinjaScript.Positions;​
    When I remove this last line, I get even more errors like this:


    HTML Code:
    Does not contain a definition for "AvgPrice" and no extend method "AvgPrice" accepting a first argument of type.
    Please help me fix this. thank you

    #2
    Hello onlinebusiness,

    Thanks for your post.

    The using statement you shared would not need to be used in the script to access the strategy Position information. Please remove this using statement from the script.

    The "Does not contain a definition for "AvgPrice" and no extend method "AvgPrice" accepting a first argument of type." error message means that there is no definition for AvgPrice so this cannot be used with Position.

    You would need to call Position.AveragePrice to get value of the average price of the strategy position, as seen in the Position help guide page. Please see the Position help guide page linked below for information about the available Position information you could access.

    Position: https://ninjatrader.com/support/help...8/position.htm
    Position.AveragePrice: https://ninjatrader.com/support/help...erageprice.htm

    Let me know if I 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


      #3
      It worked, thanks

      I still get this error:

      The name 'ExitOnClose' Does not exist in the current context

      From this part of the code:

      Code:
       // Check for trades that need to be closed at session end
      
                  if (IsExitOnSessionCloseStrategy && Bars.IsLastBarOfSession)
      
                  {
      
                      if (Position.MarketPosition == MarketPosition.Long || Position.MarketPosition == MarketPosition.Short)
      
                      {
      
                          if (Profit)
      
                              ExitOnClose();
      
                          else
      
                              ExitOnClose("Session Close");
      
                      }
      
                  }
      ​
      What do I need change please

      Comment


        #4
        Hello onlinebusiness,

        Thanks for your note.

        ExitOnClose() is not a documented/supported method in the help guide which is why you see this error.. You must use one of the supported order methods mentioned in the Managed Approach help guide page below to exit or cancel an order.

        See this help guide page for supported Managed Approach order management methods: https://ninjatrader.com/support/help...d_approach.htm

        An Exit method such as ExitLong() or ExitShort() should be used to exit a long or short position. If you would like to cancel a specified order, you could use the CancelOrder() method.

        CancelOrder(): https://ninjatrader.com/support/help...ancelorder.htm
        CancelOrder() reference sample: https://ninjatrader.com/support/help...thod_to_ca.htm

        Please let me know if I may further assist.
        <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

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        51 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        128 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X