Multi Time Frame Multi Indicator Strategy

Hi,

UPDATES:
7-20-2021 - Added Study version
7-20-2021 - Added option to select how many time frames to look at with a new 4th time frame confirmation

Overview
I created this strategy for multiple time frames with multiple indicators as the title states. It utilizes, Stochastic Momentum Index, RSI, various EMA's and CPMO for confirmations and various conditions. It is looking at 3 different timeframes (Low, Medium, High) while the Low time frame will be whatever time frame you have your chart set to (ex. If your chart is set to 1m, then the low period will be 1m, the medium period will be 2m and the high period will be 5m). There are certain timeframes not utilized such as 3m because I was getting poor w/l ratios when utilizing them (see the aggregation period code at the top of the script for what's utilized).

I personally like scalping so I set my charts to the 1m time frame and trade short term options but certain tickers will provide better results on different timeframes.

Disclaimer
I must state... I'm looking for my total profit to be positive and looking less at the win to loss ratio (though I'm a little conservative with the 200 EMA because I've been burned a lot). In some circumstances a higher win to loss ratio can provide greater total profit, in other circumstances, if the wins are greater than the losses (losses cut early), then total profit will be greater (more important imo).

No success is guaranteed but, I hope this community can help me expand and improve on this strategy for the success of us all.

Gratitude.
Thank you all for your assistance in helping me to learn thinkscript and thank you ahead of time for your contributions in making this better!

Thinkscript:

j8CFG6J.png


Ruby:
################################################################
##########            Initial Config                   #########
################################################################
input tradetype = { "long", "short", default "both" };

def timeFrame = getAggregationPeriod();
def lowestAggregation;
def middleAggregation;
def highestAggregation;
def extraHighAggregation;
If timeFrame == AggregationPeriod.MIN {
        lowestAggregation = AggregationPeriod.MIN;
        middleAggregation = AggregationPeriod.TWO_MIN;
        highestAggregation = AggregationPeriod.FIVE_MIN;
        extraHighAggregation = AggregationPeriod.TEN_MIN;
} else if timeFrame == AggregationPeriod.TWO_MIN {
        lowestAggregation = AggregationPeriod.TWO_MIN;
        middleAggregation = AggregationPeriod.FIVE_MIN;
        highestAggregation = AggregationPeriod.TEN_MIN;
        extraHighAggregation = AggregationPeriod.FIFTEEN_MIN;
} else if timeFrame == AggregationPeriod.FIVE_MIN {
        lowestAggregation = AggregationPeriod.FIVE_MIN;
        middleAggregation = AggregationPeriod.TEN_MIN;
        highestAggregation = AggregationPeriod.FIFTEEN_MIN;
        extraHighAggregation = AggregationPeriod.THIRTY_MIN;
} else if timeFrame == AggregationPeriod.TEN_MIN {
        lowestAggregation = AggregationPeriod.TEN_MIN;
        middleAggregation = AggregationPeriod.FIFTEEN_MIN;
        highestAggregation = AggregationPeriod.THIRTY_MIN;
        extraHighAggregation = AggregationPeriod.HOUR;
} else if timeFrame == AggregationPeriod.FIFTEEN_MIN {
        lowestAggregation = AggregationPeriod.FIFTEEN_MIN;
        middleAggregation = AggregationPeriod.THIRTY_MIN;
        highestAggregation = AggregationPeriod.HOUR;
        extraHighAggregation = AggregationPeriod.TWO_HOURS;
} else if timeFrame == AggregationPeriod.THIRTY_MIN {
        lowestAggregation = AggregationPeriod.THIRTY_MIN;
        middleAggregation = AggregationPeriod.HOUR;
        highestAggregation = AggregationPeriod.TWO_HOURS;
        extraHighAggregation = AggregationPeriod.FOUR_HOURS;
} else if timeFrame == AggregationPeriod.HOUR {
        lowestAggregation = AggregationPeriod.HOUR;
        middleAggregation = AggregationPeriod.TWO_HOURS;
        highestAggregation = AggregationPeriod.FOUR_HOURS;
        extraHighAggregation = AggregationPeriod.DAY;
} else if timeFrame == AggregationPeriod.TWO_HOURS {
        lowestAggregation = AggregationPeriod.TWO_HOURS;
        middleAggregation = AggregationPeriod.FOUR_HOURS;
        highestAggregation = AggregationPeriod.DAY;
        extraHighAggregation = AggregationPeriod.TWO_DAYS;
} else if timeFrame == AggregationPeriod.FOUR_HOURS {
        lowestAggregation = AggregationPeriod.FOUR_HOURS;
        middleAggregation = AggregationPeriod.DAY;
        highestAggregation = AggregationPeriod.TWO_DAYS;
        extraHighAggregation = AggregationPeriod.WEEK;
} else if timeFrame == AggregationPeriod.DAY {
        lowestAggregation = AggregationPeriod.DAY;
        middleAggregation = AggregationPeriod.TWO_DAYS;
        highestAggregation = AggregationPeriod.WEEK;
        extraHighAggregation = AggregationPeriod.MONTH;
} else {
        lowestAggregation = AggregationPeriod.TWO_DAYS;
        middleAggregation = AggregationPeriod.WEEK;
        highestAggregation = AggregationPeriod.MONTH;
        extraHighAggregation = AggregationPeriod.YEAR;
}
     
def testTimeFrames = if timeFrame == lowestAggregation and lowestAggregation < middleAggregation and middleAggregation < highestAggregation < extraHighAggregation then 1 else 0;
def CloseAllCondition = if timeFrame <= AggregationPeriod.FIFTEEN_MIN then 0 else if SecondsTillTime(1558) == 0 then 1 else 0;
def EOD = if timeFrame >= AggregationPeriod.FIFTEEN_MIN then 0 else if SecondsTillTime(1558) == 0 and SecondsFromTime(1558) == 0 then 1 else 0;
def Active = if timeFrame >= AggregationPeriod.FIFTEEN_MIN and (SecondsFromTime(1000) > 0 and SecondsTillTime(1550) > 0) then 1 else if (SecondsFromTime(0930) > 0 and SecondsTillTime(1558) > 0) then 1 else 0;

################################################################
##########            Global Variables                 #########
################################################################
# TimePeriodChecks
input timePeriods = { "Two", default "Three", "Four" };

# RSI
input rsiLength = 14;
input rsiAverageType = AverageType.WILDERS;

# Stochastic
input smiKPeriod = 5;
input smiDPeriod = 3;
input smiDontBuyAbove = 100;
input smiDontSellBelow = -100;

# CPMO
input cpmoLength1 = 14;
input cpmoLength2 = 9;
input cpmoSignalLength = 10;

# EMA
input emaPeriodL2 = 8;
input emaPeriodH2 = 14;

################################################################
##########                 RSI                         #########
################################################################
def NetChgAvg = MovingAverage(rsiAverageType, close(period = lowestAggregation) - close(period = lowestAggregation)[1], rsiLength);
def TotChgAvg = MovingAverage(rsiAverageType, AbsValue(close(period = lowestAggregation) - close(period = lowestAggregation)[1]), rsiLength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

################################################################
##########                 SMI                         #########
################################################################
# Stochastic Extra High
def min_low_xh = Lowest(low(period = extraHighAggregation), smiKPeriod);
def max_high_xh = Highest(high(period = extraHighAggregation), smiKPeriod);
def rel_diff_xh = close(period = extraHighAggregation) - (max_high_xh + min_low_xh) / 2;
def diff_xh = max_high_xh - min_low_xh;

def avgrel_xh = ExpAverage(ExpAverage(rel_diff_xh, smiDPeriod), smiDPeriod);
def avgdiff_xh = ExpAverage(ExpAverage(diff_xh, smiDPeriod), smiDPeriod);

def SMI_xh = if avgdiff_xh != 0 then avgrel_xh / (avgdiff_xh / 2) * 100 else 0;
def AvgSMI_xh = ExpAverage(SMI_xh, smiDPeriod);

# Stochastic Highest
def min_low_h = Lowest(low(period = highestAggregation), smiKPeriod);
def max_high_h = Highest(high(period = highestAggregation), smiKPeriod);
def rel_diff_h = close(period = highestAggregation) - (max_high_h + min_low_h) / 2;
def diff_h = max_high_h - min_low_h;

def avgrel_h = ExpAverage(ExpAverage(rel_diff_h, smiDPeriod), smiDPeriod);
def avgdiff_h = ExpAverage(ExpAverage(diff_h, smiDPeriod), smiDPeriod);

def SMI_h = if avgdiff_h != 0 then avgrel_h / (avgdiff_h / 2) * 100 else 0;
def AvgSMI_h = ExpAverage(SMI_h, smiDPeriod);

# Stochastic Middle
def min_low_m = Lowest(low(period = middleAggregation), smiKPeriod);
def max_high_m = Highest(high(period = middleAggregation), smiKPeriod);
def rel_diff_m = close(period = middleAggregation) - (max_high_m + min_low_m) / 2;
def diff_m = max_high_m - min_low_m;

def avgrel_m = ExpAverage(ExpAverage(rel_diff_m, smiDPeriod), smiDPeriod);
def avgdiff_m = ExpAverage(ExpAverage(diff_m, smiDPeriod), smiDPeriod);

def SMI_m = if avgdiff_m != 0 then avgrel_m / (avgdiff_m / 2) * 100 else 0;
def AvgSMI_m = ExpAverage(SMI_m, smiDPeriod);

# Stochastic Lowest
def min_low_l = Lowest(low(period = lowestAggregation), smiKPeriod);
def max_high_l = Highest(high(period = lowestAggregation), smiKPeriod);
def rel_diff_l = close(period = lowestAggregation) - (max_high_l + min_low_l) / 2;
def diff_l = max_high_l - min_low_l;

def avgrel_l = ExpAverage(ExpAverage(rel_diff_l, smiDPeriod), smiDPeriod);
def avgdiff_l = ExpAverage(ExpAverage(diff_l, smiDPeriod), smiDPeriod);

def SMI_l = if avgdiff_l != 0 then avgrel_l / (avgdiff_l / 2) * 100 else 0;
def AvgSMI_l = ExpAverage(SMI_l, smiDPeriod);
################################################################
##########                 CPMO                      ###########
################################################################
def PrimaryPMO = reference PMO(price = close(period = middleAggregation), length1 = cpmoLength1, length2 = cpmoLength2);
def PrimarySignalLine = ExpAverage(PrimaryPMO, cpmoSignalLength);

################################################################
##########                 EMA                       ###########
################################################################

def emaValueL2 = ExpAverage(close(period = lowestAggregation), length = EmaPeriodL2);
def emaValueH2 = ExpAverage(close(period = lowestAggregation), length = EmaPeriodH2);

#################################################################
############          SCAN Variables                    #########
#################################################################
plot Uptrend;
plot DownTrend;

if timePeriods == timePeriods.Two {
    UpTrend = if SMI_m > AvgSMI_m and SMI_l > AvgSMI_l then 1 else 0;
    DownTrend = if SMI_m < AvgSMI_m and SMI_l < AvgSMI_l then 1 else 0;
} else if timePeriods == timePeriods.Three {
    UpTrend = if SMI_h > AvgSMI_h and SMI_m > AvgSMI_m and SMI_l > AvgSMI_l then 1 else 0;
    DownTrend = if SMI_h < AvgSMI_h and SMI_m < AvgSMI_m and SMI_l < AvgSMI_l then 1 else 0;
} else {
    UpTrend = if SMI_xh > AvgSMI_xh and SMI_h > AvgSMI_h and SMI_m > AvgSMI_m and SMI_l > AvgSMI_l then 1 else 0;
    DownTrend = if SMI_xh < AvgSMI_xh and SMI_h < AvgSMI_h and SMI_m < AvgSMI_m and SMI_l < AvgSMI_l then 1 else 0;
}

plot ExitUpTrend;
plot ExitDownTrend;

If RSI >= 70 or RSI <= 30{
    ExitUpTrend = if (primaryPMO < primarySignalLine or emavalueL2 < emavalueH2) and SMI_l < avgSMI_l then 1 else 0;
    ExitDownTrend = if (primaryPMO > primarySignalLine or emavalueL2 > emavalueH2) and SMI_l > avgSMI_l then 1 else 0;
} else {
    ExitUpTrend = if SMI_m < avgSMI_m and SMI_l < avgSMI_l then 1 else 0;
    ExitDownTrend = if SMI_m > avgSMI_m and SMI_l > avgSMI_l then 1 else 0;
}

def LongBuy = if UpTrend == 1 and UpTrend[1] == 0 then 1 else 0;
def LongExit = if ExitUpTrend == 1 and ExitUpTrend[1] == 0 then 1 else 0;

def ShortSell = if DownTrend == 1 and DownTrend[1] == 0 then 1 else 0;
def ShortExit = if ExitDownTrend == 1 and ExitDownTrend[1] == 0 then 1 else 0;

UpTrend.Hide();
DownTrend.Hide();
ExitUpTrend.Hide();
ExitDownTrend.Hide();

#################################################################
############          NOTIFICATIONS                     #########
#################################################################
AddLabel(yes, if Uptrend == 1 and ExitUpTrend == 0 then "::Go Long::" else if DownTrend == 1 and ExitDownTrend == 0 then "::Go Short::" else "::Do Nothing::", if Uptrend == 1 and ExitUpTrend == 0 then Color.CYAN else if DownTrend == 1 and ExitDownTrend == 0 then Color.MAGENTA else Color.GRAY);

def bar = BarNumber();

def longSignal = if Uptrend == 1 and ExitUpTrend == 0 then 1 else 0;
Alert(longSignal == 1, "MTF Uptrend", Alert.BAR, Sound.Ring);

def shortSignal = if DownTrend == 1 and ExitDownTrend == 0 then 1 else 0;
Alert(shortSignal == 1, "MTF Downtrend", Alert.BAR, Sound.Ding);

plot upArrow = if (LongBuy == 1 and (tradetype == tradetype.long or tradetype == tradetype.both)) or (ShortExit == 1 and (tradetype == tradetype.short or tradetype == tradetype.both)) and Active then low else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
upArrow.SetDefaultColor(Color.CYAN);

plot downArrow = if (ShortSell == 1 and (tradetype == tradetype.short or tradetype == tradetype.both)) or (LongExit == 1 and (tradetype == tradetype.long or tradetype == tradetype.both)) and Active then low else Double.NaN;
downArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
downArrow.SetDefaultColor(Color.MAGENTA);

################################################################
##########                 BUY                       ###########
################################################################

AddOrder(OrderType.BUY_AUTO, LongBuy == 1 and (tradetype == tradetype.long or tradetype == tradetype.both) and Active and testTimeFrames, price = close, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "BUY");
AddOrder(OrderType.SELL_TO_CLOSE, LongExit == 1 and (tradetype == tradetype.long or tradetype == tradetype.both) and testTimeFrames, price = open[-1], tickcolor = Color.MAGENTA, arrowcolor = Color.MAGENTA, name = "Sell To Close");
AddOrder(OrderType.SELL_TO_CLOSE, EOD or CloseAllCondition and testTimeFrames, price = close, tickcolor = Color.MAGENTA, arrowcolor = Color.MAGENTA, name = "SELL EOD");

################################################################
##########                 SELL                      ###########
################################################################

AddOrder(OrderType.SELL_AUTO, ShortSell == 1 and (tradetype == tradetype.short or tradetype == tradetype.both) and Active and testTimeFrames, price = close, tickcolor = Color.MAGENTA, arrowcolor = Color.MAGENTA, name = "SELL");
AddOrder(OrderType.BUY_TO_CLOSE, ShortExit == 1 and (tradetype == tradetype.short or tradetype == tradetype.both) and testTimeFrames, price = open[-1], tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "Buy To Close");
AddOrder(OrderType.BUY_TO_CLOSE, EOD or CloseAllCondition and testTimeFrames, price = close, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "BUY EOD");
;

http://tos.mx/5kh7Ppr

Study Version

Cyan: Buy Long
White: Exit Long
Magenta: Sell Short
White: Exit Short

Ruby:
################################################################
##########            Initial Config                   #########
################################################################
input tradetype = { "long", "short", default "both" };

def timeFrame = getAggregationPeriod();
def lowestAggregation;
def middleAggregation;
def highestAggregation;
def extraHighAggregation;
If timeFrame == AggregationPeriod.MIN {
        lowestAggregation = AggregationPeriod.MIN;
        middleAggregation = AggregationPeriod.TWO_MIN;
        highestAggregation = AggregationPeriod.FIVE_MIN;
        extraHighAggregation = AggregationPeriod.TEN_MIN;
} else if timeFrame == AggregationPeriod.TWO_MIN {
        lowestAggregation = AggregationPeriod.TWO_MIN;
        middleAggregation = AggregationPeriod.FIVE_MIN;
        highestAggregation = AggregationPeriod.TEN_MIN;
        extraHighAggregation = AggregationPeriod.FIFTEEN_MIN;
} else if timeFrame == AggregationPeriod.FIVE_MIN {
        lowestAggregation = AggregationPeriod.FIVE_MIN;
        middleAggregation = AggregationPeriod.TEN_MIN;
        highestAggregation = AggregationPeriod.FIFTEEN_MIN;
        extraHighAggregation = AggregationPeriod.THIRTY_MIN;
} else if timeFrame == AggregationPeriod.TEN_MIN {
        lowestAggregation = AggregationPeriod.TEN_MIN;
        middleAggregation = AggregationPeriod.FIFTEEN_MIN;
        highestAggregation = AggregationPeriod.THIRTY_MIN;
        extraHighAggregation = AggregationPeriod.HOUR;
} else if timeFrame == AggregationPeriod.FIFTEEN_MIN {
        lowestAggregation = AggregationPeriod.FIFTEEN_MIN;
        middleAggregation = AggregationPeriod.THIRTY_MIN;
        highestAggregation = AggregationPeriod.HOUR;
        extraHighAggregation = AggregationPeriod.TWO_HOURS;
} else if timeFrame == AggregationPeriod.THIRTY_MIN {
        lowestAggregation = AggregationPeriod.THIRTY_MIN;
        middleAggregation = AggregationPeriod.HOUR;
        highestAggregation = AggregationPeriod.TWO_HOURS;
        extraHighAggregation = AggregationPeriod.FOUR_HOURS;
} else if timeFrame == AggregationPeriod.HOUR {
        lowestAggregation = AggregationPeriod.HOUR;
        middleAggregation = AggregationPeriod.TWO_HOURS;
        highestAggregation = AggregationPeriod.FOUR_HOURS;
        extraHighAggregation = AggregationPeriod.DAY;
} else if timeFrame == AggregationPeriod.TWO_HOURS {
        lowestAggregation = AggregationPeriod.TWO_HOURS;
        middleAggregation = AggregationPeriod.FOUR_HOURS;
        highestAggregation = AggregationPeriod.DAY;
        extraHighAggregation = AggregationPeriod.TWO_DAYS;
} else if timeFrame == AggregationPeriod.FOUR_HOURS {
        lowestAggregation = AggregationPeriod.FOUR_HOURS;
        middleAggregation = AggregationPeriod.DAY;
        highestAggregation = AggregationPeriod.TWO_DAYS;
        extraHighAggregation = AggregationPeriod.WEEK;
} else if timeFrame == AggregationPeriod.DAY {
        lowestAggregation = AggregationPeriod.DAY;
        middleAggregation = AggregationPeriod.TWO_DAYS;
        highestAggregation = AggregationPeriod.WEEK;
        extraHighAggregation = AggregationPeriod.MONTH;
} else {
        lowestAggregation = AggregationPeriod.TWO_DAYS;
        middleAggregation = AggregationPeriod.WEEK;
        highestAggregation = AggregationPeriod.MONTH;
        extraHighAggregation = AggregationPeriod.YEAR;
}
     
def testTimeFrames = if timeFrame == lowestAggregation and lowestAggregation < middleAggregation and middleAggregation < highestAggregation < extraHighAggregation then 1 else 0;
def CloseAllCondition = if timeFrame <= AggregationPeriod.FIFTEEN_MIN then 0 else if SecondsTillTime(1558) == 0 then 1 else 0;
def EOD = if timeFrame >= AggregationPeriod.FIFTEEN_MIN then 0 else if SecondsTillTime(1558) == 0 and SecondsFromTime(1558) == 0 then 1 else 0;
def Active = if timeFrame >= AggregationPeriod.FIFTEEN_MIN and (SecondsFromTime(1000) > 0 and SecondsTillTime(1550) > 0) then 1 else if (SecondsFromTime(0930) > 0 and SecondsTillTime(1558) > 0) then 1 else 0;

################################################################
##########            Global Variables                 #########
################################################################
# TimePeriodChecks
input timePeriods = { "Two", default "Three", "Four" };

# RSI
input rsiLength = 14;
input rsiAverageType = AverageType.WILDERS;

# Stochastic
input smiKPeriod = 5;
input smiDPeriod = 3;
input smiDontBuyAbove = 100;
input smiDontSellBelow = -100;

# CPMO
input cpmoLength1 = 14;
input cpmoLength2 = 9;
input cpmoSignalLength = 10;

# EMA
input emaPeriodL2 = 8;
input emaPeriodH2 = 14;

################################################################
##########                 RSI                         #########
################################################################
def NetChgAvg = MovingAverage(rsiAverageType, close(period = lowestAggregation) - close(period = lowestAggregation)[1], rsiLength);
def TotChgAvg = MovingAverage(rsiAverageType, AbsValue(close(period = lowestAggregation) - close(period = lowestAggregation)[1]), rsiLength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

################################################################
##########                 SMI                         #########
################################################################
# Stochastic Extra High
def min_low_xh = Lowest(low(period = extraHighAggregation), smiKPeriod);
def max_high_xh = Highest(high(period = extraHighAggregation), smiKPeriod);
def rel_diff_xh = close(period = extraHighAggregation) - (max_high_xh + min_low_xh) / 2;
def diff_xh = max_high_xh - min_low_xh;

def avgrel_xh = ExpAverage(ExpAverage(rel_diff_xh, smiDPeriod), smiDPeriod);
def avgdiff_xh = ExpAverage(ExpAverage(diff_xh, smiDPeriod), smiDPeriod);

def SMI_xh = if avgdiff_xh != 0 then avgrel_xh / (avgdiff_xh / 2) * 100 else 0;
def AvgSMI_xh = ExpAverage(SMI_xh, smiDPeriod);

# Stochastic Highest
def min_low_h = Lowest(low(period = highestAggregation), smiKPeriod);
def max_high_h = Highest(high(period = highestAggregation), smiKPeriod);
def rel_diff_h = close(period = highestAggregation) - (max_high_h + min_low_h) / 2;
def diff_h = max_high_h - min_low_h;

def avgrel_h = ExpAverage(ExpAverage(rel_diff_h, smiDPeriod), smiDPeriod);
def avgdiff_h = ExpAverage(ExpAverage(diff_h, smiDPeriod), smiDPeriod);

def SMI_h = if avgdiff_h != 0 then avgrel_h / (avgdiff_h / 2) * 100 else 0;
def AvgSMI_h = ExpAverage(SMI_h, smiDPeriod);

# Stochastic Middle
def min_low_m = Lowest(low(period = middleAggregation), smiKPeriod);
def max_high_m = Highest(high(period = middleAggregation), smiKPeriod);
def rel_diff_m = close(period = middleAggregation) - (max_high_m + min_low_m) / 2;
def diff_m = max_high_m - min_low_m;

def avgrel_m = ExpAverage(ExpAverage(rel_diff_m, smiDPeriod), smiDPeriod);
def avgdiff_m = ExpAverage(ExpAverage(diff_m, smiDPeriod), smiDPeriod);

def SMI_m = if avgdiff_m != 0 then avgrel_m / (avgdiff_m / 2) * 100 else 0;
def AvgSMI_m = ExpAverage(SMI_m, smiDPeriod);

# Stochastic Lowest
def min_low_l = Lowest(low(period = lowestAggregation), smiKPeriod);
def max_high_l = Highest(high(period = lowestAggregation), smiKPeriod);
def rel_diff_l = close(period = lowestAggregation) - (max_high_l + min_low_l) / 2;
def diff_l = max_high_l - min_low_l;

def avgrel_l = ExpAverage(ExpAverage(rel_diff_l, smiDPeriod), smiDPeriod);
def avgdiff_l = ExpAverage(ExpAverage(diff_l, smiDPeriod), smiDPeriod);

def SMI_l = if avgdiff_l != 0 then avgrel_l / (avgdiff_l / 2) * 100 else 0;
def AvgSMI_l = ExpAverage(SMI_l, smiDPeriod);
################################################################
##########                 CPMO                      ###########
################################################################
def PrimaryPMO = reference PMO(price = close(period = middleAggregation), length1 = cpmoLength1, length2 = cpmoLength2);
def PrimarySignalLine = ExpAverage(PrimaryPMO, cpmoSignalLength);

################################################################
##########                 EMA                       ###########
################################################################

def emaValueL2 = ExpAverage(close(period = lowestAggregation), length = EmaPeriodL2);
def emaValueH2 = ExpAverage(close(period = lowestAggregation), length = EmaPeriodH2);

#################################################################
############          SCAN Variables                    #########
#################################################################
plot Uptrend;
plot DownTrend;

if timePeriods == timePeriods.Two {
    UpTrend = if SMI_m > AvgSMI_m and SMI_l > AvgSMI_l then 1 else 0;
    DownTrend = if SMI_m < AvgSMI_m and SMI_l < AvgSMI_l then 1 else 0;
} else if timePeriods == timePeriods.Three {
    UpTrend = if SMI_h > AvgSMI_h and SMI_m > AvgSMI_m and SMI_l > AvgSMI_l then 1 else 0;
    DownTrend = if SMI_h < AvgSMI_h and SMI_m < AvgSMI_m and SMI_l < AvgSMI_l then 1 else 0;
} else {
    UpTrend = if SMI_xh > AvgSMI_xh and SMI_h > AvgSMI_h and SMI_m > AvgSMI_m and SMI_l > AvgSMI_l then 1 else 0;
    DownTrend = if SMI_xh < AvgSMI_xh and SMI_h < AvgSMI_h and SMI_m < AvgSMI_m and SMI_l < AvgSMI_l then 1 else 0;
}

plot ExitUpTrend;
plot ExitDownTrend;

If RSI >= 70 or RSI <= 30{
    ExitUpTrend = if (primaryPMO < primarySignalLine or emavalueL2 < emavalueH2) and SMI_l < avgSMI_l then 1 else 0;
    ExitDownTrend = if (primaryPMO > primarySignalLine or emavalueL2 > emavalueH2) and SMI_l > avgSMI_l then 1 else 0;
} else {
    ExitUpTrend = if SMI_m < avgSMI_m and SMI_l < avgSMI_l then 1 else 0;
    ExitDownTrend = if SMI_m > avgSMI_m and SMI_l > avgSMI_l then 1 else 0;
}

def LongBuy = if UpTrend == 1 and UpTrend[1] == 0 then 1 else 0;
def LongExit = if ExitUpTrend == 1 and ExitUpTrend[1] == 0 then 1 else 0;

def ShortSell = if DownTrend == 1 and DownTrend[1] == 0 then 1 else 0;
def ShortExit = if ExitDownTrend == 1 and ExitDownTrend[1] == 0 then 1 else 0;

UpTrend.Hide();
DownTrend.Hide();
ExitUpTrend.Hide();
ExitDownTrend.Hide();

#################################################################
############          NOTIFICATIONS                     #########
#################################################################
AddLabel(yes, if Uptrend == 1 and ExitUpTrend == 0 then "::Go Long::" else if DownTrend == 1 and ExitDownTrend == 0 then "::Go Short::" else "::Do Nothing::", if Uptrend == 1 and ExitUpTrend == 0 then Color.CYAN else if DownTrend == 1 and ExitDownTrend == 0 then Color.MAGENTA else Color.GRAY);

def bar = BarNumber();

def longSignal = if Uptrend == 1 and ExitUpTrend == 0 then 1 else 0;
Alert(longSignal == 1, "MTF Uptrend", Alert.BAR, Sound.Ring);

def shortSignal = if DownTrend == 1 and ExitDownTrend == 0 then 1 else 0;
Alert(shortSignal == 1, "MTF Downtrend", Alert.BAR, Sound.Ding);

def backscan_period = 200;

plot UpArrow = if upTrend and ((fold i1 = 1 to backscan_period with a while downTrend[i1] != 1 do i1) < (fold i2 = 1 to backscan_period with b while upTrend[i2] != 1 do i2)) or ((fold i3 = 1 to backscan_period with c while exitUpTrend[i3] != 1 do i3) < (fold i4 = 1 to backscan_period with d while upTrend[i4] != 1 do i4)) or ((fold i5 = 1 to backscan_period with e while exitDownTrend[i5] != 1 do i5) < (fold i6 = 1 to backscan_period with f while upTrend[i6] != 1 do i6)) then 1 else 0;

plot DownArrow = if downTrend and ((fold i7 = 1 to backscan_period with g while upTrend[i7] != 1 do i7) < (fold i8 = 1 to backscan_period with h while downTrend[i8] != 1 do i8)) or ((fold i9 = 1 to backscan_period with i while exitUpTrend[i9] != 1 do i9) < (fold i10 = 1 to backscan_period with j while downTrend[i10] != 1 do i10)) or ((fold i11 = 1 to backscan_period with k while exitDownTrend[i11] != 1 do i11) < (fold i12 = 1 to backscan_period with l while downTrend[i12] != 1 do i12)) then 1 else 0;

plot UpExit = if exitUpTrend and ((fold i13 = 1 to backscan_period with m while upTrend[i13] != 1 do i13) < (fold i14 = 1 to backscan_period with n while exitUpTrend[i14] != 1 do i14)) or ((fold i15 = 1 to backscan_period with o while exitDownTrend[i15] != 1 do i15) < (fold i16 = 1 to backscan_period with p while exitUpTrend[i16] != 1 do i16)) or ((fold i17 = 1 to backscan_period with q while downTrend[i17] != 1 do i17) < (fold i18 = 1 to backscan_period with r while exitUpTrend[i18] != 1 do i18)) then 1 else 0;

plot DownExit = if exitDownTrend and ((fold i19 = 1 to backscan_period with s while upTrend[i19] != 1 do i19) < (fold i20 = 1 to backscan_period with t while exitDownTrend[i20] != 1 do i20)) or ((fold i21 = 1 to backscan_period with u while exitUpTrend[i21] != 1 do i21) < (fold i22 = 1 to backscan_period with v while exitDownTrend[i22] != 1 do i22)) or ((fold i23 = 1 to backscan_period with w while downTrend[i23] != 1 do i23) < (fold i24 = 1 to backscan_period with x while exitDownTrend[i24] != 1 do i24)) then 1 else 0;

plot Signal_Up = if upTrend and UpArrow then low else Double.NaN;
Signal_Up.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Signal_Up.SetDefaultColor(Color.CYAN);
Signal_Up.SetLineWeight(3);
plot Signal_Dn = if downTrend and DownArrow then high else Double.NaN;
Signal_Dn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Signal_Dn.SetDefaultColor(Color.MAGENTA);
Signal_Dn.SetLineWeight(3);
plot Signal_Exit_Up = if exitUpTrend and UpExit then high else Double.NaN;
Signal_Exit_Up.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Signal_Exit_Up.SetDefaultColor(Color.WHITE);
Signal_Exit_Up.SetLineWeight(3);
plot Signal_Exit_Dn = if exitDownTrend and DownExit then low else Double.NaN;
Signal_Exit_Dn.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Signal_Exit_Dn.SetDefaultColor(Color.WHITE);
Signal_Exit_Dn.SetLineWeight(3);

http://tos.mx/gUFWqjZ
 
Last edited:
Can you please share tos link .
Thank you for sharing you strategy
Here's a scan as well.
http://tos.mx/K9KSUPO

It's configured for a 5m time frame (bullish) which you can adjust accordingly to whatever time frame you like to trade. Ex. if you want to trade the 15m time frame then change the study period's as such:

15m > 1h
10m > 30m
5m > 15m
5m > 15M

If you want to trade the short side then reverse the comparison operators on the studies from greater than to less than and from crosses above to crosses below.

What I'll typically do if I'm playing a 1m time frame is I'll scan for a 2m time frame and then wait for the 1m to signal. That way if I miss my exit (since I play short term options) it hopefully buys me more time to get out.
 
Last edited:

Thoward604

New member
@Drmoh1800 I just made a couple of changes to the Strategy that so far is producing better results. If you've already downloaded it you'll want to download the new one (I edited the post above with the link and the original code post)
@Mightymorphinchris .. thanks for sharing your strategy.. i plan on doing some back testing.
im trying to understand how best to leverage.. is it more accurate on the long setups than short.. im using the day time frame and seeing some go longs at the very hight of the chart.. does the go long tie back to today's candle or the last candle with a blue arrow..looking at ticker symbol NVO
 
@Mightymorphinchris .. thanks for sharing your strategy.. i plan on doing some back testing.
im trying to understand how best to leverage.. is it more accurate on the long setups than short.. im using the day time frame and seeing some go longs at the very hight of the chart.. does the go long tie back to today's candle or the last candle with a blue arrow..looking at ticker symbol NVO

I personally use it on 1m and 2m timeframes and the numbers i ran by taking 90 days worth of data led to between 70-78% accuracy (again with repainting though which definitely has an effect on live trading). I found the higher time frames personally led to a lower w/l ratio UNLESS i set the strategy to "Short" only (as opposed to both). The last 6 months, shorts have prevailed. Prior to 6 months ago, longs were winning.

The blue arrow will appear prior to confirmation of the other time frames. I personally use it as a get ready. Sometimes it falls flat and other times it provides a perfect entry.

I'm currently running numbers against having the lower time frame just be based on the Stochastic Momentum Index vs the CPMO which I consider confirmation. As stated initially, even if my w/l ratio drops.. if my total profit increases drastically that's more important. As I'd rather have my gains be big and my losses be quick to exit even if there are more losing trades.
 
Here's what i'm doing in Excel to calculate w/l percentage
aVyRa8x.png



1. Right click > Show Report
2. Export as html
3. Open html export in browser and drag and select the whole table (grabbing the column headers as shown above)
4. Paste into Excel.
5. Calculation tabs are as such:
L2 =SUMPRODUCT((H2:H1000>0)*(H2:H1000))/SUMPRODUCT(ABS(H2:H1000))
M2 =-SUMPRODUCT((H2:H1000>0)*(H2:H1000))/SUMPRODUCT(ABS(H2:H1000))
N2 = =SUM(H2:H1000)

***** I have also once again updated the strategy to create great Total Profits on most tickers that I watch with high volume. The code and links have been updated.

***** I fully welcome any and all improvements on this strategy that are suggested
 
Last edited:

JoeSD

Member
VIP
@MightyMorphin - I can't seem to get the indicator to show anything on any of my charts??? I even used the link you provided and nothing? Not sure what's up...

Thanks.


Joe
 

JoeSD

Member
VIP
@MightyMorphin - I can't seem to get the indicator to show anything on any of my charts??? I even used the link you provided and nothing? Not sure what's up...

Thanks.


Joe
I figured it out. I had renamed it and was looking in studies, but it was in strategies. thanks. Joe
 

Drmoh1800

Member
@Drmoh1800 I just made a couple of changes to the Strategy that so far is producing better results. If you've already downloaded it you'll want to download the new one (I edited the post above with the link and the original code post)
thank you again i upgraded the study
i started trading option recently
is there alert when the buy or sell signal triggered?
the other question you are trading weekly option for this strategy
what is your method choosing your stick price ?
thank you
 
thank you again i upgraded the study
i started trading option recently
is there alert when the buy or sell signal triggered?
the other question you are trading weekly option for this strategy
what is your method choosing your stick price ?
thank you
There are alert notifications in the strategy (ring for uptrend, bell for downtrend).

None of this being financial advice and just my personal opinions, trade at your own risk*

Be cautious when trading short term options. In my opinion it would probably be safer to start with shares or even just pretend to make the trades on the strategy to get a feel for it and see if it works out, that way you limit your risk.

If you miss your exit or the trade pivots the other way on you, your money can burn up very quickly due to theta being greater on close to expiration options. Obviously the opposite can happen as well if the trade goes in your favor. High risk high reward scenario.

As for me, I always look for small spreads (the difference between the bid and the ask), a good amount of volume and open interest, and typically just out of the money. If the spread is wide or volume low I will pass on the trade or trade shares.
 

Drmoh1800

Member
Thank you for sharing.
I used to trade 5 minutes brake out with confirmation crossing 9 ema . After looking to hourly chart confirming trend .
The result was 50% success .more success rate in bull market 80%
I had same problem losing the exit
. I used to sell at bid price it was bad idea
I used trail stop that eat all my wining .
what is you exiting strategy? Regarding placing the order . Market or limit orders bid or ask ?
i understand the risk . I know i am not trading the price it self i am trading other people greed and fear .
thank you 😊
 

rad14733

Well-known member
VIP
@Drmoh1800 It sounds like you are scalping or day trading options, which is what I do... From experience, you are far better off setting a predetermined profit limit that you are fairly certain momentum will allow you to attain and not worrying about leaving money on the table... Watching and waiting for maximum profit can end up setting you up for the dreaded trying to catch a falling knife scenario where profit quickly turns into a loss... As much as I hate saying it, I've been there far too many times myself so I speak from experience... Another option is to buy multiple contracts and scale out as price is rising, locking in profit, and maybe let one or a few contracts ride up for potentially maximum profit... Food for thought...
 
Thank you for sharing.
I used to trade 5 minutes brake out with confirmation crossing 9 ema . After looking to hourly chart confirming trend .
The result was 50% success .more success rate in bull market 80%
I had same problem losing the exit
. I used to sell at bid price it was bad idea
I used trail stop that eat all my wining .
what is you exiting strategy? Regarding placing the order . Market or limit orders bid or ask ?
i understand the risk . I know i am not trading the price it self i am trading other people greed and fear .
thank you 😊
I agree with @rad14733. I will typically shoot for 10-15% profit when trading before 11AM EST and after that i usually get out 5-10% profit. Just looking for many quick wins. I try to cut my losses early but for that I typically exit based on indicators and the first sign of reversal I get it out. As @rad14733 stated, its better to leave money on the table then end up missing your exit and losing a lot of money (it happens quick with short term options) of which I too have the unfortunate privilege of experience a lot.
 
I tested out a change today and so far i'm producing about a 5% greater win rate in backtesting. This other version is replacing the cpmo crossing the signal on the low time frame with SMI crossing the AvgSMI on the low time frame. It produces earlier entries and exits. Again though, you have to be prepared to cut losses early as it will repaint.


Ruby:
################################################################
##########            Initial Config                   #########
################################################################
input tradetype = { "long", "short", default "both" };

def timeFrame = getAggregationPeriod();
def lowestAggregation;
def middleAggregation;
def highestAggregation;
If timeFrame == AggregationPeriod.MIN {
        lowestAggregation = AggregationPeriod.MIN;
        middleAggregation = AggregationPeriod.TWO_MIN;
        highestAggregation = AggregationPeriod.FIVE_MIN;
} else if timeFrame == AggregationPeriod.TWO_MIN {
        lowestAggregation = AggregationPeriod.TWO_MIN;
        middleAggregation = AggregationPeriod.FIVE_MIN;
        highestAggregation = AggregationPeriod.TEN_MIN;
} else if timeFrame == AggregationPeriod.FIVE_MIN {
        lowestAggregation = AggregationPeriod.FIVE_MIN;
        middleAggregation = AggregationPeriod.TEN_MIN;
        highestAggregation = AggregationPeriod.FIFTEEN_MIN;
} else if timeFrame == AggregationPeriod.TEN_MIN {
        lowestAggregation = AggregationPeriod.TEN_MIN;
        middleAggregation = AggregationPeriod.FIFTEEN_MIN;
        highestAggregation = AggregationPeriod.THIRTY_MIN;
} else if timeFrame == AggregationPeriod.FIFTEEN_MIN {
        lowestAggregation = AggregationPeriod.FIFTEEN_MIN;
        middleAggregation = AggregationPeriod.THIRTY_MIN;
        highestAggregation = AggregationPeriod.HOUR;
} else if timeFrame == AggregationPeriod.THIRTY_MIN {
        lowestAggregation = AggregationPeriod.THIRTY_MIN;
        middleAggregation = AggregationPeriod.HOUR;
        highestAggregation = AggregationPeriod.TWO_HOURS;
} else if timeFrame == AggregationPeriod.HOUR {
        lowestAggregation = AggregationPeriod.HOUR;
        middleAggregation = AggregationPeriod.TWO_HOURS;
        highestAggregation = AggregationPeriod.FOUR_HOURS;
} else if timeFrame == AggregationPeriod.TWO_HOURS {
        lowestAggregation = AggregationPeriod.TWO_HOURS;
        middleAggregation = AggregationPeriod.FOUR_HOURS;
        highestAggregation = AggregationPeriod.TWO_DAYS;
} else if timeFrame == AggregationPeriod.FOUR_HOURS {
        lowestAggregation = AggregationPeriod.FOUR_HOURS;
        middleAggregation = AggregationPeriod.DAY;
        highestAggregation = AggregationPeriod.TWO_DAYS;
} else if timeFrame == AggregationPeriod.DAY {
        lowestAggregation = AggregationPeriod.DAY;
        middleAggregation = AggregationPeriod.TWO_DAYS;
        highestAggregation = AggregationPeriod.WEEK;
} else {
    lowestAggregation = AggregationPeriod.TWO_DAYS;   
    middleAggregation = AggregationPeriod.WEEK;
    highestAggregation = AggregationPeriod.MONTH;
}
        
def testTimeFrames = if timeFrame == lowestAggregation and lowestAggregation < middleAggregation and middleAggregation < highestAggregation then 1 else 0;
def CloseAllCondition = if timeFrame <= AggregationPeriod.FIFTEEN_MIN then 0 else if SecondsTillTime(1558) == 0 then 1 else 0;
def EOD = if timeFrame >= AggregationPeriod.FIFTEEN_MIN then 0 else if SecondsTillTime(1558) == 0 and SecondsFromTime(1558) == 0 then 1 else 0;
def Active = if timeFrame >= AggregationPeriod.FIFTEEN_MIN and (SecondsFromTime(1000) > 0 and SecondsTillTime(1550) > 0) then 1 else if (SecondsFromTime(0930) > 0 and SecondsTillTime(1558) > 0) then 1 else 0;

################################################################
##########            Global Variables                 #########
################################################################
# RSI
input rsiLength = 14;
input rsiAverageType = AverageType.WILDERS;

# Stochastic
input smiKPeriod = 5;
input smiDPeriod = 3;
input smiDontBuyAbove = 100;
input smiDontSellBelow = -100;

# CPMO
input cpmoLength1 = 14;
input cpmoLength2 = 9;
input cpmoSignalLength = 10;

# EMA
input emaPeriodL2 = 8;
input emaPeriodH2 = 14;

################################################################
##########                 RSI                         #########
################################################################
def NetChgAvg = MovingAverage(rsiAverageType, close(period = lowestAggregation) - close(period = lowestAggregation)[1], rsiLength);
def TotChgAvg = MovingAverage(rsiAverageType, AbsValue(close(period = lowestAggregation) - close(period = lowestAggregation)[1]), rsiLength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

################################################################
##########                 SMI                         #########
################################################################
# Stochastic Highest
def min_low_h = Lowest(low(period = highestAggregation), smiKPeriod);
def max_high_h = Highest(high(period = highestAggregation), smiKPeriod);
def rel_diff_h = close(period = highestAggregation) - (max_high_h + min_low_h) / 2;
def diff_h = max_high_h - min_low_h;

def avgrel_h = ExpAverage(ExpAverage(rel_diff_h, smiDPeriod), smiDPeriod);
def avgdiff_h = ExpAverage(ExpAverage(diff_h, smiDPeriod), smiDPeriod);

def SMI_h = if avgdiff_h != 0 then avgrel_h / (avgdiff_h / 2) * 100 else 0;
def AvgSMI_h = ExpAverage(SMI_h, smiDPeriod);

# Stochastic Middle
def min_low_m = Lowest(low(period = middleAggregation), smiKPeriod);
def max_high_m = Highest(high(period = middleAggregation), smiKPeriod);
def rel_diff_m = close(period = middleAggregation) - (max_high_m + min_low_m) / 2;
def diff_m = max_high_m - min_low_m;

def avgrel_m = ExpAverage(ExpAverage(rel_diff_m, smiDPeriod), smiDPeriod);
def avgdiff_m = ExpAverage(ExpAverage(diff_m, smiDPeriod), smiDPeriod);

def SMI_m = if avgdiff_m != 0 then avgrel_m / (avgdiff_m / 2) * 100 else 0;
def AvgSMI_m = ExpAverage(SMI_m, smiDPeriod);

# Stochastic Lowest
def min_low_l = Lowest(low(period = lowestAggregation), smiKPeriod);
def max_high_l = Highest(high(period = lowestAggregation), smiKPeriod);
def rel_diff_l = close(period = lowestAggregation) - (max_high_l + min_low_l) / 2;
def diff_l = max_high_l - min_low_l;

def avgrel_l = ExpAverage(ExpAverage(rel_diff_l, smiDPeriod), smiDPeriod);
def avgdiff_l = ExpAverage(ExpAverage(diff_l, smiDPeriod), smiDPeriod);

def SMI_l = if avgdiff_l != 0 then avgrel_l / (avgdiff_l / 2) * 100 else 0;
def AvgSMI_l = ExpAverage(SMI_l, smiDPeriod);
################################################################
##########                 CPMO                      ###########
################################################################
def PrimaryPMO_h = reference PMO(price = close(period = middleAggregation), length1 = cpmoLength1, length2 = cpmoLength2);
def PrimarySignalLine_h = ExpAverage(PrimaryPMO_h, cpmoSignalLength);

################################################################
##########                 EMA                       ###########
################################################################

def emaValueL2 = ExpAverage(close(period = lowestAggregation), length = EmaPeriodL2);
def emaValueH2 = ExpAverage(close(period = lowestAggregation), length = EmaPeriodH2);

#################################################################
############          SCAN Variables                    #########
#################################################################
plot Uptrend;
plot DownTrend;

UpTrend = if SMI_h > AvgSMI_h and SMI_m > AvgSMI_m and SMI_l > AvgSMI_l then 1 else 0;
DownTrend = if SMI_h < AvgSMI_h and SMI_m < AvgSMI_m and SMI_l < AvgSMI_l then 1 else 0;

plot ExitUpTrend;
plot ExitDownTrend;

If RSI >= 70 or RSI <= 30{
    ExitUpTrend = if (primaryPMO_h < primarySignalLine_h or emavalueL2 < emavalueH2) and SMI_l < avgSMI_l then 1 else 0;
    ExitDownTrend = if (primaryPMO_h > primarySignalLine_h or emavalueL2 > emavalueH2) and SMI_l > avgSMI_l then 1 else 0;
} else {
    ExitUpTrend = if SMI_m < avgSMI_m and SMI_l < avgSMI_l then 1 else 0;
    ExitDownTrend = if SMI_m > avgSMI_m and SMI_l > avgSMI_l then 1 else 0;
}

def LongBuy = if UpTrend == 1 and UpTrend[1] == 0 then 1 else 0;
def LongExit = if ExitUpTrend == 1 and ExitUpTrend[1] == 0 then 1 else 0;

def ShortSell = if DownTrend == 1 and DownTrend[1] == 0 then 1 else 0;
def ShortExit = if ExitDownTrend == 1 and ExitDownTrend[1] == 0 then 1 else 0;

UpTrend.Hide();
DownTrend.Hide();
ExitUpTrend.Hide();
ExitDownTrend.Hide();

#################################################################
############          NOTIFICATIONS                     #########
#################################################################
AddLabel(yes, if Uptrend == 1 and ExitUpTrend == 0 then "::Go Long::" else if DownTrend == 1 and ExitDownTrend == 0 then "::Go Short::" else "::Do Nothing::", if Uptrend == 1 and ExitUpTrend == 0 then Color.CYAN else if DownTrend == 1 and ExitDownTrend == 0 then Color.MAGENTA else Color.GRAY);
def bar = BarNumber();

def longSignal = if Uptrend == 1 and ExitUpTrend == 0 then 1 else 0;
Alert(longSignal == 1, "MTF Uptrend", Alert.BAR, Sound.Ring);

def shortSignal = if DownTrend == 1 and ExitDownTrend == 0 then 1 else 0;
Alert(shortSignal == 1, "MTF Downtrend", Alert.BAR, Sound.Ding);

plot upArrow = if (LongBuy == 1 and (tradetype == tradetype.long or tradetype == tradetype.both)) or (ShortExit == 1 and (tradetype == tradetype.short or tradetype == tradetype.both)) and Active then low else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
upArrow.SetDefaultColor(Color.CYAN);

plot downArrow = if (ShortSell == 1 and (tradetype == tradetype.short or tradetype == tradetype.both)) or (LongExit == 1 and (tradetype == tradetype.long or tradetype == tradetype.both)) and Active then low else Double.NaN;
downArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
downArrow.SetDefaultColor(Color.MAGENTA);

################################################################
##########                 BUY                       ###########
################################################################

AddOrder(OrderType.BUY_AUTO, LongBuy == 1 and (tradetype == tradetype.long or tradetype == tradetype.both) and Active and testTimeFrames, price = close, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "BUY");
AddOrder(OrderType.SELL_TO_CLOSE, LongExit == 1 and (tradetype == tradetype.long or tradetype == tradetype.both) and testTimeFrames, price = open[-1], tickcolor = Color.MAGENTA, arrowcolor = Color.MAGENTA, name = "Sell To Close");
AddOrder(OrderType.SELL_TO_CLOSE, EOD or CloseAllCondition and testTimeFrames, price = close, tickcolor = Color.MAGENTA, arrowcolor = Color.MAGENTA, name = "SELL EOD");

################################################################
##########                 SELL                      ###########
################################################################

AddOrder(OrderType.SELL_AUTO, ShortSell == 1 and (tradetype == tradetype.short or tradetype == tradetype.both) and Active and testTimeFrames, price = close, tickcolor = Color.MAGENTA, arrowcolor = Color.MAGENTA, name = "SELL");
AddOrder(OrderType.BUY_TO_CLOSE, ShortExit == 1 and (tradetype == tradetype.short or tradetype == tradetype.both) and testTimeFrames, price = open[-1], tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "Buy To Close");
AddOrder(OrderType.BUY_TO_CLOSE, EOD or CloseAllCondition and testTimeFrames, price = close, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "BUY EOD");

http://tos.mx/fg4xXKb
 

Drmoh1800

Member
I tested out a change today and so far i'm producing about a 5% greater win rate in backtesting. This other version is replacing the cpmo crossing the signal on the low time frame with SMI crossing the AvgSMI on the low time frame. It produces earlier entries and exits. Again though, you have to be prepared to cut losses early as it will repaint.


Ruby:
################################################################
##########            Initial Config                   #########
################################################################
input tradetype = { "long", "short", default "both" };

def timeFrame = getAggregationPeriod();
def lowestAggregation;
def middleAggregation;
def highestAggregation;
If timeFrame == AggregationPeriod.MIN {
        lowestAggregation = AggregationPeriod.MIN;
        middleAggregation = AggregationPeriod.TWO_MIN;
        highestAggregation = AggregationPeriod.FIVE_MIN;
} else if timeFrame == AggregationPeriod.TWO_MIN {
        lowestAggregation = AggregationPeriod.TWO_MIN;
        middleAggregation = AggregationPeriod.FIVE_MIN;
        highestAggregation = AggregationPeriod.TEN_MIN;
} else if timeFrame == AggregationPeriod.FIVE_MIN {
        lowestAggregation = AggregationPeriod.FIVE_MIN;
        middleAggregation = AggregationPeriod.TEN_MIN;
        highestAggregation = AggregationPeriod.FIFTEEN_MIN;
} else if timeFrame == AggregationPeriod.TEN_MIN {
        lowestAggregation = AggregationPeriod.TEN_MIN;
        middleAggregation = AggregationPeriod.FIFTEEN_MIN;
        highestAggregation = AggregationPeriod.THIRTY_MIN;
} else if timeFrame == AggregationPeriod.FIFTEEN_MIN {
        lowestAggregation = AggregationPeriod.FIFTEEN_MIN;
        middleAggregation = AggregationPeriod.THIRTY_MIN;
        highestAggregation = AggregationPeriod.HOUR;
} else if timeFrame == AggregationPeriod.THIRTY_MIN {
        lowestAggregation = AggregationPeriod.THIRTY_MIN;
        middleAggregation = AggregationPeriod.HOUR;
        highestAggregation = AggregationPeriod.TWO_HOURS;
} else if timeFrame == AggregationPeriod.HOUR {
        lowestAggregation = AggregationPeriod.HOUR;
        middleAggregation = AggregationPeriod.TWO_HOURS;
        highestAggregation = AggregationPeriod.FOUR_HOURS;
} else if timeFrame == AggregationPeriod.TWO_HOURS {
        lowestAggregation = AggregationPeriod.TWO_HOURS;
        middleAggregation = AggregationPeriod.FOUR_HOURS;
        highestAggregation = AggregationPeriod.TWO_DAYS;
} else if timeFrame == AggregationPeriod.FOUR_HOURS {
        lowestAggregation = AggregationPeriod.FOUR_HOURS;
        middleAggregation = AggregationPeriod.DAY;
        highestAggregation = AggregationPeriod.TWO_DAYS;
} else if timeFrame == AggregationPeriod.DAY {
        lowestAggregation = AggregationPeriod.DAY;
        middleAggregation = AggregationPeriod.TWO_DAYS;
        highestAggregation = AggregationPeriod.WEEK;
} else {
    lowestAggregation = AggregationPeriod.TWO_DAYS;  
    middleAggregation = AggregationPeriod.WEEK;
    highestAggregation = AggregationPeriod.MONTH;
}
       
def testTimeFrames = if timeFrame == lowestAggregation and lowestAggregation < middleAggregation and middleAggregation < highestAggregation then 1 else 0;
def CloseAllCondition = if timeFrame <= AggregationPeriod.FIFTEEN_MIN then 0 else if SecondsTillTime(1558) == 0 then 1 else 0;
def EOD = if timeFrame >= AggregationPeriod.FIFTEEN_MIN then 0 else if SecondsTillTime(1558) == 0 and SecondsFromTime(1558) == 0 then 1 else 0;
def Active = if timeFrame >= AggregationPeriod.FIFTEEN_MIN and (SecondsFromTime(1000) > 0 and SecondsTillTime(1550) > 0) then 1 else if (SecondsFromTime(0930) > 0 and SecondsTillTime(1558) > 0) then 1 else 0;

################################################################
##########            Global Variables                 #########
################################################################
# RSI
input rsiLength = 14;
input rsiAverageType = AverageType.WILDERS;

# Stochastic
input smiKPeriod = 5;
input smiDPeriod = 3;
input smiDontBuyAbove = 100;
input smiDontSellBelow = -100;

# CPMO
input cpmoLength1 = 14;
input cpmoLength2 = 9;
input cpmoSignalLength = 10;

# EMA
input emaPeriodL2 = 8;
input emaPeriodH2 = 14;

################################################################
##########                 RSI                         #########
################################################################
def NetChgAvg = MovingAverage(rsiAverageType, close(period = lowestAggregation) - close(period = lowestAggregation)[1], rsiLength);
def TotChgAvg = MovingAverage(rsiAverageType, AbsValue(close(period = lowestAggregation) - close(period = lowestAggregation)[1]), rsiLength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

################################################################
##########                 SMI                         #########
################################################################
# Stochastic Highest
def min_low_h = Lowest(low(period = highestAggregation), smiKPeriod);
def max_high_h = Highest(high(period = highestAggregation), smiKPeriod);
def rel_diff_h = close(period = highestAggregation) - (max_high_h + min_low_h) / 2;
def diff_h = max_high_h - min_low_h;

def avgrel_h = ExpAverage(ExpAverage(rel_diff_h, smiDPeriod), smiDPeriod);
def avgdiff_h = ExpAverage(ExpAverage(diff_h, smiDPeriod), smiDPeriod);

def SMI_h = if avgdiff_h != 0 then avgrel_h / (avgdiff_h / 2) * 100 else 0;
def AvgSMI_h = ExpAverage(SMI_h, smiDPeriod);

# Stochastic Middle
def min_low_m = Lowest(low(period = middleAggregation), smiKPeriod);
def max_high_m = Highest(high(period = middleAggregation), smiKPeriod);
def rel_diff_m = close(period = middleAggregation) - (max_high_m + min_low_m) / 2;
def diff_m = max_high_m - min_low_m;

def avgrel_m = ExpAverage(ExpAverage(rel_diff_m, smiDPeriod), smiDPeriod);
def avgdiff_m = ExpAverage(ExpAverage(diff_m, smiDPeriod), smiDPeriod);

def SMI_m = if avgdiff_m != 0 then avgrel_m / (avgdiff_m / 2) * 100 else 0;
def AvgSMI_m = ExpAverage(SMI_m, smiDPeriod);

# Stochastic Lowest
def min_low_l = Lowest(low(period = lowestAggregation), smiKPeriod);
def max_high_l = Highest(high(period = lowestAggregation), smiKPeriod);
def rel_diff_l = close(period = lowestAggregation) - (max_high_l + min_low_l) / 2;
def diff_l = max_high_l - min_low_l;

def avgrel_l = ExpAverage(ExpAverage(rel_diff_l, smiDPeriod), smiDPeriod);
def avgdiff_l = ExpAverage(ExpAverage(diff_l, smiDPeriod), smiDPeriod);

def SMI_l = if avgdiff_l != 0 then avgrel_l / (avgdiff_l / 2) * 100 else 0;
def AvgSMI_l = ExpAverage(SMI_l, smiDPeriod);
################################################################
##########                 CPMO                      ###########
################################################################
def PrimaryPMO_h = reference PMO(price = close(period = middleAggregation), length1 = cpmoLength1, length2 = cpmoLength2);
def PrimarySignalLine_h = ExpAverage(PrimaryPMO_h, cpmoSignalLength);

################################################################
##########                 EMA                       ###########
################################################################

def emaValueL2 = ExpAverage(close(period = lowestAggregation), length = EmaPeriodL2);
def emaValueH2 = ExpAverage(close(period = lowestAggregation), length = EmaPeriodH2);

#################################################################
############          SCAN Variables                    #########
#################################################################
plot Uptrend;
plot DownTrend;

UpTrend = if SMI_h > AvgSMI_h and SMI_m > AvgSMI_m and SMI_l > AvgSMI_l then 1 else 0;
DownTrend = if SMI_h < AvgSMI_h and SMI_m < AvgSMI_m and SMI_l < AvgSMI_l then 1 else 0;

plot ExitUpTrend;
plot ExitDownTrend;

If RSI >= 70 or RSI <= 30{
    ExitUpTrend = if (primaryPMO_h < primarySignalLine_h or emavalueL2 < emavalueH2) and SMI_l < avgSMI_l then 1 else 0;
    ExitDownTrend = if (primaryPMO_h > primarySignalLine_h or emavalueL2 > emavalueH2) and SMI_l > avgSMI_l then 1 else 0;
} else {
    ExitUpTrend = if SMI_m < avgSMI_m and SMI_l < avgSMI_l then 1 else 0;
    ExitDownTrend = if SMI_m > avgSMI_m and SMI_l > avgSMI_l then 1 else 0;
}

def LongBuy = if UpTrend == 1 and UpTrend[1] == 0 then 1 else 0;
def LongExit = if ExitUpTrend == 1 and ExitUpTrend[1] == 0 then 1 else 0;

def ShortSell = if DownTrend == 1 and DownTrend[1] == 0 then 1 else 0;
def ShortExit = if ExitDownTrend == 1 and ExitDownTrend[1] == 0 then 1 else 0;

UpTrend.Hide();
DownTrend.Hide();
ExitUpTrend.Hide();
ExitDownTrend.Hide();

#################################################################
############          NOTIFICATIONS                     #########
#################################################################
AddLabel(yes, if Uptrend == 1 and ExitUpTrend == 0 then "::Go Long::" else if DownTrend == 1 and ExitDownTrend == 0 then "::Go Short::" else "::Do Nothing::", if Uptrend == 1 and ExitUpTrend == 0 then Color.CYAN else if DownTrend == 1 and ExitDownTrend == 0 then Color.MAGENTA else Color.GRAY);
def bar = BarNumber();

def longSignal = if Uptrend == 1 and ExitUpTrend == 0 then 1 else 0;
Alert(longSignal == 1, "MTF Uptrend", Alert.BAR, Sound.Ring);

def shortSignal = if DownTrend == 1 and ExitDownTrend == 0 then 1 else 0;
Alert(shortSignal == 1, "MTF Downtrend", Alert.BAR, Sound.Ding);

plot upArrow = if (LongBuy == 1 and (tradetype == tradetype.long or tradetype == tradetype.both)) or (ShortExit == 1 and (tradetype == tradetype.short or tradetype == tradetype.both)) and Active then low else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
upArrow.SetDefaultColor(Color.CYAN);

plot downArrow = if (ShortSell == 1 and (tradetype == tradetype.short or tradetype == tradetype.both)) or (LongExit == 1 and (tradetype == tradetype.long or tradetype == tradetype.both)) and Active then low else Double.NaN;
downArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
downArrow.SetDefaultColor(Color.MAGENTA);

################################################################
##########                 BUY                       ###########
################################################################

AddOrder(OrderType.BUY_AUTO, LongBuy == 1 and (tradetype == tradetype.long or tradetype == tradetype.both) and Active and testTimeFrames, price = close, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "BUY");
AddOrder(OrderType.SELL_TO_CLOSE, LongExit == 1 and (tradetype == tradetype.long or tradetype == tradetype.both) and testTimeFrames, price = open[-1], tickcolor = Color.MAGENTA, arrowcolor = Color.MAGENTA, name = "Sell To Close");
AddOrder(OrderType.SELL_TO_CLOSE, EOD or CloseAllCondition and testTimeFrames, price = close, tickcolor = Color.MAGENTA, arrowcolor = Color.MAGENTA, name = "SELL EOD");

################################################################
##########                 SELL                      ###########
################################################################

AddOrder(OrderType.SELL_AUTO, ShortSell == 1 and (tradetype == tradetype.short or tradetype == tradetype.both) and Active and testTimeFrames, price = close, tickcolor = Color.MAGENTA, arrowcolor = Color.MAGENTA, name = "SELL");
AddOrder(OrderType.BUY_TO_CLOSE, ShortExit == 1 and (tradetype == tradetype.short or tradetype == tradetype.both) and testTimeFrames, price = open[-1], tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "Buy To Close");
AddOrder(OrderType.BUY_TO_CLOSE, EOD or CloseAllCondition and testTimeFrames, price = close, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "BUY EOD");

http://tos.mx/fg4xXKb
I test the older Study i made 4 %real profit
I noticed so far it has has some failed entry in 1 minutes
I used it mainly with 5 minutes and really helped

The main question how to avoid fake entry ? Using that system with breakout has more wining percentage .
 
I test the older Study i made 4 %real profit
I noticed so far it has has some failed entry in 1 minutes
I used it mainly with 5 minutes and really helped

The main question how to avoid fake entry ? Using that system with breakout has more wining percentage .
yeah the fakeouts are tough when things are very volatile (today being one of the most volatile days we've had in a while). How are you using a breakout indicator, if you don't mind sharing?
 
yeah the fakeouts are tough when things are very volatile (today being one of the most volatile days we've had in a while). How are you using a breakout indicator, if you don't mind sharing?
for example looking at Spy over the last 2 hours (exhausting). It's been a terrible thing to trade either direction as it's mainly been sideways with little fakeouts in both directions over and over again.

OCMopdb.png
 

Similar threads

Top