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

ExitLongStop() getting cancelled

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

    ExitLongStop() getting cancelled

    I have a simple startegy where I am submitting a ExitLongStop() as soon as a buy order gets filled. But this order comes back as cancelled right away. (In backtesting)

    //******* RELEVANT CODE
    protected override void OnOrderUpdate(IOrder order)
    {
    Log(
    "DTMT2: " + Time[0].ToString() + order.ToString(), NinjaTrader.Cbi.LogLevel.Error);
    if (order.Action == Action.Buy && order.OrderState == OrderState.Filled)
    {
    buyprice=order.AvgFillPrice;
    sellprice=buyprice*sellstop;

    exitOrder = ExitLongStop(sellprice,
    "Initial Stop", "EDC Purchase");
    }
    }
    //******************************

    THis is what shows up in logs for ExitLongStop() orders -
    9/10/2009 7:39:00 AMOrder='NT-00010/Back101' Name='Initial Stop' State=Cancelled Instrument='EDC' Action=Sell Limit price=0 Stop price=119.3801 Quantity=0 Strategy='EDC' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='257cd921dce241f791ddb255a3c47c26' Gtd='12/1/2099 12:00:00 AM'
    9/10/2009 7:39:00 AMOrder='NT-00010/Back101' Name='Initial Stop' State=PendingCancel Instrument='EDC' Action=Sell Limit price=0 Stop price=119.3801 Quantity=0 Strategy='EDC' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='257cd921dce241f791ddb255a3c47c26' Gtd='12/1/2099 12:00:00 AM'
    9/10/2009 7:38:00 AMOrder='NT-00010/Back101' Name='Initial Stop' State=Working Instrument='EDC' Action=Sell Limit price=0 Stop price=119.3801 Quantity=0 Strategy='EDC' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='257cd921dce241f791ddb255a3c47c26' Gtd='12/1/2099 12:00:00 AM'
    9/10/2009 7:38:00 AMOrder='NT-00010/Back101' Name='Initial Stop' State=Accepted Instrument='EDC' Action=Sell Limit price=0 Stop price=119.3801 Quantity=0 Strategy='EDC' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='257cd921dce241f791ddb255a3c47c26' Gtd='12/1/2099 12:00:00 AM'
    9/10/2009 7:38:00 AMOrder='NT-00010/Back101' Name='Initial Stop' State=PendingSubmit Instrument='EDC' Action=Sell Limit price=0 Stop price=119.3801 Quantity=0 Strategy='EDC' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='257cd921dce241f791ddb255a3c47c26' Gtd='12/1/2099 12:00:00 AM'

    #2
    cheeky123, please make sure TraceOrders = true is enabled in the Initialize() of your strategy, then follow the output window for more detailed debug info regarding your order behavior - http://www.ninjatrader-support2.com/...ead.php?t=3627
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi,

      I turned the trace ON, and this is what shows up in the output window.
      (its cancelling the exitstop order immediately.

      9/10/2009 6:38:00 AM Entered internal PlaceOrder() method at 9/10/2009 6:38:00 AM: Action=Buy OrderType=Market Quantity=7,398 LimitPrice=0 StopPrice=0 SignalName='EDZ Purchase' FromEntrySignal=''


      9/10/2009 6:38:00 AM Entered internal PlaceOrder() method at 9/10/2009 6:38:00 AM: Action=Sell OrderType=Stop Quantity=7,398 LimitPrice=0 StopPrice=7.78 SignalName='EDZ Sell' FromEntrySignal='EDZ Purchase'


      9/10/2009 6:39:00 AM Cancelled expired order: BarsInProgress=1: Order='NT-00001/Back101' Name='EDZ Sell' State=Working Instrument='EDZ' Action=Sell Limit price=0 Stop price=7.776 Quantity=7,398 Strategy='SetStops' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='98866ec6c0e44f32a349f668836589f3' Gtd='12/1/2099 12:00:00 AM'


      I have tried all the options without any luck. I will really appreciate any help you can provide.

      Also please let me know if it is possible to back test against "tick by tick" data instead of "minute by minute".

      thanks.

      Comment


        #4
        cheeky123, thanks for the reply - your order just expires which is default behavior at the end of each bar if not resubmitted or set to liveUntilCancelled in the overload - http://www.ninjatrader-support.com/H...tLongStop.html

        To backtest with intrabar resolution, please check into this sample here - http://www.ninjatrader-support2.com/...ead.php?t=6652
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Hi,

          I looked at the example. Example does not go for tick by tick. Both bar series in example are minute based.
          Any way this is what I have in my code -

          (Inside Initilaize)
          Add(PeriodType.Tick, 1); //For default instrument - FAS.
          Add(
          "FAZ", PeriodType.Tick, 1);

          protected override void OnBarUpdate()
          {

          if(BarsInProgress == 0) // Condition set 1 for FAS
          { }
          else if(BarsInProgress == 1) // Condition set 2 for FAZ.

          Now when i try to backtest it with FAS instrument, (selecting "tick - 1 as the value for dataseries) I do not get any output. Nothing is posted to the logs. Trace shows some entries regarding connecting to TD Ameritrade (my data provider), thats it. Also if I change the code and replace "tick" with "minute", it works fine. Please help!

          Comment


            #6
            cheeky123, bars object 0 is the primary one you start this strategy from i.e. your 1 minute chart.

            For the added two tickstreams this would then mean the correct objects to reference are 1 and 2 in your BarsInProgress call.

            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bourasrafik, Today, 03:26 PM
            0 responses
            1 view
            0 likes
            Last Post bourasrafik  
            Started by benmarkal, Yesterday, 08:44 AM
            1 response
            30 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by somethingcomplex, Yesterday, 10:36 PM
            1 response
            24 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by rayyyu12, Today, 12:47 AM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by guyonabuffalo, Yesterday, 10:01 PM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X