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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    54 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    72 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X