Announcement

Collapse
No announcement yet.

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
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    633 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    364 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    567 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X