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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          633 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          364 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          567 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          568 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X