Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Emily C.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Jimmyk, 01-26-2018, 05:19 AM
    6 responses
    835 views
    0 likes
    Last Post emuns
    by emuns
     
    Started by jxs_xrj, 01-12-2020, 09:49 AM
    6 responses
    3,291 views
    1 like
    Last Post jgualdronc  
    Started by Touch-Ups, Today, 10:36 AM
    0 responses
    11 views
    0 likes
    Last Post Touch-Ups  
    Started by geddyisodin, 04-25-2024, 05:20 AM
    11 responses
    62 views
    0 likes
    Last Post halgo_boulder  
    Started by Option Whisperer, Today, 09:55 AM
    0 responses
    9 views
    0 likes
    Last Post Option Whisperer  
    Working...
    X