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 all accounts

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

    flatten all accounts

    private void BarsRequest_Update(object sender, BarsUpdateEventArgs e)
    { if (submissionAccountMaestra.Positions.Count == 0)
    {
    CancelarsiFlat();
    }
    }
    private async Task CancelarsiFlat()
    {
    await Task.Delay(3000);
    salidatipoReplica = "Market";

    Collection<Cbi.Instrument> instrumentsToCancel = new Collection<Instrument>()
    {
    instrumentSelector1.Instrument,
    instrumentSelector2.Instrument,​
    }
    submissionAccount1.Flatten(instrumentsToCancel);
    submissionAccount2.Flatten(instrumentsToCancel);​
    Once the operation of a master account is closed and verify if (submissionAccountMaestra.Positions.Count == 0)
    calls the async process. goes through the process until it reaches submissionAccount1.Flatten(instrumentsToCancel);
    submissionAccount2.Flatten(instrumentsToCancel); but it doesn't run, could we help?

    and in this part: { if (submissionAccountMaestra.Positions.Count == 0) lo intente con
    foreach (var position in submissionAccountMaestra.Positions)
    {
    if (position.MarketPosition == MarketPosition.Flat)
    {CancelarsiFlat();}
    but it does not detect if it is flat so it stops there​​​​

    #2
    Hello franatas,

    Thanks for your post.

    Instead of using "await Task.Delay" we suggest implementing a Timer in the script with TriggerCustomEvent() if you want the script to wait a certain amount of time before an action is triggered.

    See this help guide page for more information about TriggerCustomEvent() and sample code: https://ninjatrader.com/support/help...ustomevent.htm

    I see you are using "async" in your script. As a best practice, you should always make sure to use Dispatcher.InvokeAsync() in a NinjaScript to ensure your action is done asynchronously to any internal NinjaTrader actions. Calling the synchronous Dispatcher.Invoke() method can potentially result in a deadlock scenarios as your script is loaded.

    See this help guide page about Multi-threading Considerations for NinjaScript and sample code: https://ninjatrader.com/support/help...-threading.htm

    Further, if the script is not behaving as expected then debugging prints would need to be added to the script to understand exactly how it is behaving.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Segwin, 05-07-2018, 02:15 PM
    14 responses
    1,788 views
    0 likes
    Last Post aligator  
    Started by Jimmyk, 01-26-2018, 05:19 AM
    6 responses
    837 views
    0 likes
    Last Post emuns
    by emuns
     
    Started by jxs_xrj, 01-12-2020, 09:49 AM
    6 responses
    3,293 views
    1 like
    Last Post jgualdronc  
    Started by Touch-Ups, Today, 10:36 AM
    0 responses
    12 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  
    Working...
    X