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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X