5min /ES Futures Strategy For ThinkOrSwim

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

https://ibb.co/cFMzdtK

Here are more "stop" error skewing the P/L by a good margin.

It's because the stop order has a trade price defined as the stop value. Since close is being used to define the condition, the stop trade price should probably be the next day's open, open[-1] instead of the stop value which isn't a realistic value,. By definition, the close has to be above or below the stop value, so unlikely you'd trade at that value either way.
 
First glance, it looks interesting. I'll try it out on a simulator.

Question - why aren't the upper and lower bands appearing for other products like GBP/USD and /ZB? It only shows for /ES. Nothing in the code that highlights it's only for /ES.

Thanks.
 
  • Like
Reactions: HEC
Has anyone been able to test this with the open[-1] so the prices are correct for buying and selling? Or any other tweaks that have been made to provide more accurate results? I do like what I have seen when I have looked at the code
 
This seems promising.

However I believe there is a bug here:

Code:
if barindex > Amplitude and
nexttrend[1] == 1
{
   # ...
}
else if nexttrend[1] == 0
{
  # ...
}
else
{
  nexttrend = nexttrend[1];
}

The variable nexttrend will never be defined. That causes "up" to never be equal to 1.
I am trying to fix the script but I am not sure what the intent is.
 
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", price = stopb);
def stops = EntryPrice() + ATR() * stop_mult;
AddOrder(OrderType.BUY_to_close, CLOSE >= stops, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop", price = stops);
the indicator is not working
 
the indicator is not working
Unfortunately, "indicator is not working", is not enough information to determine where you went astray.
The most common error that members have when loading STRATEGIES is that they do not realize that STRATEGIES need to be copy and pasted into the STRATEGIES TAB (which is located to the right of the studies tab in chart settings).

Other than that the indicator itself does not seem to have any problems:
azTuHTB.png
 
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
Hi Akotic. Have you used the 5Min strategy in live trading? If so, have the results been similar to the backtests?
Thanks
 
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
hello, did you manage to convert it to ninjascript for NT8 ?? I would be interested in testing it there too to use capital similar to the one I have
 
Last edited:
Does anyone know why the FloatingPL does not show up for NQ? It shows up for ES.
Also, I am not sure if anyone has been able to convert this to NT8. Thanks!!
 
How do you make a AddLabel for the below AddOrder ?. I tried to use 'close <= stopb' for an if statement but it did not trigger the label.

AddOrder(OrderType.SELL_TO_CLOSE, close <= stopb, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop", price = open[-1]);
 
How do you make a AddLabel for the below AddOrder ?. I tried to use 'close <= stopb' for an if statement but it did not trigger the label.

AddOrder(OrderType.SELL_TO_CLOSE, close <= stopb, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop", price = open[-1]);
Chart with label issue >>https://tos.mx/aROuey3

Also interested in the answer as to why it is not able to be triggered.
 
Last edited by a moderator:

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
175 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