Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Flatten - not workin

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

    Flatten - not workin

    Hello,

    I tried to add logic to my strategy - flatten my position on specific chart.

    I used Account.Flatten(instrumentsToClose); - I thought position will be flattened but it did not happen. What am I doing wrong?

    and in StateDatLoaded I called

    // instantiate a list of instruments
    instrumentsToClose = new Collection<Instrument>();

    // add instruments to the collection
    instrumentsToClose.Add(Instrument.GetInstrument(Ac count.Name));

    ​to initiate instrumentsToClose

    What am I missing?

    Thanks for advices

    Paul

    #2
    Hello Paul,

    Thank you for your post.

    The Instrument.GetInstrument() method requires that you pass in an instrument name, though it appears you are passing in Account.Name. For more information on the use of this method:


    In the example on the Flatten page of the help guide, the instruments "MSFT" and "AAPL" are added to the instrumentsToClose collection:
    Code:
    // Please note that your 'Using declarations' section needs to have
    //
    // using System.Collections.ObjectModel;
    //
    // added in order for this example to compile correctly
    
     
    
    // instantiate a list of instruments
    Collection<Cbi.Instrument> instrumentsToClose = new Collection<Instrument>();        
     
    // add instruments to the collection
    instrumentsToClose.Add(Instrument.GetInstrument("AAPL"));        
    instrumentsToClose.Add(Instrument.GetInstrument("MSFT"));
     
    // pass the instrument collection to the Flatten() method to be flattened
    Account.Flatten(instrumentsToClose);
    ​
    I suspect this is the underlying issue; you could try printing the Count of your instrumentsToClose collection prior to calling Account.Flatten to see if it contains any elements to confirm this. For example:
    Code:
    Print("There are " + instrumentsToClose.Count + " instruments to be closed.");
    Account.Flatten(instrumentsToClose);
    Please let us know if we may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    42 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    29 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    46 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Working...
    X