Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy w/ ATM is posting error ChangeStopTarget function

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

    Strategy w/ ATM is posting error ChangeStopTarget function

    The photo I've attached shows the error I'm getting to the output window

    Click image for larger version  Name:	Screenshot (158).png Views:	0 Size:	11.8 KB ID:	1318616

    Logic Line-> AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);​

    The "STOP1" I'm assuming is why it won't work correctly IDK. I deleted the STOP1 and just left ( "" ) so that it doesn't send popups on every tick once an order is taken.
    It does work like this but if theres a proper way to code this logic would be cool. Kind of tougher to read the Prints: with a thousand error messages.


    Also,
    I am trying to setup the "ChangeStopTarget" on a strategy without the ATM so that I can backtest and fix errors;
    This code is from the SampleATMStrategy on NinjaTrader, I'm trying to setup an Order Entry logic to backtest a couple strategies and I was wondering if anyone familiar with coding knows how to set this up. This line of code is so that the StopLoss and ProfitTarget can be moved around after being placed. Ive tried several times and can't get it to function as expected. thanks in advance

    if (atmStrategyId.Length > 0)
    {
    // You can change the stop price**
    if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
    AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);
    }

    A standard NinjaScript strategy doesn't have the (atmStrategyId) string and I did try creating a new string to serve as it but it didn't function correctly.​ I suppose I dont completely understand the backend programming of NinjaScript so that isn't helping me

    #2
    Hello FBraun,

    The error in the output window is specifically because you used "" instead of an order name, you need to use the order name to be able to change the orders. You will also get that if you call that method before the order is active or is in a state where it cannot be changed. I would suggest trying to use the following as the target names, I see this works in a script I have on my end.

    Code:
    AtmStrategyChangeStopTarget(0, Low[0] - 20 * TickSize, "Stop1", atmStrategyId);
    AtmStrategyChangeStopTarget(High[0] + 20 * TickSize,0 , "Target1", atmStrategyId);
    I would also suggest looking at the SampleATMStrategy code to make sure you are using the atmStrategyId variable correctly, that should be populated with the ATM's id which is also required to change the targets. If the wrong id is supplied then it won't be able to find the targets and will produce the message you are seeing. ​

    Comment


      #3
      Thanks Jesse
      This code is directly off of the SampleAtmStrategy

      if (atmStrategyId.Length > 0)
      {
      // You can change the stop price
      if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
      AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);​
      }

      The "STOP1" isnt working and is throwing the error.

      I changed it to-> [orderId] from Line 31 SampleAtmStrategy [private string orderId = string.Empty;]​
      Without the quotes " " and it now shows the order number in the log and on the NinjaScript output but still throws errors.


      Click image for larger version  Name:	Screenshot (160).png Views:	0 Size:	51.3 KB ID:	1318636
      Technically it does work and the stops are adjustable but.. if theres a bug somewhere I'd like to spray it with raid.


      I have applied it to the SampleAtmReversal that is found on the ecosystem by one of the staff. Here is the code I'm using. Let me know what you think.
      Last edited by FBraun; 09-18-2024, 06:08 PM.

      Comment


        #4
        Hello FBraun,

        May we have a screenshot showing STOP1 is also causing an invalid name error?

        The order id and empty string will not work, but I do expect STOP1 to work as long as the entry has filled.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Yes ma'am,
          Here are the pics
          This is with @"STOP1" and there's two Error popups. I also tried without capitalization so just "Stop1" and the popup errors are more numerous.

          Without the "Stop1" the error messages are printed to the output window, albeit many of them, without popups errors. So that would be the orderId or just "" or "Stop5"

          Click image for larger version  Name:	Screenshot (163ref).png Views:	0 Size:	5.5 KB ID:	1318720 Click image for larger version  Name:	Screenshot (163).png Views:	0 Size:	14.7 KB ID:	1318721
          Edit: It seems that the {AtmStrategyChangeStopTarget} must be inside the EnterLong/Short logic if its added to the OnBarUpdate this error happens


          Question 2: How do I add the {AtmStrategyChangeStopTarget} to a strategy without an ATM?? Just a {StrategyChangeStopTarget}
          Last edited by FBraun; 09-19-2024, 02:33 PM.

          Comment


            #6
            Here is the reversal version but the STOP1 still doesn't work right see next post
            Attached Files
            Last edited by FBraun; 09-19-2024, 02:52 PM.

            Comment


              #7
              Unfortunately that one doesn't work right either and produces this on the NS Output without the "STOP1"
              Click image for larger version  Name:	Screenshot (164).png Views:	0 Size:	25.9 KB ID:	1318731
              Last edited by FBraun; 09-19-2024, 02:54 PM.

              Comment


                #8
                Hello FBraun,

                Please try the attached script to see if that works for you. I see this working on my end. To test just apply the script to a 10 second chart, let the entry fill and then watch the targets, they should be updated after the bar closes.

                Attached Files

                Comment


                  #9
                  Thank You Jesse

                  Your version works for limit orders but I was using market order entry so I just changed it up to market. See below.

                  Also see the attached file. The error seems to happen when a limit order is "Placed Above/Below Market Order" and the original is missing brackets after the ->

                  if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
                  { <-
                  AtmStrategyChangeStopTarget
                  } <-

                  Somehow the sandbox didn't pick up on the lack of bracket orders.

                  The revision file code is listed as follows for a market order::

                  AtmStrategyChangeStopTarget(DefaultQuantity, 0, "Stop1", atmStrategyId);

                  Thank You again
                  Frank
                  Attached Files
                  Last edited by FBraun; 09-21-2024, 11:53 AM.

                  Comment


                    #10
                    Hello FBraun,

                    I am not sure I understand what you are saying, a market order cannot be changed. You can only change resting orders like limit, stop limit, stop market type orders.

                    Comment


                      #11
                      Hi Jesse
                      What I'm doing is submitting a market order initially with the ATM Strategy. Instead of a limit order. So it won't let me move the stop around as a limit order without error.
                      I'm using this code without any errors for the Change Stop. And when it gets executed it's listed in the Log file as a market stop order.

                      AtmStrategyChangeStopTarget(DefaultQuantity, 0, "Stop1", atmStrategyId);

                      Issue solved! And thank you for your help, your code does work for orders that are submitted as limit orders btw.​

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      558 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      324 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      101 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      545 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      547 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X