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

Four day old Error Msg and Covers being placed with 0 price and disabling Strategy

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

    Four day old Error Msg and Covers being placed with 0 price and disabling Strategy

    My strat starts but gets terminated when I place my cover order. The ninja log gives me an error from a test order four days ago. Probably is the issue but no open orders in my console. Any help or suggestions appreciated. Thanx in advance.

    My custom strategy places the entry order as follows:
    EnterBuyLimit(0, true, oi.shares, oi.price, oi.orderID); // oi is an order instruction class price member is double shares member is int
    Places the cover after execution as follows:
    ExitLongStopMarket(0, true, oi.shares, oi.price, oi.orderID, oi.targetOrderID); // oi member targetOrderID is the orderID of entry order

    Ninja Log:

    2020-03-27 10:59:17:796|3|4|Strategy 'DoubleTee/196784471': A Sell stop order placed at '3/23/2020 6:01:02 PM' has been ignored since the stop price is greater than or equal to the close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy.
    2020-03-27 10:59:18:769|1|4|Enabling NinjaScript strategy 'DoubleTee/196784471' : On starting a real-time strategy - StartBehavior=WaitUntilFlat Position=NQ 06-20 1S, NQ 06-20 1S EntryHandling=All entries EntriesPerDirection=2 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
    2020-03-27 10:59:21:241|1|16|NinjaScript strategy 'DoubleTee/196784471' submitting order
    2020-03-27 10:59:21:243|1|32|Order='39e82f70347f481dbfc05b4b5 e9a48bc/Sim101' Name='Limit-5894' New state='Submitted' Instrument='NQ 06-20' Action='Buy' Limit price=7624 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    2020-03-27 10:59:21:343|1|32|Order='39e82f70347f481dbfc05b4b5 e9a48bc/Sim101' Name='Limit-5894' New state='Accepted' Instrument='NQ 06-20' Action='Buy' Limit price=7624 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    2020-03-27 10:59:21:348|1|32|Order='39e82f70347f481dbfc05b4b5 e9a48bc/Sim101' Name='Limit-5894' New state='Working' Instrument='NQ 06-20' Action='Buy' Limit price=7624 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    2020-03-27 10:59:21:349|1|32|Order='39e82f70347f481dbfc05b4b5 e9a48bc/Sim101' Name='Limit-5894' New state='Filled' Instrument='NQ 06-20' Action='Buy' Limit price=7624 Stop price=0 Quantity=1 Type='Limit' Time in force=GTC Oco='' Filled=1 Fill price=7622.75 Error='No error' Native error=''
    2020-03-27 10:59:21:351|1|8|Execution='0b7803edcf014b2ca0c4d6 2b504376aa' Instrument='NQ 06-20' Account='Sim101' Exchange=Default Price=7622.75 Quantity=1 Market position=Long Operation=Operation_Add Order='39e82f70347f481dbfc05b4b5e9a48bc' Time='03/27/2020 10:59:21'
    2020-03-27 10:59:21:355|1|64|Instrument='NQ 06-20' Account='Sim101' Average price=7622.75 Quantity=1 Market position=Long Operation=Operation_Add
    2020-03-27 10:59:58:266|1|32|Order='fd1fe00c407842e08dda0d14b 3f2de99/Sim101' Name='Sell' New state='Submitted' Instrument='NQ 06-20' Action='Sell' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    2020-03-27 10:59:58:274|1|4|Disabling NinjaScript strategy 'DoubleTee/196784471'
    2020-03-27 10:59:58:380|1|32|Order='fd1fe00c407842e08dda0d14b 3f2de99/Sim101' Name='Sell' New state='Accepted' Instrument='NQ 06-20' Action='Sell' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    2020-03-27 10:59:58:383|1|32|Order='fd1fe00c407842e08dda0d14b 3f2de99/Sim101' Name='Sell' New state='Working' Instrument='NQ 06-20' Action='Sell' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    2020-03-27 10:59:58:387|1|32|Order='fd1fe00c407842e08dda0d14b 3f2de99/Sim101' Name='Sell' New state='Filled' Instrument='NQ 06-20' Action='Sell' Limit price=0 Stop price=0 Quantity=1 Type='Market' Time in force=GTC Oco='' Filled=1 Fill price=7613.75 Error='No error' Native error=''
    2020-03-27 10:59:58:389|1|8|Execution='2f63c1d8a77b4e9b899bcd c8ed810ed2' Instrument='NQ 06-20' Account='Sim101' Exchange=Default Price=7613.75 Quantity=1 Market position=Short Operation=Operation_Add Order='fd1fe00c407842e08dda0d14b3f2de99' Time='03/27/2020 10:59:58'
    2020-03-27 10:59:58:391|1|64|Instrument='NQ 06-20' Account='Sim101' Average price=0 Quantity=0 Market position=Flat Operation=Remove

    My Log:

    Enabling NinjaScript strategy 'DoubleTee/196784471' : On starting a real-time strategy - StartBehavior=WaitUntilFlat Position=NQ 06-20 1S, NQ 06-20 1S EntryHandling=All entries EntriesPerDirection=2 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
    3/27/2020 10:59:18 AM: Entering Realtime State DoubleTee(DT) @ 3/27/2020 10:59:18 AM
    3/27/2020 10:59:18 AM: Running in Wait Until Flat mode
    3/27/2020 10:59:18 AM: Canceling all Orders...
    3/27/2020 10:59:18 AM: Exiting Positions...
    3/27/2020 10:59:21 AM: StartPositionEntry: A1, 1, LONG, EWA.Bar
    3/27/2020 10:59:21 AM: New Position Created: DoubleTee_NQ 06-20_Sim101_DT-5893
    3/27/2020 10:59:21 AM: Placing BuyLimit @ 7624.00Target: 7627.50 - LimitOrder::StartEntryLogic()
    3/27/2020 10:59:21 AM: BuyLimit [email protected] - Limit-5894
    3/27/2020 10:59:21 AM: OnOrderUpdate(Limit-5894) Buy/Submitted: Shares: 1@7624
    3/27/2020 10:59:21 AM: OnOrderUpdate(Limit-5894) Buy/Accepted: Shares: 1@7624
    3/27/2020 10:59:21 AM: OnOrderUpdate(Limit-5894) Buy/Working: Shares: 1@7624
    3/27/2020 10:59:21 AM: OnOrderUpdate(Limit-5894) Buy/Filled: Shares: 1@7624
    3/27/2020 10:59:21 AM: Starting TrailingStop(128,64,8,False) - TrailingStop::StartExitLogic()
    3/27/2020 10:59:21 AM: Target: 7655.75 Ratchet: 8 - TrailingStop::StartEntryLogic()
    3/27/2020 10:59:21 AM: Placing SellToCoverStopMarket @ 7607.75 - TrailingStop::StartExitLogic()
    3/27/2020 10:59:21 AM: SellToCoverStopMarket [email protected] - TrailingStop-5895 Limit-5894
    3/27/2020 10:59:21 AM: Terminating DoubleTee(DT) @ 3/27/2020 10:59:58 AM
    3/27/2020 10:59:21 AM: Canceling all Orders...
    3/27/2020 10:59:21 AM: Exiting Positions...
    3/27/2020 10:59:21 AM: Terminated DoubleTee(DT) @ 3/27/2020 10:59:58 AM
    Disabling NinjaScript strategy 'DoubleTee/196784471'



    #2
    Hello MajorIssue,

    Thank you for your post.

    First, the initial error that appears to be coming from several days ago is the strategy telling you it tried to place an order on historical data but was unable to do so as the stop price was greater than or equal to the close price of the current bar.

    The first thing I would recommend would be to turn on the Order Trace function:

    if (State == State.SetDefaults)
    {
    TraceOrders = true;
    }

    Once you then recompile the strategy, you can open a new NinjaScript Output window under New > NinjaScript Output. This will print a log of any orders submitted by the strategy during while it's running, along with any ignored orders. You can then look through and see what may be occurring along with your own prints.

    Here is a link to our help guide that goes into more detail on tracing orders:



    Trace orders alone may not give you the full picture of whether or not a trade should have been entered on a given bar, so I'd also recommend adding some prints to check what the value of oi.price is before submitting the stop market order.

    Also, where within your code are you monitoring for the order fill and then submitting the stop market order?

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Kate replied to the the NinjaTrader noob with the awesome suggestion of the TraceOrders Flag (I learned something new today), now with more (ninja) debug I am a little closer. The lines starting with *** are my comments and not debug messages. I also print the thread ID because this might be a threading issue. As you can see with output buffering and the log times.
      The log reveals: Reason='This was an exit order but no position exists to exit' . But I just got an execution. Do I have to wait before placing a cover order? Should I cover in OnPositionUpdate()?

      My log:

      Enabling NinjaScript strategy 'DoubleTee/196806131' : On starting a real-time strategy - StartBehavior=WaitUntilFlat Position=NQ 06-20 1L, NQ 06-20 1L EntryHandling=All entries EntriesPerDirection=2 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
      *** In the OnStateChange() - if realtime state cancel all historical orders and call ExitLong(); ExitShort();
      3/27/2020 4:14:59 PM-(11): Entering Realtime State DoubleTee(DT) @ 3/27/2020 4:23:41 PM
      3/27/2020 4:14:59 PM-(11): Running in Wait Until Flat mode
      3/27/2020 4:14:59 PM-(11): Canceling all Orders...
      3/27/2020 4:14:59 PM-(11): Exiting Positions...
      3/27/2020 4:23:41 PM Strategy 'DoubleTee/196806131': Entered internal SubmitOrderManaged() method at 3/27/2020 4:23:41 PM: BarsInProgress=1 Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
      3/27/2020 4:14:52 PM-(11): OnOrderUpdate(Sell) Sell/Submitted: Shares: 0@0
      3/27/2020 4:14:52 PM-(11): OnOrderUpdate(DoubleTee_NQ 06-20_Sim101_DT-0011-0025) Sell/Accepted: Shares: 0@0
      3/27/2020 4:14:52 PM-(11): OnOrderUpdate(DoubleTee_NQ 06-20_Sim101_DT-0011-0025) Sell/Working: Shares: 0@0
      3/27/2020 4:23:41 PM Strategy 'DoubleTee/196806131': Entered internal SubmitOrderManaged() method at 3/27/2020 4:23:41 PM: BarsInProgress=1 Action=BuyToCover OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
      3/27/2020 4:23:41 PM Strategy 'DoubleTee/196806131': Ignored SubmitOrderManaged() method at 3/27/2020 4:23:41 PM: BarsInProgress=1 Action=BuyToCover OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'
      3/27/2020 4:14:52 PM-(18): OnOrderUpdate(DoubleTee_NQ 06-20_Sim101_DT-0011-0025) Sell/Filled: Shares: 1@0
      *** This is in the OnBarUpdate() my my signal is true
      3/27/2020 4:30:10 PM-(18): StartPositionEntry: A1, 1, SHORT, EWA.Bar
      3/27/2020 4:30:10 PM-(18): New Position Created: DoubleTee_NQ 06-20_Sim101_DT-0026
      3/27/2020 4:30:10 PM-(18): Placing ShortLimit @ 7557.00Target: 7553.50 - LimitOrder::StartEntryLogic()
      3/27/2020 4:30:10 PM-(18): ShortLimit [email protected] - Limit-0027
      3/27/2020 4:30:10 PM Strategy 'DoubleTee/196806131': Entered internal SubmitOrderManaged() method at 3/27/2020 4:30:10 PM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=7557.00 StopPrice=0 SignalName='Limit-0027' FromEntrySignal=''
      3/27/2020 4:30:10 PM-(18): OnOrderUpdate(Limit-0027) SellShort/Submitted: Shares: 1@7557
      3/27/2020 4:30:10 PM-(56): OnOrderUpdate(Limit-0027) SellShort/Accepted: Shares: 1@7557
      3/27/2020 4:30:10 PM-(56): OnOrderUpdate(Limit-0027) SellShort/Working: Shares: 1@7557
      3/27/2020 4:30:10 PM-(18): OnOrderUpdate(Limit-0027) SellShort/Filled: Shares: 1@7557
      3/27/2020 4:30:10 PM-(18): Starting FollySqueeze(64,64,8,False) - FollySqueeze::StartExitLogic()
      3/27/2020 4:30:10 PM-(18): Target: 7541.25 Ratchet: 8 - FollySqueeze::StartExitLogic()
      3/27/2020 4:30:10 PM-(18): Placing BuyToCoverStopMarket @ 7573.25 - FollySqueeze::StartExitLogic()
      3/27/2020 4:30:10 PM-(18): BuyToCoverStopMarket [email protected] - FollySqueeze-0028 Limit-0027
      3/27/2020 4:30:10 PM Strategy 'DoubleTee/196806131': Entered internal SubmitOrderManaged() method at 3/27/2020 4:30:10 PM: BarsInProgress=0 Action=BuyToCover OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=7573.25 SignalName='FollySqueeze-0028' FromEntrySignal='Limit-0027'
      3/27/2020 4:30:10 PM Strategy 'DoubleTee/196806131': Ignored SubmitOrderManaged() method at 3/27/2020 4:30:10 PM: BarsInProgress=0 Action=BuyToCover OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=7573.25 SignalName='FollySqueeze-0028' FromEntrySignal='Limit-0027' Reason='This was an exit order but no position exists to exit'
      *** This is in the OnStateChange() I recognize terminated state and attempt to cancel all open orders and call ExitLong(); ExitShort();
      3/27/2020 4:30:09 PM-(28): Terminating DoubleTee(DT) @ 3/27/2020 4:32:46 PM
      3/27/2020 4:30:09 PM-(28): Canceling all Orders...
      3/27/2020 4:30:09 PM-(28): Exiting Positions...
      3/27/2020 4:30:09 PM Strategy 'DoubleTee/196806131': Entered internal SubmitOrderManaged() method at 3/27/2020 4:30:09 PM: BarsInProgress=1 Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
      3/27/2020 4:30:09 PM Strategy 'DoubleTee/196806131': Ignored SubmitOrderManaged() method at 3/27/2020 4:30:09 PM: BarsInProgress=1 Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'
      3/27/2020 4:30:09 PM Strategy 'DoubleTee/196806131': Entered internal SubmitOrderManaged() method at 3/27/2020 4:30:09 PM: BarsInProgress=1 Action=BuyToCover OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
      3/27/2020 4:30:09 PM-(28): Terminated DoubleTee(DT) @ 3/27/2020 4:32:46 PM
      Disabling NinjaScript strategy 'DoubleTee/196806131'

      Comment


        #4
        Hello MajorIssue,

        Thank you for your reply.

        Who is your data provider? With certain data providers, Kinetick and Rithmic specifically, the order that OnOrderUpdate, OnExecutionUpdate, and OnPositionUpdate occur isn't guaranteed, so it's possible that you're trying to submit the exit order before the position update has occurred.

        You didn't mention where in your code you're currently submitting the exit order from - are you doing this within OnBarUpdate?

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thanx Kate,

          My data provider is Continuum. In my experience with trading systems, I am betting that your statement is correct in that the position has not yet been recorded in the ledger. I am submitting the cover order in code that is called from inside OnOrderUpdate() function. I will switch that logic to the OnExecutionUpdate() and ultimately try my luck with the OnPositionUpdate(). I will post my results once I am finished. Thank you again.

          Comment


            #6
            I moved the code that responds to Executions into the OnExecutionUpdate() method and my cover orders are being placed as expected. I am writing a custom strategy and using the advanced order handling API. Thanks again Kate.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Brevo, Today, 01:45 AM
            0 responses
            3 views
            0 likes
            Last Post Brevo
            by Brevo
             
            Started by aussugardefender, Today, 01:07 AM
            0 responses
            3 views
            0 likes
            Last Post aussugardefender  
            Started by pvincent, 06-23-2022, 12:53 PM
            14 responses
            239 views
            0 likes
            Last Post Nyman
            by Nyman
             
            Started by TraderG23, 12-08-2023, 07:56 AM
            9 responses
            384 views
            1 like
            Last Post Gavini
            by Gavini
             
            Started by oviejo, Today, 12:28 AM
            0 responses
            6 views
            0 likes
            Last Post oviejo
            by oviejo
             
            Working...
            X