This strategy is a variation on the Four Down Days strategy. A plain Four Up Days (flip) of the down days strategy did not produce good results for Altucher, reinforcing his statement that going short is not the exact opposite of going long. So he provides this “up day” variation, which uses up days instead of down days, but it also enforces two extra conditions. The first condition is that the fourth day up has to be a huge one (2% or more). After 3 days up already, going up 2% on the fourth day would be quite impressive. Theoretically, such a jump on the fourth day would be a strong invitation to long stock holders to take some profits off the table the next morning, thereby driving down the price. So this strategy issues a short order on the close of the fourth day, for execution at the open of the fifth day. The second condition is that the strategy exits when it reaches a 1% profit target, and uses a limit order to implement the exit during trading day 5. If the position is still open at the end of day 5, the strategy issues a market order to close the position, for execution at market open on day 6. Keep in mind that this discussion assumes the use of daily bars.
using OpenQuant.API; public class MyStrategy : Strategy { [Parameter("Order quantity (number of contracts to trade)")] double Qty = 100; // exit with a profit target of 1% [Parameter("Profit Target")] double ProfitTarget = 1; // last day up must be a big 2% up day [Parameter("Up Move")] double UpPercent = 2; // Number of consecutive down closes [Parameter("Number of consecutive down closes")] int ConsClosesCount = 4; // count of up days int count; double prevClose; // orders Order buyOrder; Order sellOrder; public override void OnStrategyStart() { prevClose = -1; count = 0; } public override void OnBar(Bar bar) { // we need to let a bar go by to capture the prev close if (prevClose != -1) { // if we don't have a position open, update the count // of up days, and try to enter a trade if (!HasPosition) { if (prevClose < bar.Close) count++; else count = 0; // if we have seen 4 (consClosesCount is equal to 4 by default) up days, AND if the last day // up was 2% or more, then open a new position, // going short on the day's close if (count == ConsClosesCount) { if ((bar.Close - prevClose) / prevClose >= UpPercent / 100) { sellOrder = MarketOrder(OrderSide.Sell, Qty, "Entry"); sellOrder.Send(); } } } // if we have a position open, cancel our previous // 1% profit target order, and close using a market order else { buyOrder.Cancel(); Buy(Qty, "Buy Cover"); } } // now today's close becomes the previous close prevClose = bar.Close; } public override void OnPositionOpened() { // when we open a position, immediately issue a limit order // for our 1% profit target double target_price = sellOrder.AvgPrice * (1 - ProfitTarget / 100); buyOrder = BuyLimitOrder(Qty, target_price, "Exit (Take Profit)"); buyOrder.Send(); } }