The rationale behind this simple breakout strategy is to take advantage of a big (4%) daily move upward that would likely squeeze all those short sellers who were hoping the stock would go down. This strategy thinks that moving 4% up in a single day is such a big move that it would scare all the short sellers into covering their positions by buying long, thereby driving the price up even further the next day. (Of course, contrarian traders would be thinking of going short the next day, to take advantage of a price recovery to lower levels.) This strategy uses the OnBarOpen event handler, so that all trading events take place at the beginning of the day, at market open (on the leading edge of the daily bar). As each day begins, the strategy calculates an entry price 4% higher than yesterday’s close, and issues a limit order to open a long position if that price is reached. The next morning, if a position exits (opened during yesterday’s trading), the strategy issues a market order to close the position.

using OpenQuant.API;

public class MyStrategy : Strategy
{
	[Parameter("Order quantity (number of contracts to trade)")]
	int Qty = 100;
	
	// enter trade on 4 breakoutPercent breakout
	[Parameter("Percent")]
	double BreakoutPercent = 4;
	
	// orders and trade quantity
	Order buyOrder;
	// for calculating breakout price limit
	double prevClose;

	public override void OnStrategyStart()
	{
		prevClose = -1;
	}

	public override void OnBarOpen(Bar bar)
	{
		// we need to let the first bar go by before we can
		// calculate the breakout limit
		if (prevClose != -1)
		{
			// if we do not have a position, then cancel the
			// previous limit order (it is out of date)
			if (!HasPosition)
			{
				if (buyOrder != null)
					buyOrder.Cancel();

				// now try to enter a trade by setting a limit order
				// to automatically buy in if the big 4% jump arrives.
				// This order will reside on the exchange servers, and 
				// will execute during the day if the limit is triggered.
				double breakout_fraction = 1 + (BreakoutPercent / 100);
				double breakout_price = prevClose * breakout_fraction;
				buyOrder = BuyStopOrder(Qty, breakout_price, "Entry");	
				buyOrder.Send();
			}

				// if we have a position open, then close it now. 
				// Now (which is the leading edge of today's daily bar)
				// is the start of the day after the trade was opened.
			else
				Sell(Qty, "Exit");
		}
	}

	public override void OnBar(Bar bar)
	{
		// update the prevClose value for the breakout calculation
		prevClose = bar.Close;
	}
}