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 AaronKoRn, Today, 09:49 PM
    0 responses
    11 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Today, 08:42 PM
    0 responses
    10 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Today, 07:51 PM
    0 responses
    11 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,980 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    9 views
    0 likes
    Last Post rbeckmann05  
    Working...
    X