A Contrarian Challenge
Today, we’re going against the grain. There are certain financial instruments, specifically stock indices, that are characterized by a long-term upward bias.
And that’s why creating long strategies on them is easier, because, in fact, we’re taking advantage of what we can consider to be their inherent traits.
But let’s try to make things harder for ourselves by creating a short-only strategy, which could serve as a kind of hedge for long strategies or investments in general, since systematic trading allows us to benefit from broader diversification.
To do this, we’ll try to build a strategy that’s as simple as possible on the Mini S&P 500 future, an instrument that, I remind everyone, is traded on the CME in Chicago with a session that runs from 5:00 p.m. to 4:00 p.m., exchange time.
Alright, at this point I’d say let’s jump straight to the chart and see what we can come up with.
Here we are. What we currently see on the chart is the Mini S&P 500 future, in this case with a 60-minute time frame.
I’ve already set up a basic strategy here, which we’ll now go through together.
A Simple Short Strategy
As you can see, this is a very simple strategy that trades only short, as we mentioned earlier, and it’s built around a single condition.
That condition is specifically an inside bar.
What do I mean by an inside bar? I mean a bar that, imagine this, has a range that is completely within the range of the previous bar.
To call it in the code, I’ve written this very simple line: the high must be lower than the previous bar’s high, and the low must be higher than the previous bar’s low.
Another thing I’ve set is a time window for trading activity, which in this case I’ve set from 8:30 a.m. to 4:00 p.m.
Let’s try to understand why I set it up this way. We know that the Mini S&P 500 future is an instrument that trades 23 hours a day, as we mentioned in the video intro, from 5:00 p.m. until 4:00 p.m. the next day.
However, what I tried to do in this code is focus only on the session known as the “cash” session, that is, the session during which the stock markets are also open, and which we can consider as the most liquid session.
This session starts at 8:30 a.m. exchange time.
Exit on Close and Stop Loss
So, if we are within this time window and condition 1 occurs, which, as we said before, is the inside bar, then we will open a short position on the break of the current bar’s low.
Finally, there are two more very simple commands here.
The first is the set exit on close. Basically, regardless of how the trade goes, I will close the position at the end of the session.
This is therefore a purely intraday strategy, and I also want to emphasize that, since we are working only short on this instrument, it would be difficult to get a good result with a multi-day approach.
That’s another reason why we decided to use set exit on close.
Finally, I set a stop loss of $1,000 in this case.
Alright, now let’s go back to the chart. And once again, there’s something important I want to point out.
A $1,000 stop loss on a 60-minute time frame isn’t really a large value.
That’s why, when I launched the backtest, I also enabled the Bar Magnifier.
What does the Bar Magnifier do? It essentially looks inside the candlestick.
So in this case, considering we have a relatively tight stop loss, using the Bar Magnifier gives us a more realistic backtest.
A Practical Example
Alright, with that said, let’s take a look at a trade we can see here as n example.
Here we can clearly see that this bar is an inside bar relative to the previous bar.
In fact, the high is lower than the high of the previous bar, while the low is higher.
So, since this condition is met and we are also within the operational time window, a short position is opened at the break of this low.
In this case, we see a trade that ends up in profit, and the position is closed at the end of the session thanks to the set exit on close we mentioned earlier.
Initial Performance
Great. At this point, let’s go ahead and take a look at the performance report.
And here we can see that starting from 2010, overall, the result is trending upward.
Certainly, it’s not a steady equity line, there are some significant drawdown phases, but considering the buy and hold of this financial instrument, which you can see here, we are looking at a strategy that has some potential.
As for the average trade, we’re around $21.
Obviously, we see 1,284 trades here, all short, because the strategy operates only short. And unfortunately, with this average trade value, this is a strategy that, if traded live, couldn’t yet cover operating costs such as slippage and commissions.
A Simple but Powerful Adjustment
So, let’s try making a change and do a bit of brainstorming.
One idea that comes to mind, for example, based on how the trade is structured here, is that instead of opening the position at the break of this low, we could open the position at the break of the previous low.
Let me explain better: since the condition is formed by these two candlesticks, let’s try to see what happens if, instead of opening at the break of the inside bar, I open the position at the break of the low of the candlestick that comes before the inside bar.
This way, we have, in a sense, a sort of confirmation, meaning that if the price drops enough to break through the previous bar, then it might be that we’re looking at a more efficient trade.
Obviously, to find the answer, the only thing we can do is test it.
So let’s go back to the code for a moment, and here, instead of opening the position at the break of the inside bar, we’ll open the position at the break of the low of the bar before that one.
We recompile, and now let’s take a look at the trade. Here it is.
In this case, let me zoom in a bit so it’s easier to see, the position is no longer opened at the break of this bar, but instead it’s opened at the break of the low of the previous bar.
Let’s take a look at the impact of this simple change, and we can see that, from an equity line perspective, there’s a clear improvement.
Now we’re looking at a strategy that generates profits in a much more consistent way compared to what we saw earlier, and also, the drawdowns are definitely smaller.
So it seems that waiting for this kind of confirmation, meaning the break of the previous bar’s low, is definitely a smart move.
Let’s check how the average trade of the strategy has changed.
Here we clearly see that fewer trades are being executed.
Why are there fewer trades? It’s partly due to what we said earlier, because we’re, in a way, waiting for confirmation.
It’s less likely that a lower low will be broken compared to the low of the inside bar. So as a result, there’s indeed a drop in the number of trades.
But on the flip side, we see a significant increase in the average trade, which has gone from $25 in the previous strategy to $75.
That still isn’t a large enough figure for this strategy to go live, but we could definitely refine this system even further.
Improving the Time Window
What other ideas could we come up with?
Well, considering that, as we mentioned earlier, the strategy only operates from 8:30 a.m. to 4:00 p.m., I’d say that, for example, if a breakout happens at 3:00 p.m., that breakout likely won’t have enough time to generate a decent profit, since it happens close to the end of the session.
So let’s try to see what happens if we move the end of the operational time window earlier, meaning we only take signals during the early part of the cash session.
And if there’s a signal close to the session’s close, we’ll skip it, because most likely, it wouldn’t result in a high enough average trade.
To do this, in this case, we just need to optimize this second input, which refers to the “my end time,” so the end of the operational time window.
I’ve already run the optimization, so let’s take a look at the results.
Here you can see what happens when we vary the “my end time.”
Specifically, what would happen if we set the end of the operational time window to 10, 11, 12, and so on.
Four o’clock, 16:00, is the input we’ve been using so far, so the results we’ve seen from the strategy up to now are with this input, where essentially the end of the time window matches the end of the session.
Optimization and Final Choice
Alright, so let’s take a look at these results.
We can see, that the net profit increases as the operational window gets wider.
And clearly, this is not a coincidence—because if we look at the Total Trades, we can also see that more trades are being executed.
And that makes perfect sense, because the wider this operational window is, the more likely it is that a certain condition will occur, and as a result, we can enter a trade.
But the most interesting thing shows up when we look at this column here for average trade.
Here we clearly see that with the current version, we have an average trade of $75.
But if we were to shorten the operational window, say, to 1:00 p.m. or even 12:00 noon, we can see a significant increase in this metric.
Specifically, based on these results, I would personally go with the value 13, 1:00 p.m., because that’s where we don’t see a major loss in net profit, we see an improvement in average trade, and we also see an improvement in drawdown.
So I’d say let’s go ahead and select this value.
Alright, let’s also take a look at the equity line.
We can see that it basically doesn’t change much, it’s more or less the same equity line we saw earlier, but as we mentioned before, in terms of average trade, we’re now at a value that we could say is borderline for going live with this strategy.
Conclusions
That said, we’ve seen how it’s possible to generate profit even on the short side of this financial instrument, despite the long-term upward bias.
What’s interesting is that we managed to do this with just two very simple conditions: an operational time window, which we didn’t even change the start of, but only adjusted the end, and a second condition related to the inside bar.
With that said, if you’re interested in topics like this, as always, you’ll find useful information at the first link in the description, and let me know in the comments what you think about this simple but effective system.
See you in the next video.





