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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    47 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    22 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    15 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    21 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    23 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X