Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Joining Bid/Ask for a set time then going to market if not filled

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

    Joining Bid/Ask for a set time then going to market if not filled

    Hello all,

    I'm trying to write a strategy that uses 1-minute bars and upon a trigger being met joins the bid/ask for a portion of the current minute (from 10 to 30 seconds into the minute) and, if not filled, converts to a market order. I'm comfortable using the computer clock to determine the limits of my patience.

    Here's my attempt, but not sure if it will do what I want. Any comments/questions/suggestions are greatly appreciated.

    Code:
    // In the Initialize() method:
    
    			CalculateOnBarClose = false;
    
    //  In the OnBarUpdate() method
    
    if (Historical) int second = 0;
    else second = DateTime.Now.Second;
    if (Position.MarketPosition == MarketPosition.Flat){
    	if (Close[1] <= SELong && Close[0] > SELong) waitFor = 1;
    	else if (Close[1] >= SEShort && Close[0] < SEShort) waitFor = -1;
    	if (waitFor != 0){
    		if (!triggerPassed && (second > 10 && second < 30)){
    			if (waitFor == 1) EnterLongLimit(Quant, GetCurrentBid(), "LELimit");
    			else if (waitFor == -1) EnterShortLimit(Quant, GetCurrentAsk(), "SELimit");
    		}
    		else if (second >= 30 || second < 1) triggerPassed = true;
    		if (triggerPassed){
    			if (waitFor == 1) EnterLong("LEMarket");
    			else if (waitFor == -1) EnterShort("SEMarket");
    		}
    	}
    }

    #2
    Hello,

    Thanks for your forum post.

    One of our NinjaScript Certified Tech's will respond in the morning when they get in.

    Thank you for your patience.
    BrettNinjaTrader Product Management

    Comment


      #3
      Hi kaydgee, looks ok to me on quick overview, you would need to give a run in realtime or Market Replay to better debug.

      Also: I did not see you cancelling the working limit orders if the 'patience' timer is over, they would expire after the bar, however you might want to cancel them just in case...

      Comment


        #4
        Hi Bertrand,

        Thank you for your response. I assumed the orders would be cancelled on the new tick, but thank you for pointing out that they survive for the duration of the bar.

        I've never used Market Replay. Can you point me to a reference that describes its use?

        All the best,

        Ken
        Last edited by kaydgee; 09-02-2010, 08:09 AM. Reason: Read up on OnOrderUpdate() and CancelOrder()

        Comment


          #5
          Hi Ken,

          You can see here for Market Replay documentation:
          Ryan M.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          42 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          25 views
          0 likes
          Last Post PaulMohn  
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          162 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          98 views
          1 like
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          157 views
          2 likes
          Last Post CaptainJack  
          Working...
          X