Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATM stop

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

    ATM stop

    Hello,
    If I understand correctly it's not possible to use OnExecution() method within ATM strategy. Is there any way to change stop loss immediately after entry order execution?

    #2
    Hello Leeroy_Jenkins, thanks for writing in.

    You will need to run the script OnEachTick to get the update as soon as possible. Call GetAtmStrategyEntryOrderStatus() on each tick (if the ATM has been submitted) to check for the entry order fill. Once that reaches the filled state you can change the stop price with AtmStrategyChangeStopTarget(). This is not as quick as OnExecutionUpdate, but it is the closest you can get using at ATM strategy.

    Please let me know if I can assist any further.

    Comment


      #3
      I'm trying to implement @SampleAtmStrategy in my code and sometimes get 'AtmStrategyChangeStopTarget' method error: Order name 'Stop1' is invalid error. Entry order is filled but looks like stop haven't placed yet. So my code looks like this:

      Code:
      protected override void OnBarUpdate()
      {
      
      if (atmStrategyId.Length > 0)
      ChangeStop();
      
      }
      
      private void ChangeStop()
      {
      
      if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat && !StopPlaced)
      {
      
      try
      {
      // You can change the stop price
      if (GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Long)
      {
      AtmStrategyChangeStopTarget(0, StopPriceLong, "Stop1", atmStrategyId);
      StopPlaced = true;
      }
      
      if (GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Short)
      {
      AtmStrategyChangeStopTarget(0, StopPriceShort, "Stop1", atmStrategyId);
      StopPlaced = true;
      }
      
      }
      
      catch (Exception e)
      {
      if (State >= State.Terminated)
      
      return;
      Log("SampleTryCatch Error: Please check your code for errors.", NinjaTrader.Cbi.LogLevel.Warning);
      Print(Time[0] + " " + e.ToString());
      }
      
      }
      
      }
      Sometimes it works w/o error.

      I tried to check it this way and error still exists:
      Code:
      //on bar update
      string[] status = GetAtmStrategyEntryOrderStatus(orderId);
      if(status[2] == "Filled") ChangeStop();

      Comment


        #4
        Hello, thanks for the follow up.

        The problem could be the stop or target orders are not filled yet. Please check stop and target for State.Filled before trying to change the order:



        I look forward to hearing of you results.

        Comment


          #5
          You mean State.Accepted cuz I'm trying to change stop order which doesn't exist yet.

          I'm checking if it's Accepted by using GetAtmStrategyStopTargetOrderStatus but still get this error Order name 'Stop1' is invalid.
          There is some delay between filled entry order and ATM places stop loss order. So how can I check Stop1 if it's doesn't exist?

          Comment


            #6
            Hello Leeroy_Jenkins, thanks for your reply.

            I apologize for the oversight, I did mean either the Working or Accepted state. Do you have a reduced example you can post or send to me? I will be happy to take a look at the original code. If you do not want to post it here, please send it to platformsupport at ninjatrader.com and reference "Attn ChrisL 2780455" in the body of the email.

            https://ninjatrader.com/support/help...tAsSourceFiles - Export Script.

            I look forward to hearing from you.

            Comment


              #7
              Hello Leeroy_Jenkins, thanks for your reply.

              I was able to get it to work by changing "STOP1" To "Stop1". Please test this out and let me know how it goes.

              I look forward to hearing from you.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Mindset, 04-21-2026, 06:46 AM
              0 responses
              90 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by M4ndoo, 04-20-2026, 05:21 PM
              0 responses
              137 views
              0 likes
              Last Post M4ndoo
              by M4ndoo
               
              Started by M4ndoo, 04-19-2026, 05:54 PM
              0 responses
              68 views
              0 likes
              Last Post M4ndoo
              by M4ndoo
               
              Started by cmoran13, 04-16-2026, 01:02 PM
              0 responses
              120 views
              0 likes
              Last Post cmoran13  
              Started by PaulMohn, 04-10-2026, 11:11 AM
              0 responses
              71 views
              0 likes
              Last Post PaulMohn  
              Working...
              X