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

Updating the Stop Order for an ATM Strategy isn't working

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

    Updating the Stop Order for an ATM Strategy isn't working

    My strategy is simple, and works for the most part. The only trouble I'm having is when I want to update the stop order for the ATM strategy.

    My ATM strategy:
    Target 1:
    • Stop Loss: 16 ticks, Profit 16 ticks
    • Stop limit for stop loss enabled
    Auto Trail 1 Step:
    • Stop Loss: 3 ticks
    • Profit Trigger: 4 ticks
    • Frequency: 1 tick


    Code:
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId(); // used for getting the order status
    
    double currentBid = GetCurrentBid(); Print("Current Bid " + currentBid);
    double prevLow = Low[1]; Print("Current Low " + prevLow);
    AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, currentBid, 0, TimeInForce.Day, orderId, "Engulfing", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
       if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
       {
          isAtmStrategyCreated = true;
          inPosition = true;
          Print(Time[0].ToString() + " Entered a long position.");// Stop was set to: " + Low[1].ToString());
          Print("ATMStrategyId " + atmStrategyId);
          if(isAtmStrategyCreated)
          {
             Print("ATM create. Adjusting stop to high.");
             AtmStrategyChangeStopTarget(0, prevLow, "Stop1", atmStrategyId); // will this be limit or market??
          }
       }
    });
    Print("Long should have been created.");
    What I'm wanting is to create the AtmStrategy - which works just fine. However, I want to immediately update the stop to be equal to the previous bar's Low value.
    It isn't doing this. It doesn't update the stop loss.

    The Print() statement just above it executes.

    #2
    Hello brettcomardelle93 , thanks for your post.

    Are there any errors in the log tab of the Control Center when the AtmStrategyChangeStopTarget method is called? Also, use Print() on the Stop price, is this a valid price level for the order?

    I look forward to hearing from you.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      I see two

      An order is submitted and then the Order name is shown to be invalid (because it hasn't been created yet I guess). This doesn't happen all of the time. Every few orders it does.
      8/21/2020 2:54:59 PM Order Order='2409a884cd634f41a7175d21fc4b5932/Sim101' Name='Entry' New state='Submitted' Instrument='GC 12-20' Action='Buy' Limit price=1946.4 Stop price=0 Quantity=1 Type='Limit' Time in force=DAY Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
      8/21/2020 2:54:59 PM Default 'AtmStrategyChangeStopTarget' method error: Order name 'Stop1' is invalid

      I see this one quite often, but I'm unsure if this happens with the ATM autotrail or if it is when the change tries to set it below the previous bar. Like I said before, when I noticed that it does change the stop loss, it doesn't set it to the previous bar's Low. It's likely trying to change, but it sets it incorrectly.
      8/21/2020 3:02:15 PM Order Sim101, Stop price can't be changed above the market. affected Order: Sell 1 StopLimit @ 1944.8 x 1942.8

      Comment


        #4
        For future readers, I found a simple solution to the issue - I don't know why I didn't figure this out quicker... very simple.

        On each OnBarClose(), at the end of the logic, store the OHLC - or whichever values you need from that bar - into a global variable.
        The next OnBarClose() logic will be able to use the OHLC you stored from the previous bar before overwriting the variables for future set up.

        Comment


          #5
          Hello brettcomardelle93, Im glad you were able to find a solution to the issue.

          We do have two methods that let you check the status of the ATM entry order and the stop and target to make sure they are filled before changing/updating the stop or target:

          https://ninjatrader.com/support/help...rderstatus.htm - GetAtmStrategyEntryOrderStatus()
          https://ninjatrader.com/support/help...rgetorders.htm - GetAtmStrategyStopTargetOrderStatus()

          Chris L.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,404 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by Shai Samuel, 07-02-2022, 02:46 PM
          4 responses
          95 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by DJ888, Yesterday, 10:57 PM
          0 responses
          8 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          159 views
          0 likes
          Last Post loganjarosz123  
          Started by Belfortbucks, Yesterday, 09:29 PM
          0 responses
          8 views
          0 likes
          Last Post Belfortbucks  
          Working...
          X