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

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.
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        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.
            Chris L.NinjaTrader Customer Service

            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.
              Chris L.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by jaybedreamin, Today, 05:56 PM
              0 responses
              3 views
              0 likes
              Last Post jaybedreamin  
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              18 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              9 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Working...
              X