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

How to prevent Rogue Order in ATM Strategies

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

    How to prevent Rogue Order in ATM Strategies

    Ok I installed the latest version 8.0.27.1, I do not know if its this version or not. But my code has not changed. Here is what happens
    I have a ATM strategy with these settings below. When the Order is executed I get a Target and Stop, Every now and then at random when an order is closed because it hits the stop
    I get a reverse order without a stop, which cause me to lose some serious money. You can see I do not have reverse on stop tuned on.

    Because this is random and does replicate at least a few time per day. Here is the question the order place in reverse does carry a ATM ID it is a regular Execution order without a stop.
    I there a way to find through code an order regardless if its ATM or not that does not a Stop order and close immediately that order so the damage is minimized.

    While figure out if it is my code, or whether its a bug in the version, is there are way to close any trade that does not carry a stop1 .I do not use in my code execution orders I use standard out of the sample code ATMcreate and that of course gets over writing with the ATM anyways. I am inclining it code me how the ATM in Chart Trader is re-acting but who knows.

    Summary How to Cancel Close in a Pure ATM script and Rogue non ATM order that has no stop order that was created.

    for now all I have been doing is baby sitting and close them as soon as I see them but with a couple charts open is hard to react fast.

    Thanks


    Click image for larger version

Name:	image.png
Views:	131
Size:	21.3 KB
ID:	1230060Click image for larger version

Name:	image.png
Views:	77
Size:	20.1 KB
ID:	1230061​​

    #2
    Even though it does not matter here is the initial entry of the stadegy cause the ATM in Chart Trader overrules this after wards.

    isAtmStrategyCreated = false; // reset atm strategy created check to false
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();​

    AtmStrategyCreate(OrderAction.Sell, OrderType.Market, 0, 0, TimeInForce.Gtc, orderId, TradeEventer, atmStrategyId, (atmCallbackErrorCode, atmCallBackId)

    => {
    //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
    if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
    isAtmStrategyCreated = true;
    });​

    Comment


      #3
      Hello nettony,

      Thank you for reaching out.

      It is important to understand the information regarding using ATM strategies with NinjaScript that is listed here:


      As that page mentions, "Executions from ATM Strategies will not have an impact on the hosting NinjaScript strategy position and PnL - the NinjaScript strategy hands off the execution aspects to the ATM, thus no monitoring via the regular NinjaScript strategy methods will take place (also applies to strategy performance tracking)." This means that there is no way to monitor the ATM via NinjaScript, so there wouldn't necessarily be a way to detect a filled entry that does not have a stop.

      Something you might be able to do is monitor the PnL from an ATM strategy as shown in this example:


      Then, based on the PnL you could set up a condition once a certain amount of loss is hit to then call AtmStrategyClose()


      Ultimately, you will likely need to use debugging tools to better understand your strategy's behavior and narrow down the cause of the unwanted position that is opening. I recommend enabling Trace Orders to review the order submissions in the NinjaScript Output window as well as Print() statements to break down the variables in your script and the actions being taken. For more information, please see the following links:




      Please let us know if we may be of further assistance.
      Emily C.NinjaTrader Customer Service

      Comment


        #4
        Thanks alot, I will try the PnL,

        I would like to ask if you can please add to the wish list of new features, control of events made by the Chart Trader ATM via Scripting.
        Some of us the make software add-ons that allow customers to use the ATM for the targets and while our add-ons handle other aspects of the event or session.

        The importance of the ATM in chart trader and how you can lose alot of money there should more ways to access what the ATM is doing other than performance and using general Close and Cancel.

        There should be a sort of Tagged event where we can tell difference whether the trade event was created by the Chart Trader ATM as opposed to from script.

        We can react better if we knew when chart trader was doing, more granular.

        Plus adding a wish for some sort of function that gives all orders ID without a STOP1 so we can close them kinda a clean up the unwanted stragglers would be real nice.

        One the most dangerous trades is a Entry without a Stop1. If there was any function that should exist in NinjaTrader, (THIS should be the one )

        A way to close trades that do not have a receptor stop.

        Thanks Hope - Wish to see a function in the future added to Ninja

        Regards

        Tony
        TradeFoxx

        Comment


          #5
          Hello Tony,

          Thank you for your reply.

          I would like to address parts of your inquiry below.

          "There should be a sort of Tagged event where we can tell difference whether the trade event was created by the Chart Trader ATM as opposed to from script."
          • You can determine which orders were created by a strategy by adding print statements to your strategy and/or by reviewing the Trace Orders output. You can also view in the Log tab of the Control Center when an order is placed by Chart Trader with an ATM strategy or if an entry order was submitted via a NinjaScript strategy instance. If you know the order ID, you can review the Log to see if it was submitted manually via Chart Trader or if it was submitted by a NinjaScript strategy.
          "Plus adding a wish for some sort of function that gives all orders ID without a STOP1 so we can close them kinda a clean up the unwanted stragglers would be real nice."
          • This can be determined and resolved using the debugging tools I previously mentioned. If an order submitted without a STOP1 is unexpected behavior, you will need to debug your strategy's behavior in order to identify the cause and implement a resolution to prevent this from happening. There is no function to identify this because the potential causes of this behavior could be numerous.
          The second bullet point ties in to this comment you made in your original post: "Here is the question the order place in reverse does carry a ATM ID it is a regular Execution order without a stop."
          • Since you have an ATM ID for the unexpected reverse orders, I highly recommend adding print statements to your strategy to print additional information about this order and better understand why it is being submitted. The ATM ID can be used in many of the ATM Strategy Methods that provide information about the ATM strategy if it was submitted via NinjaScript:
          Rather than identifying trades that do not have a stop and closing them, the route to take for debugging is to identify why these orders that seem to not have a stop are being placed and prevent them from happening in the first place. The PnL and AtmStrategyClose() was a suggestion that you could use as a backup way to close an ATM strategy position, although ideally you will need to debug your strategy and test it out in simulation until it is exhibiting the desired behavior before you trade it on a live account.

          Thank you for your time and patience. Please don't hesitate to reach out with any additional questions or concerns.
          Emily C.NinjaTrader Customer Service

          Comment


            #6
            Thank for the information Emily, I hear you on debugging to find out why I got the rogue trade, but truth is that a rogue trade can happen for other reasons at any time, partial filled closes, bad exit trade code scripting, bad response sent or received from the broker to name a few reasons.

            Rogue waves are unusually large, unpredictable, and suddenly appearing waves, it is exactly what can happen with a Rogue Trade Event Large Loss and Potential Damage, unpredictable, and Sudden appearing.


            Capturing the issue I used what you suggested Print("Open PnL: " + PositionAccount.GetUnrealizedProfitLoss(PerformanceUnit.currency, Close[0]));
            the I react to negative
            Get
            UnrealizedProfitLoss > 250 do something;


            But “do something” that is not working unless I use flatten

            Account.Flatten(new [] { Instrument.GetInstrument("ES 12-15") });
            this works but then I must continuous babysitting the trade so I can turn on again the strategy.

            I tried these and did not work,
            Exitshort ExitLong did not work.
            AtmStrategyClose("idValue"); does not work because this was used and gave the partial filled rogue trade and does not work the 2nd time.
            CloseStrategy(string signalName) did not work cause I do not know the signalname and cannot be blank can't use CloseStrategy()

            Can you suggest a way of closing a trade the only one that is running without flattening, and without knowing the Orderid.

            And most importantly how to I get the current active orderID
            Thanks

            Comment


              #7
              Hello Tony,

              Thank you for your response.

              Because we don't understand where this order is coming from, it is proving difficult to be able to close it without flattening. Rather than chasing the rogue order and trying to close it, I would like to offer more debugging tips to really narrow down when/why the order is happening so you can better understand your strategy and the actions it is taking. This would also give you the Order ID information. Although ATM strategy executions do not have an impact on the NinjaScript strategy, you could take advantage of the Account class in your strategy's logic in order to get information about all orders placed on your account, whether they are manual, from a NinjaScript strategy, or from an ATM strategy. What I recommend is utilizing the OrderUpdate event handler from the Account class as demonstrated here:


              After subscribing to all order update events for the account, you should print e.Order.ToString() so you are able to watch the orders as they update. In your strategy, you should add prints for every set of conditions so you can see which conditions are evaluating to true and when. Having all of this information in the NinjaScript Output will really help to follow what is happening between your NinjaScript strategy and the ATM strategy every step of the way and narrow down what is causing the unexpected order.

              I appreciate your patience. If you are unsure of the meaning of the output between the order updates and the prints from your conditions, please feel free to share the output and we could take a look at it with you to help identify the next steps.
              Emily C.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by ageeholdings, Today, 07:43 AM
              0 responses
              7 views
              0 likes
              Last Post ageeholdings  
              Started by pibrew, Today, 06:37 AM
              0 responses
              4 views
              0 likes
              Last Post pibrew
              by pibrew
               
              Started by rbeckmann05, Yesterday, 06:48 PM
              1 response
              14 views
              0 likes
              Last Post bltdavid  
              Started by llanqui, Today, 03:53 AM
              0 responses
              6 views
              0 likes
              Last Post llanqui
              by llanqui
               
              Started by burtoninlondon, Today, 12:38 AM
              0 responses
              12 views
              0 likes
              Last Post burtoninlondon  
              Working...
              X