• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitStopMarket() Not working as expected

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

    ExitStopMarket() Not working as expected

    Hello:

    I am using ExitLongStopMarket() to move the StopLoss in a trade. I am facing an issue when I move the StopLoss. The original StopLoss order stays put and doesn't cancel. I am modifying the order object. This happens only If I modify the Stop Signal name. If I keep the same Signal name in the order it works fine. I need to use a different signal name to make tracking my orders better. Is there any way to fix the issue.

    When I change the signal name, Is it not modifying the same order object? It appears If I change the Quantity/Price and keep the Signal name and FromEntrySignal the order object is modified but If I change the StopLoss signal name then the original order object stays the same and a new StopLoss order is created.

    See below the log:



    ===========
    Now the interesting thing is If I do not change the name Name but keep it the same and update the StopLoss price.
    Then it is working as expected. The StopLoss is moved correctly
    ===========



    ===========
    Now the interesting thing is If I do not change the name Name but keep it the same and update the StopLoss price.
    Then it is working as expected. The StopLoss is moved correctly
    ===========


    Order='636364144/ACCOUNT' Name='StopShort STB1' New state='Working' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.7013 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636364144/ACCOUNT' Name='StopShort STB1' New state='Accepted' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.7013 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636364144/ACCOUNT' Name='StopShort STB1' New state='Change submitted' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.7013 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636364144/ACCOUNT' Name='StopShort STB1' New state='Working' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.7021 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636364144/ACCOUNT' Name='StopShort STB1' New state='Accepted' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.7021 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636364144/ACCOUNT' Name='StopShort STB1' New state='Change submitted' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.7021 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636364144/ACCOUNT' Name='StopShort STB1' New state='Working' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.70228 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636364144/ACCOUNT' Name='StopShort STB1' New state='Accepted' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.70228 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636364144/ACCOUNT' Name='StopShort STB1' New state='Change submitted' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.70228 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636364144/ACCOUNT' Name='StopShort STB1' New state='Working' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.70259 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636364144/ACCOUNT' Name='StopShort STB1' New state='Accepted' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.70259 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636364144/ACCOUNT' Name='StopShort STB1' New state='Submitted' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.70259 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''

    =====
    I modified the StopLoss to give the trade little bit of breathing room
    Here I changed the StopLoss name to "StopShort STB1"

    Now the effect is , The Original StopLoss as well as the New StopLoss are there in Working State" I am expecting the Original Stop Loss to be replaced with the New StopLoss Order

    ==========

    NinjaScript strategy 'Ninja8STRX/131611074' submitting order
    Order='636340689/ACCOUNT' Name='TargetShort' New state='Working' Instrument='NZDUSD' Action='Buy to cover' Limit price=0.67365 Stop price=0 Quantity=14,000 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636340689/ACCOUNT' Name='TargetShort' New state='Accepted' Instrument='NZDUSD' Action='Buy to cover' Limit price=0.67365 Stop price=0 Quantity=14,000 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636340689/ACCOUNT' Name='TargetShort' New state='Submitted' Instrument='NZDUSD' Action='Buy to cover' Limit price=0.67365 Stop price=0 Quantity=14,000 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636340685/ACCOUNT' Name='StopShort Init' New state='Working' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.70265 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636340685/ACCOUNT' Name='StopShort Init' New state='Accepted' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.70265 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636340685/ACCOUNT' Name='StopShort Init' New state='Submitted' Instrument='NZDUSD' Action='Buy to cover' Limit price=0 Stop price=0.70265 Quantity=14,000 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''

    =====
    My Initial StopLoss Order is called = "StopShort Init"
    ====

    Instrument='NZDUSD' Account='ACCOUNT' Average price=0.69865 Quantity=14,000 Market position=Short Operation=Operation_Add
    NinjaScript strategy 'Ninja8STRX/131611074' submitting order
    Execution='636340684' Instrument='NZDUSD' Account='ACCOUNT' Exchange=Default Price=0.69865 Quantity=14,000 Market position=Short Operation=Operation_Add Order='636340684' Time='6/1/2018 01:30'
    NinjaScript strategy 'Ninja8STRX/131611074' submitting order
    Order='636340684/ACCOUNT' Name='ShortSTRXBig' New state='Filled' Instrument='NZDUSD' Action='Sell short' Limit price=0 Stop price=0 Quantity=14,000 Type='Market' Time in force=GTC Oco='' Filled=14000 Fill price=0.69865 Error='No error' Native error=''
    Order='636340684/ACCOUNT' Name='ShortSTRXBig' New state='Working' Instrument='NZDUSD' Action='Sell short' Limit price=0 Stop price=0 Quantity=14,000 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636340684/ACCOUNT' Name='ShortSTRXBig' New state='Submitted' Instrument='NZDUSD' Action='Sell short' Limit price=0 Stop price=0 Quantity=14,000 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    Order='636340684/ACCOUNT' Name='ShortSTRXBig' New state='Accepted' Instrument='NZDUSD' Action='Sell short' Limit price=0 Stop price=0 Quantity=14,000 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    NinjaScript strategy 'Ninja8STRX/131611074' submitting order
    Enabling NinjaScript strategy 'Ninja8STRX/131611074' : On starting a real-time strategy - StartBehavior=AdoptAccountPosition AccountPosition=NZDUSD 14000L, NZDUSD 14000L EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=False SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes


    =============

    Character limit doesn't allow me to input the code snippet into this message.
    I will add it as the replay to this thread.

    #2
    Code Snippet
    ============


    Here are the relevant code details:

    Entry Order:

    EnterLong(Convert.ToInt32(QuantityBig), @"LongBig");

    StopLoss Order in OnExecutionUpdate:

    protected override void OnExecutionUpdate(......))

    StopOrder = ExitLongStopMarket(0, true, execution.Order.Filled, execution.Order.AverageFillPrice - StopLossInitBig, "StopLong Init", @"LongBig");

    TargetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AverageFillPrice + TakeProfitBig, "TargetLong", @"LongBig");

    Trail Stop and Update Quantity and some time StopLoss Name change in OnBarUpdate():

    protected override void OnBarUpdate()

    if ((Stop Loss Condition))
    {
    StopOrder = ExitLongStopMarket(0, true, StopOrderQuantity, (Close[0] - STB1), "StopLong STB1", @"LongBig");
    StopLongPrice = (Close[0] - STB1);
    }
    else if ((Stop Loss Condition & Profit Condition))
    {
    ExitLong(0, BigTL2, "TakeProfit STB2", @"LongBig");
    TargetOrder = ExitLongLimit(0, true, StopOrderQuantity - BigTL2, TargetLongPrice, "TargetLong", @"LongBig");
    StopOrder = ExitLongStopMarket(0, true, StopOrderQuantity - BigTL2, (Close[0] - STB2), "StopLong STB2", @"LongBig");
    StopLongPrice = (Close[0] - STB2);
    StopOrderQuantity = (StopOrderQuantity - BigTL2);
    }
    else
    {
    StopOrder = ExitLongStopMarket(0, true, StopOrderQuantity, (Close[0] - STB2), "StopLong STB2", @"LongBig");
    StopLongPrice = (Close[0] - STB2);
    }

    As you can see from the above, I change the name inside the StopLoss Order object when the trade passes thru certain targets levels which I want to track. The problem is when I change the StopLoss name in the same order object, it does not seem to take it instead, it is keeping the old and creating a new order and what I end is with two duplicate working orders.

    Can you suggest a method to avoid the issue and keep the same StopLoss order and to avoid the duplications?

    Comment


      #3
      Hello ajsdnyyrr1234DDf,

      Thank you for your post.

      You would either need to avoid using two signal names for essentially the same order or use two Order objects and cancel the one you are switching from.

      Please let me know if you have any questions.
      Patrick H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by supermht, Today, 10:13 PM
      0 responses
      0 views
      0 likes
      Last Post supermht  
      Started by supermht, Today, 07:59 PM
      0 responses
      2 views
      0 likes
      Last Post supermht  
      Started by mohdhm, Today, 05:13 PM
      1 response
      12 views
      0 likes
      Last Post nkhoi
      by nkhoi
       
      Started by 3lliot, Today, 05:55 PM
      0 responses
      2 views
      0 likes
      Last Post 3lliot
      by 3lliot
       
      Started by Fargo, Today, 04:57 PM
      0 responses
      11 views
      0 likes
      Last Post Fargo
      by Fargo
       
      Working...
      X