In this example, the algorithm buys a ES futures contract when an up trend is defined by a EMA Cross in SPY. When the contract expires, another one if bought.