/MES Futures Strategy

hectorgasm

Member
0h4U7F.jpg



This is intended to use on a 5 minute graph
-Please feel free to comment or suggest further enhancements

http://tos.mx/HaokTj2


Code:
##CREATED BY GASMOS ;)

########################   PLOTTING THE 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 OverBought = over_bought;
def MiddleLine = 50;
def OverSold = over_sold;

#plot breakout signals of SLOWRSI

def UpSignal = if SlowRSI crosses above OverSold then OverSold else Double.NaN;
def DownSignal = if SlowRSI crosses below OverBought then OverBought else Double.NaN;

#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;

# plot the Moving Averages of SLOWRSI
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;




################################  Plotting the MomentumSMA   ###############################

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

#Momentum
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;

def ZeroLine = 0;

#plotting the arrows of Momentum SMA

def UpSignal1 = if Momentum crosses above pMA11 then pMA11 else Double.NaN;
def DownSignal2 = if Momentum crosses below pMA11 then pMA11 else Double.NaN;

#######################      PLOTTING Z SCORE    #####################################

def Data = close;
#Computes and plots the Zscore
#Provided courtesy of ThetaTrend.com
#Feel free to share the indicator, but please provide a link back to ThetaTrend.com




input length = 20;
input ZavgLength = 26;

#Initialize values
def oneSD = StDev(price, length);
def avgClose = SimpleMovingAvg(price, length);
def ofoneSD = oneSD * price[1];
def Zscorevalue = ((price - avgClose) / oneSD);
def avgZv = Average(Zscorevalue, 20);

#Compute and plot Z-Score
def Zscore = ((price - avgClose) / oneSD);


def avgZscore = Average(Zscorevalue, ZavgLength);


#This is an optional plot that will display the momentum of the Z-Score average
#plot momZAvg = (avgZv-avgZv[5]);

#Plot zero line and extreme bands
def zero = 0;
def two = 2;
def one = 1;
def negone = -1;
def negtwo = -2;





#############   Plotting 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;
def ZeroLineDI = 0;

#Demand Index 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;













##########USE THIS STRATEGY FOR CONSISTENT RESULTS

AddOrder(OrderType.BUY_auto, SlowRSI crosses above pMA2 and Zscore > -1 and SlowRSI < MiddleLine and SLOWRSI > Oversold and dMIndx > pDMIndxMA2 and (Momentum > pMA11 or Momentum > Zeroline), tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "LE");

AddOrder(OrderType.SELL_auto, SlowRSI crosses below pMA2 and Zscore < -1 and SLOWRSI > Oversold and (dMIndx < pDMIndxMA2), tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SE");

AddOrder(OrderType.SELL_auto, SlowRSI crosses below pMA2 and Zscore < 1 and SlowRSI > MiddleLine and SLOWRSI < Overbought and dMIndx < pDMIndxMA2 and (Momentum < pMA11 or Momentum < Zeroline), tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SE");

AddOrder(OrderType.BUY_auto, SlowRSI crosses above pMA2 and Zscore > -1 and SLOWRSI > Oversold and (dMIndx > pDMIndxMA2), 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);
 
Last edited:

MatthewA

Active member
This is cool but very disorganized... Could you post the study that goes along with the strat?
I have some similar works too maybe we could collaborate
 

tom23824

Member
VIP
another noob question!!
A new LE showed up but description says Buy to Close.
You consider this signal to go long, right?

W3ThigC.jpg
 

MatthewA

Active member
I deleted all the junk code that wasn't being used, now it's clean my dude and also plotted the indicators

http://tos.mx/pfZZTV6
You're doing great things my brother :).
I most likely will not use any of this I am working in the 1 minute range because unfortunately ThinkScript does not support real range bars :( (If they made a30 second bar I would probably strain myself to use that)

I notice that you are correct in that you are not using any re-painting indicators! (y)If you prefer RSI as your Momentum study you may look at @chewie76 take on RSI his HOTZONE I use that with BuyTheDip...

I notice right away that some of you un-profitable trades may have been avoided if you included volume in you Weighted Moving Average.
If it would help later when my eyes have recovered from work I might help you add some volume terms in your Weighted Moving Average

Is TOS still capable of 'near-perfect' auto-trading or was that recently disabled or was only retail options automation disabled or IDK I'm sorry I haven't been keeping up???
 

hectorgasm

Member
You're doing great things my brother :).
I most likely will not use any of this I am working in the 1 minute range because unfortunately ThinkScript does not support real range bars :( (If they made a30 second bar I would probably strain myself to use that)

I notice that you are correct in that you are not using any re-painting indicators! (y)If you prefer RSI as your Momentum study you may look at @chewie76 take on RSI his HOTZONE I use that with BuyTheDip...

I notice right away that some of you un-profitable trades may have been avoided if you included volume in you Weighted Moving Average.
If it would help later when my eyes have recovered from work I might help you add some volume terms in your Weighted Moving Average

Is TOS still capable of 'near-perfect' auto-trading or was that recently disabled or was only retail options automation disabled or IDK I'm sorry I haven't been keeping up???
I checked it out but didn't know what to do with it my dude, and also a quick update. This is working very smoothly and I've noticed it is best at times of high volatility.
w27L94.jpg
 

MatthewA

Active member
I will see what I have that you might like later. I think maybe some 'mean reversal' as in return to where volume is would keep you out of the chop
 

hectorgasm

Member
I will see what I have that you might like later. I think maybe some 'mean reversal' as in return to where volume is would keep you out of the chop
Man that would be awesome, also I'm thinking on incorporating Some rules so it trades always inverted to the /VX futures
 

Chence27

Active member
This reminds me of one of those charts that is purposefully messy beyond comprehension to make fun of traders who use way too many indicators.
 

rad14733

Well-known member
VIP
@MatthewA what do you mean TOS does use real range bars?

@Nomak Have you tried using the Range Bars that come standard in TOS...??? Click on Chart Settings > Settings > Time Axis > Aggregation Type > Range... Then go to Range Type > Range Bars... Select your Price Range > ATR or Ticks... And Select Time Interval...

1AJMIyl.png
 

Nomak

Member
2019 Donor
@rad14733 yeah that's what I thought. I use range bars but not the ATR because I like to control the size of the movement. TOS seems to need at least 10 days selected to find the ATR.

I read somewhere on the net that TOS range bars work like this:
If you trade YM there are times when with in one minute it can go down 40 points and
head back up all in the same minute. Tos range bars will form on the way down, but erase themselves on the way back up if that one minute time bar is not done. In fairness once the one minute bar is done, phantom bars are created and back fill where price has been
 

rad14733

Well-known member
VIP
@rad14733 yeah that's what I thought. I use range bars but not the ATR because I like to control the size of the movement. TOS seems to need at least 10 days selected to find the ATR.

I read somewhere on the net that TOS range bars work like this:

Renko Bars work that way but I'm not sure whether Range Bars do... Renko Bars go by movement via Ticks to paint bricks but I think Range Bars work more as expected... Refer to https://tlc.thinkorswim.com/center/howToTos/thinkManual/charts/Chart-Aggregation/Range-Charts for more information... The Learning Center is your friend...
 

rj3137

New member
I've been learning some coding but I'm not sure how to add a take profit in this script. Can anyone give any advice or pointers? There is a stop loss so I think it would be useful to add an adjustable take profit as well. That might increase the win ratio
 

rad14733

Well-known member
VIP
I've been learning some coding but I'm not sure how to add a take profit in this script. Can anyone give any advice or pointers? There is a stop loss so I think it would be useful to add an adjustable take profit as well. That might increase the win ratio

I'm glad to hear that your coding skills are coming along... I don't trade futures so I'm going to refrain from commenting on take profit strategy at this point and let someone more familiar with futures to assist... I scalp options and am usually all-in or all-out... If I were to take partial profit I'd base it on RSI or other indicators...
 

Similar threads

Top