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

Linking specific stop/target orders to respective entries with FXCM

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

    Linking specific stop/target orders to respective entries with FXCM

    I have an account with FXCM and I’m placing orders on that account via a Ninjascript strategy. Anytime my strategy places an order I can see it in FXCM TradeStation and in the NT7 orders window. If the trade triggers I can see the stop/target as an OCO pair as I’m using the SetStopLoss() and SetProfitTarget() methods. That all works fine and as intended but…

    …sometimes I have more than one trade open for the same market/instrument. The trades are always in the same direction i.e. buy/long as hedging must be disabled but that’s not the issue either. The problem is that FXCM does not recognize which stop/target OCO order pair is linked to which entry; it closes trades on a first in/first out basis. I don’t use tiered exits either; I always close out an entire position whenever the stop or target is hit.

    So say for example I go long on a specific instrument (call it ‘Trade A’) and then sometime later I go long again on that same instrument (call it ‘Trade B’) then FXCM will close out Trade A first, even if the stop or target from Trade B has been triggered first. That will leave me with Trade B open and Trade A’s stop and target orders alive. Note the order quantities of Trade A and Trade B are not always the same, so I could be left with part of Trade A still open as well as Trade B, or all of Trade A plus a part of Trade B gets closed.

    I am using unique order names for each trade and I pass that name into the entry, stop and target. I can see in the NT7 order window that the OCO stop/target pair is linked to it’s respective entry as the value in the OCO column will match up with the value in the ID column. Unfortunately there is no way to confirm this in TradeStation; it simply shows an entry order in the opposite direction for the specified price and the same quantity as the entry order.

    Now it doesn’t make a difference in terms of trade outcomes if the stop/target order from ‘Trade A’ is used to close out ‘trade B’ and vice versa, but (aside from messing up my reporting) it causes the strategy to error and disable itself when the stop/target orders from ‘Trade A’ get triggered but only ‘Trade B’ is open. Here’s a copy of the error from the log:

    7/03/2022 10:56:25 PM|0|128|Strategy submitted an order that generated the following error 'UnableToChangeOrder'. Strategy has sent cancel requests, attempted to close the position and terminated itself.

    I realize you cannot see what TradeStation is doing and nor can you do anything about it, but I was hoping someone might be able to shed some light. I wondered if removing the order names from the entry, stop and target or using the Exit() methods instead of Set() methods would at least prevent the strategy from erroring when the second trade closes.

    #2
    Hello newuser,

    The UnableToChangeOrder error comes directly from the broker. It could mean that one of the exit orders (either stop loss or profit target) was being changed already and couldn't be modified or could be for another reason.

    It might be helpful to use exit methods like ExitLongLimit/ExitStopLimit/ExitStopMar****rder/ etc.


    I would recommend contacting your broker and asking specifically why this order could not be modified. The script could further be adapted to handle the brokerage error.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the response. When you say "The script could further be adapted to handle the brokerage error." do you just mean wrapping both the SetStopLoss() and SetProfitTarget() code blocks in a try-catch statement or is there something else?

      I gather the Exit methods are not OCO order types so if I went down that route I would have to write code to cancel whichever order (stop loss or profit target) was still alive when the 'other' triggers?

      Comment


        #4
        Hello newuser,

        I do not suggest wrapping anything in a try and catch.

        The brokerage would let us know the issue, and the script would be modified to handle that issue. For example if the issue was an order change submission was too rapid the script could be coded to send change requests less frequently.

        It is possible to use the RealtimeErrorHandling to ignore the brokerage order messages.


        Exit methods are not OCO, but have local handling to cancel when the entry fills.

        An unmanaged strategy can use OCO.

        Support for the development of custom automated trading strategies using NinjaScript.



        Please note, NinjaTrader 7 is no longer in active development and we are no longer considering new feature requests or changes for NinjaTrader 7. Main development has shifted to our flagship platform NinjaTrader 8. This does mean updates from brokerages, data feeds, or operating systems that require an update in NinjaTrader will not be implemented in NinjaTrader 7 and may cause an interruption in service.

        While there is not a set ETA for the complete discontinuation of NinjaTrader 7, we highly recommend transitioning to NinjaTrader 8 as soon as possible before NinjaTrader 7 reaches its end of life to prevent interruption of service.

        Click below to download NinjaTrader 8.
        NinjaTrader is a futures trading platform that delivers integrated multi-device trading. Discover our best platform to trade futures for active futures traders.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        27 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 02-22-2024, 01:11 AM
        5 responses
        32 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 04-23-2024, 09:53 PM
        2 responses
        49 views
        0 likes
        Last Post wzgy0920  
        Started by Kensonprib, 04-28-2021, 10:11 AM
        5 responses
        193 views
        0 likes
        Last Post Hasadafa  
        Started by GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,235 views
        0 likes
        Last Post xiinteractive  
        Working...
        X