Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AtmStrategy order entry problems

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

    AtmStrategy order entry problems

    My Strategy executes correctly and as expected in Playback. After spending two days attempting to run on Sim the results are not as expected. The following occurs:
    The atmStrategyCreate executes and the call back function block matches the AtmStrategyID and their are no Errors.
    So isAtmStrategyCreated is set true. The code for this identical to the sample code supplied.
    The AtmStrategy template gets applied to the chart. This all happens on the close of a bar ( i.e. Is first tick of bar)

    And Here is where it takes a left turn. On the next tick ( i.e. Not first tick) a portion of my code reads the market position.
    if (GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)

    and it reports back that it is "FLAT". My code then clears variables etc which disables all of the features that need to be accessed while the Atmstrategy is on the chart on running.

    This seems like some kind of synchronization problem. What is going on as clearly it is not flat.

    I assumed since my AtmStrategy submits a Market order, It was filled immediately and since I am waiting for the next onbarupdate (next tick). I again assumed I was good to go. I am going to insert a while loop checking if flat with a counter after the isAtmstrategycreated. But that seems an unseemly way to solve this if it does.


    Thanks for any help and direction you can give.

    Jerry



    Last edited by JerryWar; 01-28-2025, 08:33 PM.

    #2
    Hello JerryWar,

    Thank you for your post.

    Are you testing using historical or Market Replay data in Playback?

    What Calculate setting are you using?

    Please provide output as well to illustrate what is going on. You can use GetAtmStrategyEntryOrderStatus(), GetAtmStrategyStopTargetOrderStatus(), and GetAtmStrategyMarketPosition() to get the status of the position and the orders.

    Comment


      #3
      Hi Gaby,
      Thanks for your response.. As I now interpret it, and please correct me if I am wrong. The callback function block is totally asynchronous to the rest of the inline code which continues to execute. So for example the bool in your code example for AtmStrategyCreate() , "isAtmStrategyCreated" in Sim Mode, will not get set immediately, However in Playback mode it effectively does which explains why my code worked fine in Playback but sputtered in Sim. I am now checking for "isAtmStrategyCreated" on the next tick(next OnbarUpdate) and everything seems to be fine.

      Is this accurate ?

      thanks
      Jerry

      I am still having issue accessing. Here is a print. I wait until its long and then move the stop but it errors out the first time. Subsequent access is fine.

      Time of first MarketPosition Long on Tick update = 1/29/2025 11:02:07 AM
      'AtmStrategyChangeStopTarget' method error: Order name 'Stop1' is invalid​

      I don't understand this behaviour
      Last edited by JerryWar; 01-29-2025, 10:06 AM.

      Comment


        #4
        Originally posted by NinjaTrader_Gaby View Post
        Hello JerryWar,

        Thank you for your post.

        Are you testing using historical or Market Replay data in Playback?

        What Calculate setting are you using?

        Please provide output as well to illustrate what is going on. You can use GetAtmStrategyEntryOrderStatus(), GetAtmStrategyStopTargetOrderStatus(), and GetAtmStrategyMarketPosition() to get the status of the position and the orders.
        Market replay , but it doesn't matter as it works in Playback just not in Sim
        CalculateOnEachTick but most calculations are on the FirstTickofBar (close of last bar)

        I tried using GetAtmStrategyStopTargetOrderStatus() before moving Stop1. This fails miserably as it gives an error telling me Stop1 doesn't exist.
        atmStrategy is created
        Marketposition is detected
        But can't change stop without getting error telling me it doesn't exist. And there seems to be NO status I can read tthat
        tells me WHEN I can access it.

        Jerry

        Comment


          #5
          Hello Jerry,

          Likely this has something to do with how you've coded the script. If you take a look at SampleAtmStrategy in the platform, it uses isAtmStrategyCreated to return until it is true so it waits for the ATM to have been successful before doing anything else.

          If you are using GetAtmStrategyMarketPosition (or another method to change or check the order) before that is true to reset variables that would be the problem. You'll need to wait for that bool to be true before you can start working with the ATM.

          The script also has an if/else condition on the ID of the available entry order, if the order hasn't filled it won't start checking for flat yet. Once the entry order fills, it sets the variable back to string.Empty so it can start checking if the Atm is flat to reset variables.

          Additionally, in case you are using a while loop, we would not recommend using that as it can prevent the script from correctly processing incoming data.

          Comment


            #6
            Gaby,
            Thanks, I figured it out. For whatever reason, I had pushed the limit of code before doing a check on if (!isAtmStrategyCreated) return. What happens if you do what I did is, the isAtmStrategycreated can become true before the check BUT not all the elements , orders, Marketposition are fully satisfied and generate errors randomly. Just moving the check right after the CallBack block solved the problem.

            Jerry

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            62 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            134 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            75 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            45 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            50 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X