5min /ES Futures Strategy For ThinkOrSwim

Akotic

New member
I've gained a lot from this website in the shadows and figured I'd share this strategy I'm working on for opinions and/or suggestions.

This uses the halftrend indicator with added deviation bands I coded in. The conditions are fairly simple.

On the 5min 180day test it gets 1270 trades, a 2.3 profit factor and a pretty sweet equity curve that you should be able to see in the screenshot below.

This is a trend following strategy.


-----------Click for image----------

Settings In use:

Price: Low
Amplitude: 20
Num dev dn: -4
num dev up: 4
stop mult: 0.5

-------------------------
Here's the strategy code:

#Trender

input Price = High;
input Amplitude = 25;
input Num_Dev_Dn = -17;
input Num_Dev_up = 17;
def lowpricei;
def highpricei;
def lowma;
def highma;
def barindex = BarNumber();
def nexttrend;
def maxlowprice;
def trend;
def minhighprice;
def up;
def down;

def halftrend;

lowpricei = Lowest(low, Amplitude);
highpricei = Highest(high, Amplitude);
lowma = Average(low, Amplitude);
highma = Average(high, Amplitude);
if barindex > Amplitude and
nexttrend[1] == 1
{
maxlowprice = Max(lowpricei, maxlowprice[1]);
trend = if highma < maxlowprice[1] and close < low[1]
then 1
else trend[1];
nexttrend = if highma < maxlowprice[1] and close < low[1]
then 0
else nexttrend[1];
minhighprice = if highma < maxlowprice[1] and close < low[1]
then highpricei
else minhighprice[1];
}
else if nexttrend[1] == 0
{
minhighprice = Min(highpricei, minhighprice[1]);
trend = if lowma > minhighprice[1] and close > high[1]
then 0
else trend[1];
nexttrend = if lowma > minhighprice[1] and close > high[1]
then 1
else nexttrend[1];
maxlowprice = if lowma > minhighprice[1] and close > high[1]
then lowpricei
else maxlowprice[1];
}
else
{
maxlowprice = maxlowprice[1];
trend = trend[1];
nexttrend = nexttrend[1];
minhighprice = minhighprice[1];
}
if trend == 0
{
up = if trend[1] <> 0
then down[1]
else Max(maxlowprice[1], up[1]);
down = 0;
}
else if trend[1] <> 1
{
down = up[1];
up = 0;# up[1] este era el error
}
else if trend == 1
{
down = Min(minhighprice, down[1]);
up = up[1];
}
else
{
up = up[1];
down = down[1];
}
if up > 0
{
halftrend = up;
}
else
{
halftrend = down;
}


plot MidLine = halftrend;
plot LowerBand = halftrend + Num_Dev_Dn;
plot UpperBand = halftrend + Num_Dev_up;

Midline.SetStyle(Curve.Firm);
midline.AssignValueColor(if up > 0 then color.Cyan else color.Red);
Midline.SetLineWeight(2);



AddOrder(OrderType.BUY_auto, Price crosses above midline and up, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "LE");

AddOrder(OrderType.SELL_auto, Price crosses below lowerband, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SE");

AddOrder(OrderType.SELL_auto,Price crosses below midline and down, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SE");

AddOrder(OrderType.BUY_auto,Price crosses above upperband, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "LE");

#STOP LOSS ATR

input stop_mult = 2.5;

def stopb = EntryPrice() - ATR() * stop_mult;
AddOrder(OrderType.SELL_to_close, CLOSE <= stopb, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop");
def stops = EntryPrice() + ATR() * stop_mult;
AddOrder(OrderType.BUY_to_close, CLOSE >= stops, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop");
 
Last edited by a moderator:
What are the entry exit conditions? Sorry, not reading the code
Rich (BB code):
AddOrder(OrderType.BUY_auto, Price crosses above midline and up, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "LE");
AddOrder(OrderType.SELL_auto, Price crosses below lowerband, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SE");
Must be cut& pasted into the strategy tab not the regular study tab
 
Thanks Akotic. Some questions: 1- Is your P/L for 24 hr trading or for standard market hours? , 2 Have you traded it in real time? 3- It seems the default values are different to the ones you suggested. Which are the ones used for 5 mins?, 4- Any idea on the drawdown experieneced so far?
Thanks for the strategy!!!
 
Thanks Akotic. Some questions: 1- Is your P/L for 24 hr trading or for standard market hours? , 2 Have you traded it in real time? 3- It seems the default values are different to the ones you suggested. Which are the ones used for 5 mins?, 4- Any idea on the drawdown experieneced so far?
Thanks for the strategy!!!
1) 24hr
2) No, I need to code it in ninja script and will be doing more testing on NT8.
3) I listed the settings I use in the original post
4) picture shows the equity curve with minimal drawdown. I need to add the MDD to the excel sheet but growth is very consistent
 
1) 24hr
2) No, I need to code it in ninja script and will be doing more testing on NT8.
3) I listed the settings I use in the original post
4) picture shows the equity curve with minimal drawdown. I need to add the MDD to the excel sheet but growth is very consistent
Thanks.. Ill try it !(y)
 
Unfortunately, few people can wait out a loss of $93000+ before turning a profit

You are mistaken, TOS runs the test taking 100 contract positions. It’s a drawdown of only 18 points starting out. Also, this is simply how trend trading strategies function. Many tiny losses, and giant wins.
 
"equity curve (drawdown), and profit factor" is the mq4...mq5 universe. Real world; none using ThinkOrSwim ahs $93000 to play with. I suspect TOS will attempt stop you (which is a good thing) before you lose it all!
 
"equity curve (drawdown), and profit factor" is the mq4...mq5 universe. Real world; none using ThinkOrSwim ahs $93000 to play with. I suspect TOS will attempt stop you (which is a good thing) before you lose it all!
Perhaps you’re not understanding. The drawdown you are referring to is very minimal. Like I said, about 18 points. You are just looking at the number which is irrelevant because TOS runs the backtest taking 100 contract trades.
 
Now your are getting somewhere. Now do another study with 1 contract or more realistic number. like that One can go from there.
 
Can't fault your method or desire. Looking forward to seeing a succeesful reproducible trade algo. Cheers!
 
Thanks, however I’ve never had a reason to change it since it’s not needed to get the metrics I want.
or you can just make the number of contracts an input and add tradesize to your order. Then you can test away with whatever size you normally trade in. Also, don't forget to consider fees per contract when looking at reports. Wish they'd include that.

input NumContracts = 100;
...
AddOrder(OrderType.BUY_auto, Price crosses above midline and up, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "LE", tradesize=NumContracts);
 
Hi, @Akotic I was checking your strategy. it seems very good but one drawdown.... please check when stop loss hits. Its way above the candle means it does not show a real price when the stop loss is getting it but the buy and sell order seems good. if you could correct the stop loss then we can backtest it correctly.
 
Thanks for sharing @Akotic. As I write this I'm working with a NT8 developer I hired to code a strategy for me which so far seems very profitable in the ToS backtest but I wanted to tested it live on NT @Robster021. The guy didn't manage yet to reproduce it 100% exactly as the code I have for ToS but when he does, if the strategy proves to be as profitable as in the backtest I will gladly share it.
[/QUOTE
It’s became apparent that the TOS backtester simply isn’t reliable. I’m now working on similar setups on NT8 that are performing well on much larger amounts of data. Currently using a trend following strategy during market hours only on 3000 tick MES
 
Last edited by a moderator:
Is anyone able to add arrows on the "current" bar before the next bar shows an entry signal? Similar to just making it a regular indicator?
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
494 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top