Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATM problem

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

    ATM problem

    Hi -

    I am having an intermittent problem moving stops/targets. I start a trade using AtmStrategyCreate(). Initially the ATM works as expected and creates stops and targets defined in the ATM. I immediately want to move the ATM preset stops/targets to levels from my strategy. I am using the AtmStrategyChangeStopTarget() to do this. I call my function MoveStopAndTargets() from the OnExecutionUpdate() handler. The calls frequently fail with the error message: 'AtmStrategyChangeStopTarget' method error: Order name 'Target1' is invalid. I need to move 4 orders (2 targets, and 2 stops.) If there are errors moving my orders, I call my MoveStopAndTargets() on each tick from the OnBarUpdate() function until all the targets/stops eventually will be moved to the correct place.

    Strategy attached to see the code generating these outputs.

    Here is some output I generate to trace things showing that the ATM started correctly:

    Output from the ATM callback:

    NoError Call Back ID832b00a9633c43378efcd5e842144277 Strat ID: 832b00a9633c43378efcd5e842144277
    STATUS Flat

    ===========================================
    Output form the OnExecutionUpdate() handler:

    Execution Name: Entry OrderName: Entry Market Position: Flat AtmStrategyId: 832b00a9633c43378efcd5e842144277
    ATM Entry:12566.25 StrategyId: 832b00a9633c43378efcd5e842144277

    ================================================== ===================
    Output from the my MoveStopAndTargets() function called first from OnExecutionUpdate() then from OnBarUpdate() until orders have be moved:

    Move Target1:12571.25
    'AtmStrategyChangeStopTarget' method error: Order name 'Target1' is invalid
    ATM Entry:12566.25 StrategyId: 832b00a9633c43378efcd5e842144277
    Move Target1:12571.25
    'AtmStrategyChangeStopTarget' method error: Order name 'Target1' is invalid
    ATM Entry:12566.25 StrategyId: 832b00a9633c43378efcd5e842144277
    Move Target1:12571.25
    'AtmStrategyChangeStopTarget' method error: Order name 'Target1' is invalid
    ATM Entry:12566.25 StrategyId: 832b00a9633c43378efcd5e842144277
    Move Target1:12571.25
    'AtmStrategyChangeStopTarget' method error: Order name 'Target1' is invalid
    ATM Entry:12566.25 StrategyId: 832b00a9633c43378efcd5e842144277
    Move Target1:12571.25
    Move Target2:12576.25
    Move Stop1:12556.25
    Move Stop2:12556.25

    I am not sure why, but frequently, the chart has 'Cancelled pending' orders left on my chart, that can only be removed by resetting the account. If I do not move stops and targets, there is never a 'Cancel pending' order left on the chart. So I assume that moving the orders is causing an error in the ATM.

    Two questions:

    Why is the ATM not updating the Stops/Targets on the first call to the AtmStrategyChangeStopTarget routine from the OnExecutionUpdate()?

    Why are the 'Cancel pending' orders being left on the chart?

    Thank you for your help.

    Attached Files

    #2
    Hello kweiss,

    Thank you for your post.

    So that I may best reproduce the behavior you're seeing, can you provide instruction on whether any strategy settings should be modified from the default, and also supply screenshots of your ATM setup for the ATM template you're using? Looks like it's called HitAndRun 3c 2-1.
    • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
    • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.
    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Find attached requested ATM

      Note: This strategy MUST be run on volumetric bars (I use 5 minute). To run, start strategy, press both Long and Short. Wait for execution.

      Thanks for your help.
      Attached Files

      Comment


        #4
        Hello kweiss,

        Thank you for your reply.

        A few notes here. First, I wasn't able to run this at first because it was hitting issues, specifically because you weren't checking that ChartControl and account are not null before accessing them in various states in OnStateChange. I'd take a look at what I've done here to check that those aren't null as you can hit several of the states they are referenced in in places that don't have access to ChartControl or Account:

        Code:
         else if (State == State.Configure)
        {
        [B]if (ChartControl != null)[/B]
        {
        ChartControl.Dispatcher.InvokeAsync((Action)(() =>
        {
        //ATMName = ChartControl.OwnerChart.ChartTrader.AtmStrategy.Te mplate;
        TradingAccount = ChartControl.OwnerChart.ChartTrader.Account.Name;
        Qty = ChartControl.OwnerChart.ChartTrader.Quantity;
        Print(string.Format("Account: {0} Quantity: {1} Template: {2}", TradingAccount, Qty, ATMName));
        }));
        }
        }
        else if (State == State.Historical)
        {
        [B]if (ChartControl != null)[/B]
        {
        foreach (ChartScale scale in ChartPanel.Scales)
        if (scale.ScaleJustification == ScaleJustification)
        chartScale = scale;
        
        ChartControl.Dispatcher.InvokeAsync((System.Action )(() =>
        {
        LoadBrushesFromSkin();
        // WPF modifications wait until State.Historical to play nice with duplicating tabs
        CreateWPFControls();
        }));
        
        
        originalBackgroundBrush = ChartControl.Properties.ChartBackground;
        
        [B]ChartControl.MouseLeftButtonDown += MouseClicked;
        ChartControl.KeyDown += KeyDown;
        ChartControl.KeyUp += KeyUp;[/B]
        }
        [B]if (account != null)[/B]
        {
        account.AccountItemUpdate += OnAccountItemUpdate;
        account.ExecutionUpdate += OnExecutionUpdate;
        }
        }
        else if (State == State.DataLoaded)
        {
        lock (Account.All)
        account = Account.All.FirstOrDefault(a => a.Name == TradingAccount);
        }
        else if (State == State.Realtime)
        {
        
        }
        else if (State == State.Terminated)
        {
        [B]if (account != null)[/B]
        {
        account.AccountItemUpdate -= OnAccountItemUpdate;
        account.ExecutionUpdate -= OnExecutionUpdate;
        }
        
        [B]if (ChartControl != null)[/B]
        {
        ChartControl.MouseLeftButtonDown -= MouseClicked;
        ChartControl.KeyDown -= KeyDown;
        ChartControl.KeyUp -= KeyUp;
        
        ChartControl.Dispatcher.InvokeAsync((() =>
        {
        DisposeWPFControls();
        }));
        }
        }
        That being said, I'm having good luck with adding this code to the beginning of MoveStopAndTargets:

        Code:
         private void MoveStopAndTargets()
        {
        string[,] target1 = GetAtmStrategyStopTargetOrderStatus("Target1", atmStrategyId);
        if (target1.Length == 0)
        return;
        string[,] target2 = GetAtmStrategyStopTargetOrderStatus("Target2", atmStrategyId);
        if (target2.Length == 0)
        return;
        string[,] stop1 = GetAtmStrategyStopTargetOrderStatus("Stop1", atmStrategyId);
        if (stop1.Length == 0)
        return;
        string[,] stop2 = GetAtmStrategyStopTargetOrderStatus("Stop2", atmStrategyId);
        if (stop2.Length == 0)
        return;
        Basically we're just checking if the stop and target orders have been created yet before we try to change them - so if you add the above, at least in my testing, it took a little while for the targets specifically to be created, which we can see here in the output:

        NoError Call Back ID: 139b1a25535040c4a20ffc19378452ec Strategy ID:139b1a25535040c4a20ffc19378452ec
        STATUS Flat
        Execution Name: Entry OrderName: Entry Market Position: Flat AtmStrategyId: 139b1a25535040c4a20ffc19378452ec
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target2' is invalid
        ATM Entry:4076.25 StrategyId: 139b1a25535040c4a20ffc19378452ec
        Move Target1:4081.25
        Move Target2:4086.25
        Move Stop1:4066.25
        Move Stop2:4066.25
        Execution Name: Stop1 OrderName: Stop1 Market Position: Long AtmStrategyId: 139b1a25535040c4a20ffc19378452ec
        Execution Name: Stop2 OrderName: Stop2 Market Position: Long AtmStrategyId: 139b1a25535040c4a20ffc19378452ec
        Strategy 'HitAndRunTraderV1/261861308' lost order connection but will keep running.
        Strategy 'HitAndRunTraderV1/261861308' lost price connection but will keep running.
        So basically, you'll have to check the status before you try to change the stop and target. I wasn't able to replicate the stuck orders, are you able to replicate those after making the changes I've pointed out?

        Thanks in advance; I look forward to assisting you further.

        Comment


          #5
          Hi Kate -

          Thank you for your help. I have done some quick testing and your suggestion helps. I, too, have not seen the 'Cancel pending' issue yet. Maybe all of the calls setting non-existent orders is causing problems for Ninja order processing.

          Also, than you for your suggestion on how to fix my other problem. I was aware of it, but had not put in the time to figure what was going on. You save me a bit of time

          Thanks again.

          Ken

          Comment


            #6
            Hi Kate -

            Sad news. The 'Cancel pending' issue still persists. It happened during greater volatility. I see that when my first target are hit, intermittently the second target and/or stop go into the 'Cancel pending' state also.

            Also when 'Cancel pending' issue occurs, exiting the trade with a call to AtmStrategyClose() does not always close the trade properly. I get a popup message saying to close the trade manually -- at times the trade is already closed and other times the trade is still open. (See attached for error)



            Do you have any suggestions on how to trace down this problem?

            Thank you for your help.
            Attached Files
            Last edited by kweiss; 06-10-2022, 08:56 AM.

            Comment


              #7
              Hello kweiss,

              Thank you for your reply.

              There's certain scenarios in which this error would not be a bug - the close operation will time out if nothing is received from the broker within 5 seconds, and there's other situations in which this could happen as well.

              That being said, to determine what the issue may be, I'll need to take a look at your log and trace files. Rather than post those here, as they may contain personally identifiable information, please send them in directly through the platform.

              You can do this by going to the Control Center-> Help-> Email Support. Ensuring 'Log and Trace Files' is checked will include these files. This is checked by default.

              Please reference the following ticket number in the body of the email: 3649810 ATTN Kate W. and a link to this post in the body of the email.

              Thanks in advance; I look forward to assisting you further.

              Comment


                #8
                Kweiss
                Did you ever manage to resolve your issue?

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                50 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                126 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                69 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                42 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                46 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X