/MES Futures Strategy For ThinkOrSwim

@hectorgasm Pretty cool. Here is the PnL chart for the past 6 months. Struggled the first month, but it seems like it goes in stair step increments. Goes sideways as market goes sideways? and takes advantage of the moves?

Tagecpu.png


It looks promissing.
 
@hectorgasm Pretty cool. Here is the PnL chart for the past 6 months. Struggled the first month, but it seems like it goes in stair step increments. Goes sideways as market goes sideways? and takes advantage of the moves?

Tagecpu.png


It looks promissing.
That's what I haven't been able to figure out man, but I created this algo in 2020 when the market was crashing and remained profitable throughout the that year and also the last months of 2019, but struggled on the last 3 months of 2020
 
That's what I haven't been able to figure out man, but I created this algo in 2020 when the market was crashing and remained profitable throughout the that year and also the last months of 2019, but struggled on the last 3 months of 2020
I think there are many uncertainties in the market lately. Trends reverse too quickly or don’t follow through. I’m still impressed with what it can do.
 
Hi @hectorgasm, great strategy! I've been paper trading it and want to give it another 2 days before using a live account on the micros. Can this strategy be translated into Ninjatrader 8? Thank you for your time!!!
 
@hectorgasm some clean up to the script and added plots to show the ATR targets and arrows. I'll add stop arrows and alerts next.

Code:
##CREATED BY GASMOS ;)
## barbaros - 2021/03/23 - clean up

# SlowRSI

input emaLength = 5;
input rsiLength = 10;
input over_bought = 80;
input over_sold = 20;

# Breakout signals of SLOWRSI
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

def ema = ExpAverage(close, emaLength);
def netChgAvg = WildersAverage(close - ema, rsiLength);
def totChgAvg = WildersAverage(AbsValue(close - ema), rsiLength);
def chgRatio = if totChgAvg != 0 then netChgAvg / totChgAvg else 0;

def SlowRSI = 50 * (chgRatio + 1);
def MiddleLine = 50;

# Moving Averages of SLOWRSI

input MALength = 9;
input AverageType1 = AverageType.WEIGHTED;
input MALength2 = 26;
input AverageType2 = AverageType.SIMPLE;
input MALength3 = 57;
input AverageType3 = AverageType.SIMPLE;
input MALength4 = 200;
input AverageType4 = AverageType.HULL;

def MA = MovingAverage(AverageType1, SlowRSI, MALength);
def pMA = MA;
def MA2 = MovingAverage(AverageType2, SlowRSI, MALength2);
def pMA2 = MA2;
def MA3 = MovingAverage (AverageType3, SlowRSI, MALength3);
def pMA3 = MA3;
def MA4 = MovingAverage(AverageType4, SlowRSI, MALength4);
def pMA4 = MA4;

# MomentumSMA

input price = close;
input momentumLength = 26;
input smaLength = 26;
input AverageType11 = AverageType.SIMPLE;
input smaLength2 = 100;
input AverageType22 = AverageType.SIMPLE;

Assert(momentumLength > 0, "'momentum length' must be positive: " + momentumLength);

def Momentum = price - price[momentumLength];

# MomentumSMA Moving averages
def MA11 = MovingAverage(AverageType11, Momentum, smaLength);
def pMA11 = MA11;
def MA22 = MovingAverage(AverageType22, Momentum, smaLength2);
def pMA22 = MA22;

# Z SCORE

input length = 20;
input ZavgLength = 26;

def oneSD = StDev(price, length);
def avgClose = SimpleMovingAvg(price, length);
def Zscorevalue = ((price - avgClose) / oneSD);

def Zscore = ((price - avgClose) / oneSD);
def avgZscore = Average(Zscorevalue, ZavgLength);

# DEMANDIndex

input lengthDI = 20;

def wClose = (high + low + 2 * close) * 0.25;
def wCRatio = (wClose - wClose[1]) / Min(wClose, wClose[1]);
def closeRatio = 3 * wClose / Average(Highest(high, 2) - Lowest(low, 2), lengthDI) * AbsValue(wCRatio);
def volumeRatio = volume / Average(volume, lengthDI);
def volumePerClose = volumeRatio / Exp(Min(88, closeRatio));
def buyP;
def sellP;
if (wCRatio > 0) {
    buyP = volumeRatio;
    sellP = volumePerClose;
} else {
    buyP = volumePerClose;
    sellP = volumeRatio;
}
def buyPres = if IsNaN(buyPres[1]) then 0 else ((buyPres[1] * (lengthDI - 1)) + buyP) / lengthDI;
def sellPres = if IsNaN(sellPres[1]) then 0 else ((sellPres[1] * (lengthDI - 1)) + sellP) / lengthDI;
def tempDI;
if ((((sellPres[1] * (lengthDI - 1)) + sellP) / length - ((buyPres[1] * (lengthDI - 1)) + buyP) / lengthDI) > 0) {
    tempDI = - if (sellPres != 0) then buyPres / sellPres else 1;
} else {
    tempDI = if (buyPres != 0) then sellPres / buyPres else 1;
}
def DMIndx = if IsNaN(close) then Double.NaN else if tempDI < 0 then -1 - tempDI else 1 - tempDI;

# DEMANDIndex Moving Averages

input DMIndxMALength = 8;
input DMIndxAverageType = AverageType.SIMPLE;
input DMIndxMALength2 = 26;
input DMIndxAverageType2 = AverageType.WEIGHTED;
input DMIndxMALength3 = 40;
input DMIndxAverageType3 = AverageType.SIMPLE;
input DMIndxMALength4 = 50;
input DMIndxAverageType4 = AverageType.SIMPLE;

def DMIndxMA = MovingAverage(DMIndxAverageType, DMIndx, DMIndxMALength);
def pDMIndxMA = DMIndxMA;
def DMIndxMA2 = MovingAverage(DMIndxAverageType2, DMIndx, DMIndxMALength2);
def pDMIndxMA2 = DMIndxMA2;
def DMIndxMA3 = MovingAverage(DMIndxAverageType3, DMIndx, DMIndxMALength3);
def pDMIndxMA3 = DMIndxMA3;
def DMIndxMA4 = MovingAverage(DMIndxAverageType4, DMIndx, DMIndxMALength4);
def pDMIndxMA4 = DMIndxMA4;

# Strategy

def LE1 =  SlowRSI crosses above pMA2 and Zscore > -1 and SlowRSI < MiddleLine and SLOWRSI > over_sold and dMIndx > pDMIndxMA2 and (Momentum > pMA11 or Momentum > 0);
def LE2 = SlowRSI crosses above pMA2 and Zscore > -1 and SLOWRSI > over_sold and (dMIndx > pDMIndxMA2);

def SE1 = SlowRSI crosses below pMA2 and Zscore < -1 and SLOWRSI > over_sold and (dMIndx < pDMIndxMA2);
def SE2 = SlowRSI crosses below pMA2 and Zscore < 1 and SlowRSI > MiddleLine and SLOWRSI < over_bought and dMIndx < pDMIndxMA2 and (Momentum < pMA11 or Momentum < 0);

AddOrder(OrderType.BUY_auto, LE1, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "LE1");
AddOrder(OrderType.BUY_auto, LE2, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "LE2");
AddOrder(OrderType.SELL_auto, SE1, arrowcolor = GetColor(1), name = "SE1");
AddOrder(OrderType.SELL_auto, SE2, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SE2");

# Stoploss ATR

input stop_mult = 2.5;

plot stopb = EntryPrice() - ATR() * stop_mult;
stopb.SetDefaultColor(Color.RED);

plot stops = EntryPrice() + ATR() * stop_mult;
stops.SetDefaultColor(Color.RED);

AddOrder(OrderType.SELL_to_close, CLOSE <= stopb, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop", price = stopb);
AddOrder(OrderType.BUY_to_close, CLOSE >= stops, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop", price = stops);

# Plot Arrows

plot LE1Signal = !LE1[1] and LE1;
LE1Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
LE1Signal.SetDefaultColor(Color.GREEN);

plot LE2Signal = !LE2[1] and LE2;
LE2Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
LE2Signal.SetDefaultColor(Color.GREEN);

plot SE1Signal = !SE1[1] and SE1;
SE1Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SE1Signal.SetDefaultColor(Color.RED);

plot SE2Signal = !SE2[1] and SE2;
SE2Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SE2Signal.SetDefaultColor(Color.RED);
 
This looks really nice at first glance. Is there a position-sizing element to this strategy by chance or are all entries fixed positions?
 
This looks really nice at first glance.
I get a red FloatingPL graph when I run the code from post #25.
EDIT: I went back and loaded the original study set from the ToS shortcut in post #1, and noticed the timeframe was set to 30D, 5 minutes.
After I changed my timeframe from 2 D, 5 minutes to 30D, 5 minutes, I got a green P/L graph.
I can thus conclude that some calculations in the study that help it to avoid bad trades depend on more back-data.
EDIT2: I was wrong. these past few days haven't been so hot for the strategy is what appears to have happened (it's not every week a hedge fund goes belly-up, so these past few days are hopefully an anomaly, and we aren't seeing another Lehman Brothers.)


Is there a position-sizing element to this strategy by chance or are all entries fixed positions?
You can modify this at "default trade size for Entry orders" at "Edit Studies" > "Global Strategy Settings".
"Global Strategy Settings" is found at the lower left of the "Edit Studies" screen.

Reference:
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/AddOrder
https://tlc.thinkorswim.com/center/...nd-Strategies/strategies-setup/globalsettings
 
Last edited:
@hectorgasm Do you use this daily and have there been any modifications to the code? I changed the SlowRSI value to 80 instead of 50, added a script to get me out at the last bar of the day (so I'm not getting hit with overnight margins) and I altered the stop loss to get out at HIGH and LOW according to whether short/long, making it more realistic than at bar CLOSE. Really liking what I am seeing here.

@barbaros Curious to see if you have messed around with this since your previous update.
 
@hectorgasm Do you use this daily and have there been any modifications to the code? I changed the SlowRSI value to 80 instead of 50, added a script to get me out at the last bar of the day (so I'm not getting hit with overnight margins) and I altered the stop loss to get out at HIGH and LOW according to whether short/long, making it more realistic than at bar CLOSE. Really liking what I am seeing here.

@barbaros Curious to see if you have messed around with this since your previous update.
Haven't looked at it for a while.
 
guys, had been off for a while and noticed that the code wasn't the same after cleaning it up, now it's back to what it is supposed to be as i updated the code and the link for the chart. ENJOY!
 
Hi, thanks for sharing this ideas.
I´m playing with /MES but I always want to close the trade before 16:45 and dont open a trade until 19:00. So with this conditions I dont leave open the contract while the futures market close.
With your original code the P/L is very profitable but when I write the time condition the results are the opposite way, very awful.
Any Ideas? Dont you also close the futures trade in similar way of time?
 
Hi @hectorgasm, great strategy! I've been paper trading it and want to give it another 2 days before using a live account on the micros. Can this strategy be translated into Ninjatrader 8? Thank you for your time!!!
Hi, how is ur experience with it so far? did u manage to translate it to ninjatrader? im thinking about doing that too.
 
I just came back to Thinkscript after a long time and I a re-acquainting myself with different posts that I should mention once I start sharing some volume studies.
 

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
531 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