Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancel Short and Long Limit Order at the same time

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

    Cancel Short and Long Limit Order at the same time

    Hello

    I try to get a strategy running with exit short and at the same time setting a new long Limit + Stop . But Managed Order Handling refuse this with a error message. ( An Enter() method to submit an entry order at... has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.)
    ...
    CancelOrder (short);
    CancelOrder (shortstop);
    if (marketPosition == MarketPosition.short) ExitShort();
    longorder = EnterLongLimit(0,true,1, ( BarTief + 1),OrderName );
    ....

    so i try UnManaged like this :
    ...
    // exit short
    if (ordershort != null)
    {
    CancelOrder(ordershort);

    CancelOrder(ordershortstop);

    }
    if(Position.MarketPosition == MarketPosition.Short)
    {
    shortexit = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, 1, 0, 0,
    "", "shortexit");
    CancelOrder(ordershortstop);
    }
    //longlimit + stop
    orderlong = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, 1, limit1, 0, "", "long");
    orderstop = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, 1,0, stoplimit1, "", "stop");


    This works better. But i get a message "... refuse the order ...Margin...."
    I guess submit the new buy limit order is faster then cancel the old short position / orders.
    How can i cancel the short orders and submit a new long order without waiting a full bar and don`t use Margin for the old and the new order...?

    #2
    Hello jr123, and thank you for your question. While using the unmanaged approach does prevent Ninja from running its own rules checks on your strategies, NinjaTrader's rules checks are not the only ones that are in play. The trade desk will have their own rules as well, and if you are using a simulated connection, your simulated trade desk will have rules independent of your strategy. One of these rules is that your account must have enough margin to place a trade. If you are simulated trading, you can increase the amount of money you have in your Sim101 account by visiting the accounts tab of the control center, right-clicking your Sim101 account, and selecting Edit Account. Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Thank You, but of course on a Sim101 account the margin is not a problem, i will go live and the message is from the live account...
      How can i submit the new long order in the moment when the old Short order is canceled without waiting for the next bar ?
      What is better for this ? Unmanaged or is managed possible ?

      I have try something like this, but it seems it do not transmit any order...

      PHP Code:
      protected override void OnOrderUpdate(Order orderdouble limitPricedouble stopPriceint quantityint filleddouble averageFillPriceOrderState orderStateDateTime timeErrorCode errorstring nativeError)
        {
         if (
      order.Name == "long" && orderState == OrderState.Cancelled)
            
      orderlong null;  
         
         if (
      order.Name == "short" && orderState == OrderState.Cancelled)
          
      ordershort null

             if  (
      goshort == && orderlong null)
             {
                   
             
      goshort 0;      
             
      ordershort SubmitOrderUnmanaged(0OrderAction.SellOrderType.Limit1limit10"""short");
             }
             
             
             if  (
      golong == &&  ordershort null)
             {
             
      golong 0;      
             
      orderlong SubmitOrderUnmanaged(0OrderAction.BuyOrderType.Limit1limit10"""long");

             }
        } 
      Last edited by jr123; 04-26-2017, 12:04 PM.

      Comment


        #4
        I am glad we were able to clarify the reason for your message regarding margins. For live trading you will need to ensure your account is funded beyond the needs of your strategy.

        With regard to your strategy performing the way you would like, while fully debugging and developing user strategies is beyond the scope of the support we may provide, It will be easier to answer questions about strategies not producing expected results if we could answer as many of the following questions as possible. Could you take a few minutes to review these questions? I am happy to explain further any of the below questions and the rationale behind asking them.


        * Do you see expected results when running the same test environment on the SampleMaCrossOver strategy in NinjaTrader with a 3 and 14 period?
        * By expected results, I mean that the SampleMACrossover places trades whenever a 3 and 14 period SMA cross
        * Who are you connected to? This is displayed in green on lower left corner of the Control Center window.
        * Are you connected to your data feed provider when running this test?
        * What instrument(s) (and expiry if applicable) have you selected?
        * What Data Series Type have you selected? Example: Tick, Minute, Day
        * What From and To date is selected?
        * Is your strategy a multi instrument or multi time frame strategy?
        * Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          * Do you see expected results when running the same test environment on the SampleMaCrossOver strategy in NinjaTrader with a 3 and 14 period?

          give the short or long signal logic is not the problem

          * By expected results, I mean that the SampleMACrossover places trades whenever a 3 and 14 period SMA cross

          yes this works

          * Who are you connected to? This is displayed in green on lower left corner of the Control Center window.

          Dorrman and IB

          * Are you connected to your data feed provider when running this test?

          yes

          * What instrument(s) (and expiry if applicable) have you selected?

          YM 0617

          * What Data Series Type have you selected? Example: Tick, Minute, Day

          1min

          * What From and To date is selected?

          1 day

          * Is your strategy a multi instrument or multi time frame strategy?

          no only one instrument
          * Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?

          i have described the errors with managed Orders and the margin error, with the last test (sending the order together with OnOrderUpdate ...) there are just no order visible in Orders or chart

          Comment


            #6
            Now after Reset DB... The last script seems working ... the old order is cancelt and the new order transmitted after this and it seems to work on the live account...
            Did you see any problems with this "sending new order with order update" or is this the solution for the double margin problem ?

            PHP Code:
            protected override void OnOrderUpdate(Order orderdouble limitPricedouble stopPriceint quantityint filleddouble averageFillPriceOrderState orderStateDateTime timeErrorCode errorstring nativeError)
              {
               if (
            order.Name == "long" && orderState == OrderState.Cancelled)
                  
            orderlong null;  
               
               if (
            order.Name == "short" && orderState == OrderState.Cancelled)
                
            ordershort null
               

               
                   if  (
            shortgehen == && orderlong == null)
                   {
                     
                   
            shortgehen 0;      
                   
            ordershort SubmitOrderUnmanaged(0OrderAction.SellOrderType.Limit5limit10"""short");
                   Print ( 
            ordershort);
                    
                   }
                   
                   
                   if  (
            longgehen == && ordershort == null)
                   {
                      
                   
            longgehen 0;      
                   
            orderlong SubmitOrderUnmanaged(0OrderAction.BuyOrderType.Limit5limit10"""long");
                   Print ( 
            orderlong);
                    
                   }
              } 

            Comment


              #7
              I am glad a database reset resolved your query. Without the old database, we do not have all the information we would need to determine exactly why your script was not working in accord with expectations previously. If any other questions come up we can answer please do not hesitate to ask.
              Jessica P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by condorhero, Today, 09:28 PM
              0 responses
              5 views
              0 likes
              Last Post condorhero  
              Started by MaraAnkh, Today, 08:44 PM
              0 responses
              6 views
              0 likes
              Last Post MaraAnkh  
              Started by wooofad, Today, 05:38 PM
              0 responses
              7 views
              0 likes
              Last Post wooofad
              by wooofad
               
              Started by caacapital, Today, 10:10 AM
              2 responses
              18 views
              0 likes
              Last Post caacapital  
              Started by DiverG20, Today, 10:23 AM
              0 responses
              23 views
              0 likes
              Last Post DiverG20  
              Working...
              X