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.
// 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");
}
}
}

Comment