Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Removing Limit order

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

    Removing Limit order

    I'm trying to figure out how I can more accurately remove a placed limit order if the market moves 5 ticks away from it.

    say I wanted to go long at 11:30, so I have something like this.

    if(ToTime(Time[0]) == 113000){
    limPrice = Open[0]+ -1*TickSize;
    myEntryOrder = EnterLongLimit(1, limPrice , "goLONG");

    }

    If I am correct this will place a limit order 1 tick below the current market so that if it falls that one tick it will fill a long order. However if it does not fall that one and rises 5 or more ticks I want to remove that order and not trade.

    would something like this work? or is there a better way?

    if (myEntryOrder != null && GetCurrentAsk() >= limPrice+4*TickSize)
    CancelOrder(myEntryOrder);

    #2
    shazzmoe, yes this should do it - you should also keep in mind this limit order as you have coded it now would expire at the end of the bar, so if you want to keep this placed on the next either resubmit each bar or set this to liveUntilCancelled - http://www.ninjatrader-support.com/H...LongLimit.html
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Code:
       protected override void OnBarUpdate()
              {
                  if(ToTime(Time[0]) == 113000){
                          limPrice = Open[0]+ -1*TickSize;
                          myEntryOrder = EnterLongLimit(0, true, 1, limPrice , "goLONG");
                      
                  }
      
      
               if (myEntryOrder != null && GetCurrentAsk() >= limPrice+4*TickSize)
                      CancelOrder(myEntryOrder);
      
      }
      Thank you, however after some testing I've realized another problem. Because of other things that get calculated in my strat I need to run this on a 5 minute bar chart.

      If i want it to enter exactly at 11:30 I could have it trade at the end of the 11:25 bar using calc on bar close, however doing so would prevent the order from cancelling if it moved to far away in that 5 min span. But if i set calc on bar close = false it constantly triggers a new limit order durring that bar because the first statement is true

      I thought maybe i could put a bool value as a flag (something like isLimitPlaced) but this doesn't seem to work for a chart that spans more than 24 hours

      Comment


        #4
        shazzmoe,

        Use CalculateOnBarClose = false and then for the parts where you want it to process at the end of the bar limit it through the use of this:

        if (FirstTickOfBar)

        Remember to reference back one index value so [0] would be [1] when using such a statement to try and access the price of the bar that just closed.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Ok thank you so much I think this should work but I just wanted to double check. (I'm being extra cautious because I had an incorrect entry this morning that cost me quite a bit)

          Code:
          protected override void OnBarUpdate(){
          
            if(ToTime(Time[0]) == 113000 && FirstTickOfBar){
                if([I]someCondition)[/I]{
                  limPrice = Open[0]+ -1*TickSize;
                  myEntryOrder = EnterLongLimit(NuContracts, limPrice , "LE");
                }
                else{
                  limPrice = Open[0]+ 1*TickSize;
                  myEntryOrder = EnterShortLimit(NuContracts, limPrice , "SE");
                }
            }
          
                      if (myEntryOrder != null){ 
                          if (Position.MarketPosition == MarketPosition.Short){
                              if(GetCurrentBid() <= limPrice-cancelTrade*TickSize)
                                  CancelOrder(myEntryOrder);
                          }
                          else if (Position.MarketPosition == MarketPosition.Long){
                              if (GetCurrentAsk() >= limPrice+cancelTrade*TickSize)
                                  CancelOrder(myEntryOrder);
                          }                
                      }
          As I understand it this will enter a trade at 11:30 at the first tick. If the market moves away from it by the amount known as "cancelTrade" it will cancel the trade.

          Again thank you so much for your help.

          Comment


            #6
            Looks good shazzmoe, just remember to run this CalculateOnBarClose = false then...easiest to test without risking your live account $ on a new script would be the 'Simulated data feed' option, the trend slider give you full control to check in detail how orders are triggered and cancelled - http://www.ninjatrader-support.com/H...dDataFeed.html
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Stanfillirenfro, Yesterday, 09:19 AM
            7 responses
            51 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by TraderCro, 04-12-2024, 11:36 AM
            4 responses
            69 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Mindset, Yesterday, 02:04 AM
            1 response
            15 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by agclub, 04-21-2024, 08:57 PM
            4 responses
            18 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by Irukandji, Today, 04:58 AM
            0 responses
            6 views
            0 likes
            Last Post Irukandji  
            Working...
            X