Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cannot apply Indexing with [] to an expression

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

    Cannot apply Indexing with [] to an expression

    Hi all,

    when compiling I get the following error

    Cannot apply Indexing with [] to an expression of type 'method group'

    the code is pasted below

    if (entryOrder == null)
    {
    /* The entryOrder object will take on a unique ID from our SubmitOrder()
    that we can use later for order identification purposes in the OnOrderUpdate() method. */
    Print("I was null at " + Time[0]);
    entryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "Enter Long");
    entryOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Market, 1, Position.Close[0] - 4 * TickSize, 0, "", "Enter Short");

    #2
    Hello,

    This would be related to the use of Position.Close

    Position.Close is a method in which can be called but does not return a value as it shows void in the intellesense popup.

    This method is used to close a position but not return a value of price.

    I believe what you are looking for is the avg fill price which would be this:

    Code:
    SubmitOrder(0, OrderAction.Sell, OrderType.Market, 1, Position.AvgPrice - 4 * TickSize, 0, "", "Enter Short");
    The error you are getting is specifically saying that you can not apply an index [1] to a method ()
    the position close would normally look like this:

    Position.Close();

    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    56 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    143 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    160 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    96 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    276 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X