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

Repeated "Cancel all orders account=XXXXXX" messages in log

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

    Repeated "Cancel all orders account=XXXXXX" messages in log

    Hi NT8 fam,

    I have an automated strategy that is running on 3 accounts, that are linked with a trade copier. This morning after coming back to my desk and seeing how to system performed I noticed these messages in the Control Center logs (screenshot attached below). It seems like the Strategy is trying to cancel all orders repeatedly on the main account, and I'm trying to dig into why this might be happening.

    For one, I override OnAccountItemUpdate() in my strategy code to check the realized/unrealized PnL and exit all positions and cancel pending orders if certain criteria are met. Imagine that code looks something like this

    protected override void OnAccountItemUpdate(Account account, AccountItem accountItem, double value)

    Code:
    [B]{
    
    double totalPNL = Account.Get(AccountItem.RealizedProfitLoss, Currency.UsDollar) + Account.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar);
    
    if((totalPNL < -550 * IQ - 40 || totalPNL > 1700 * IQ + 40 || ToTime(DateTime.Now) > ToTime(endTime) - 60) && PositionAccount.MarketPosition != MarketPosition.Flat)
    
    {
    
    ExitLong();
    
    ExitShort();
    
    Account.CancelAllOrders(Bars.Instrument);
    
    trades = 1;
    
    entries = EntriesPerDirection;
    
    }
    
    }
    ​[/B]
    These are really just emergency failsafe conditions that should execute if the profit target logic in other parts of the strategy failed to execute properly. My questions are:

    1) Could this be the cause of these repeated logs? Is OnAccountItemUpdate called so frequently such that it would cause these log prints multiple times per millisecond?

    2) Is this harmful in any way? I'd obviously want to remove the code that is causing this behavior, but want to make sure nothing is being communicated to my broker that could cause issues.
    Attached Files
    Last edited by jaybedreamin; 03-23-2023, 10:01 AM.
    jaybedreamin
    NinjaTrader Ecosystem Vendor - Zion Trading Algos

    #2
    Hello jaybedreamin,

    Are you using prints to debug the script and understand the behavior?
    https://ninjatrader.com/support/foru...121#post791121

    Are you asking why the condition is evaluating as true multiple times?

    Could this be the cause of these repeated logs?
    Possibly, it could be anything running in NinjaTrader.
    Its necessary to debug to confirm where an issue is coming from, and why it is occurring.
    For example, if you comment the code out does the behavior stop? If you uncomment that code does the behavior return? (This would confirm that this the code cause the behavior)
    To know why, print the time and all values in the conditions or used for calculations to the output window.

    Is this harmful in any way? I'd obviously want to remove the code that is causing this behavior, but want to make sure nothing is being communicated to my broker that could cause issues.
    Harmful in that this would cancel an order that is protecting an open position?
    Harmful in that this would close a position you did not intend to close?
    Harmful in that trying to manage a position through an account will not reflect in the strategy?

    It would be hard to say. This would be specific to the position you want the strategy to have and the account to have, and what orders you want to be working.

    Regarding spamming a broker server with invalid requests, this drives up traffic and is not a good idea.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Jonafare, 12-06-2012, 03:48 PM
    5 responses
    3,986 views
    0 likes
    Last Post rene69851  
    Started by Fitspressorest, Today, 01:38 PM
    0 responses
    2 views
    0 likes
    Last Post Fitspressorest  
    Started by Jonker, Today, 01:19 PM
    0 responses
    2 views
    0 likes
    Last Post Jonker
    by Jonker
     
    Started by futtrader, Today, 01:16 PM
    0 responses
    9 views
    0 likes
    Last Post futtrader  
    Started by Segwin, 05-07-2018, 02:15 PM
    14 responses
    1,792 views
    0 likes
    Last Post aligator  
    Working...
    X