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 rhyminkevin, Today, 04:58 PM
    4 responses
    52 views
    0 likes
    Last Post dp8282
    by dp8282
     
    Started by iceman2018, Today, 05:07 PM
    0 responses
    5 views
    0 likes
    Last Post iceman2018  
    Started by lightsun47, Today, 03:51 PM
    0 responses
    7 views
    0 likes
    Last Post lightsun47  
    Started by 00nevest, Today, 02:27 PM
    1 response
    14 views
    0 likes
    Last Post 00nevest  
    Started by futtrader, 04-21-2024, 01:50 AM
    4 responses
    50 views
    0 likes
    Last Post futtrader  
    Working...
    X