#### Mightymorphinchris

##### Active member

**Overview**

This is v2 of V1.

A multi indicator, multi time frame strategy that repaints (beware). If used properly with other technical analysis (which I hope you'll suggest and contribute to this) then it can potentially produce good results. I wrote this with scalping in mind and have personally struggled with swing trading. That doesn't mean this won't work for you in swing trading but.... if it does please share your settings or additional indicators that improve upon swing trades.

**Trading**

I have spent a significant amount of time on this strategy. I typically trade the 1m time frame (which this strategy is looking at multiple time frames). The biggest problem with this strategy is repainting... and as a scalper that's usually the problem with most strategies.

I trade the 1m time frame but, this strategy is coded to look at multiple time frames no matter what time frame you're on.

**Cry for help**

If you can help improve upon what I have here that would be greatly appreciated.

**Settings**

The strategy has an automatic setting mode and a manual. The automatic is what I found produced the best results for SPY when back testing on various time frames Please, if you find better settings, contribute to the community and share what you've found.

**Final thoughts**

I feel like I'm sharing my life's work here so if you can bring your own contributions and improvements to it I'd love that.

**Share link**

http://tos.mx/Df9v5Kr

**Code**

Ruby:

```
###############################################################
########## Initial Config #########
################################################################
input securityType = { default "stocks", "forex"};
input tradetype = { "long", "short", default "both" };
input mode = { default "superScalp", "normal"};
input configMode = { default "automatic", "manual"};
input timeMode = { default "shorter", "normal"};
def timeFrame = GetAggregationPeriod();
def lowestAggregation;
def middleAggregation;
def highestAggregation;
def extraHighAggregation;
def xxlAggregation;
def xxxlAggregation;
if timeFrame == AggregationPeriod.MIN and timeMode == timeMode.shorter {
lowestAggregation = AggregationPeriod.MIN;
middleAggregation = AggregationPeriod.TWO_MIN;
highestAggregation = AggregationPeriod.FOUR_MIN;
extraHighAggregation = AggregationPeriod.FIVE_MIN;
xxlAggregation = AggregationPeriod.TEN_MIN;
xxxlAggregation = AggregationPeriod.FIFTEEN_MIN;
} else if timeFrame == AggregationPeriod.MIN {
lowestAggregation = AggregationPeriod.MIN;
middleAggregation = AggregationPeriod.TWO_MIN;
highestAggregation = AggregationPeriod.FOUR_MIN;
extraHighAggregation = AggregationPeriod.FIVE_MIN;
xxlAggregation = AggregationPeriod.FIFTEEN_MIN;
xxxlAggregation = AggregationPeriod.TWENTY_MIN;
} else if timeFrame == AggregationPeriod.TWO_MIN and timeMode == timeMode.shorter {
lowestAggregation = AggregationPeriod.TWO_MIN;
middleAggregation = AggregationPeriod.FOUR_MIN;
highestAggregation = AggregationPeriod.FIVE_MIN;
extraHighAggregation = AggregationPeriod.TEN_MIN;
xxlAggregation = AggregationPeriod.FIFTEEN_MIN;
xxxlAggregation = AggregationPeriod.THIRTY_MIN;
} else if timeFrame == AggregationPeriod.TWO_MIN {
lowestAggregation = AggregationPeriod.TWO_MIN;
middleAggregation = AggregationPeriod.FIVE_MIN;
highestAggregation = AggregationPeriod.TEN_MIN;
extraHighAggregation = AggregationPeriod.FIFTEEN_MIN;
xxlAggregation = AggregationPeriod.THIRTY_MIN;
xxxlAggregation = AggregationPeriod.HOUR;
} else if timeFrame == AggregationPeriod.THREE_MIN and timeMode == timeMode.shorter {
lowestAggregation = AggregationPeriod.THREE_MIN;
middleAggregation = AggregationPeriod.FOUR_MIN;
highestAggregation = AggregationPeriod.FIVE_MIN;
extraHighAggregation = AggregationPeriod.TEN_MIN;
xxlAggregation = AggregationPeriod.FIFTEEN_MIN;
xxxlAggregation = AggregationPeriod.THIRTY_MIN;
} else if timeFrame == AggregationPeriod.THREE_MIN {
lowestAggregation = AggregationPeriod.THREE_MIN;
middleAggregation = AggregationPeriod.FIVE_MIN;
highestAggregation = AggregationPeriod.TEN_MIN;
extraHighAggregation = AggregationPeriod.FIFTEEN_MIN;
xxlAggregation = AggregationPeriod.THIRTY_MIN;
xxxlAggregation = AggregationPeriod.HOUR;
} else if timeFrame == AggregationPeriod.FOUR_MIN and timeMode == timeMode.shorter {
lowestAggregation = AggregationPeriod.FOUR_MIN;
middleAggregation = AggregationPeriod.FIVE_MIN;
highestAggregation = AggregationPeriod.TEN_MIN;
extraHighAggregation = AggregationPeriod.FIFTEEN_MIN;
xxlAggregation = AggregationPeriod.TWENTY_MIN;
xxxlAggregation = AggregationPeriod.THIRTY_MIN;
} else if timeFrame == AggregationPeriod.FOUR_MIN {
lowestAggregation = AggregationPeriod.FOUR_MIN;
middleAggregation = AggregationPeriod.FIVE_MIN;
highestAggregation = AggregationPeriod.TEN_MIN;
extraHighAggregation = AggregationPeriod.FIFTEEN_MIN;
xxlAggregation = AggregationPeriod.THIRTY_MIN;
xxxlAggregation = AggregationPeriod.HOUR;
} else if timeFrame == AggregationPeriod.FIVE_MIN {
lowestAggregation = AggregationPeriod.FIVE_MIN;
middleAggregation = AggregationPeriod.TEN_MIN;
highestAggregation = AggregationPeriod.FIFTEEN_MIN;
extraHighAggregation = AggregationPeriod.THIRTY_MIN;
xxlAggregation = AggregationPeriod.HOUR;
xxxlAggregation = AggregationPeriod.TWO_HOURS;
} else if timeFrame == AggregationPeriod.TEN_MIN {
lowestAggregation = AggregationPeriod.TEN_MIN;
middleAggregation = AggregationPeriod.FIFTEEN_MIN;
highestAggregation = AggregationPeriod.THIRTY_MIN;
extraHighAggregation = AggregationPeriod.HOUR;
xxlAggregation = AggregationPeriod.TWO_HOURS;
xxxlAggregation = AggregationPeriod.FOUR_HOURS;
} else if timeFrame == AggregationPeriod.FIFTEEN_MIN {
lowestAggregation = AggregationPeriod.FIFTEEN_MIN;
middleAggregation = AggregationPeriod.THIRTY_MIN;
highestAggregation = AggregationPeriod.HOUR;
extraHighAggregation = AggregationPeriod.TWO_HOURS;
xxlAggregation = AggregationPeriod.FOUR_HOURS;
xxxlAggregation = AggregationPeriod.DAY;
} else if timeFrame == AggregationPeriod.THIRTY_MIN {
lowestAggregation = AggregationPeriod.THIRTY_MIN;
middleAggregation = AggregationPeriod.HOUR;
highestAggregation = AggregationPeriod.TWO_HOURS;
extraHighAggregation = AggregationPeriod.FOUR_HOURS;
xxlAggregation = AggregationPeriod.DAY;
xxxlAggregation = AggregationPeriod.TWO_DAYS;
} else if timeFrame == AggregationPeriod.HOUR {
lowestAggregation = AggregationPeriod.HOUR;
middleAggregation = AggregationPeriod.TWO_HOURS;
highestAggregation = AggregationPeriod.FOUR_HOURS;
extraHighAggregation = AggregationPeriod.DAY;
xxlAggregation = AggregationPeriod.TWO_DAYS;
xxxlAggregation = AggregationPeriod.FOUR_DAYS;
} else if timeFrame == AggregationPeriod.TWO_HOURS {
lowestAggregation = AggregationPeriod.TWO_HOURS;
middleAggregation = AggregationPeriod.FOUR_HOURS;
highestAggregation = AggregationPeriod.DAY;
extraHighAggregation = AggregationPeriod.TWO_DAYS;
xxlAggregation = AggregationPeriod.FOUR_DAYS;
xxxlAggregation = AggregationPeriod.WEEK;
} else if timeFrame == AggregationPeriod.FOUR_HOURS {
lowestAggregation = AggregationPeriod.FOUR_HOURS;
middleAggregation = AggregationPeriod.DAY;
highestAggregation = AggregationPeriod.TWO_DAYS;
extraHighAggregation = AggregationPeriod.FOUR_DAYS;
xxlAggregation = AggregationPeriod.WEEK;
xxxlAggregation = AggregationPeriod.MONTH;
} else if timeFrame == AggregationPeriod.DAY {
lowestAggregation = AggregationPeriod.DAY;
middleAggregation = AggregationPeriod.TWO_DAYS;
highestAggregation = AggregationPeriod.FOUR_DAYS;
extraHighAggregation = AggregationPeriod.WEEK;
xxlAggregation = AggregationPeriod.MONTH;
xxxlAggregation = AggregationPeriod.QUARTER;
} else {
lowestAggregation = AggregationPeriod.TWO_DAYS;
middleAggregation = AggregationPeriod.FOUR_DAYS;
highestAggregation = AggregationPeriod.WEEK;
extraHighAggregation = AggregationPeriod.MONTH;
xxlAggregation = AggregationPeriod.QUARTER;
xxxlAggregation = 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 securityType == securityType.stocks {
Active = if (SecondsFromTime(0930) > 0 and SecondsTillTime(1558) > 0) then 1 else 0;
} else {
Active = 1;
#Active = if ((SecondsFromTime(0500) > 0 and SecondsTillTime(0800) > 0)) or ((SecondsFromTime(1700) > 0 and SecondsTillTime(2100) > 0)) then 1 else 0;
}
################################################################
########## Global Variables #########
################################################################
# TimePeriodChecks
input timePeriodsLong = { "One", "Two", "Three", default "Four", "Five", "Six" };
def timePeriodsNumLong = if timePeriodsLong == timePeriodsLong.Six then 6 else if timePeriodsLong == timePeriodsLong.Five then 5 else if timePeriodsLong == timePeriodsLong.Four then 4 else if timePeriodsLong == timePeriodsLong.Three then 3 else if timePeriodsLong == timePeriodsLong.Two then 2 else 1;
input timePeriodsShort = { "One", "Two", "Three", default "Four", "Five", "Six" };
def timePeriodsNumShort = if timePeriodsShort == timePeriodsShort.Six then 6 else if timePeriodsShort == timePeriodsShort.Five then 5 else if timePeriodsShort == timePeriodsShort.Four then 4 else if timePeriodsShort == timePeriodsShort.Three then 3 else if timePeriodsShort == timePeriodsShort.Two then 2 else 1;
input timePeriodsEMA = { "One", "Two", "Three", default "Four", "Five", "Six" };
def timePeriodsNumEMA = if timePeriodsEMA == timePeriodsEMA.Six then 6 else if timePeriodsEMA == timePeriodsEMA.Five then 5 else if timePeriodsEMA == timePeriodsEMA.Four then 4 else if timePeriodsEMA == timePeriodsEMA.Three then 3 else if timePeriodsEMA == timePeriodsEMA.Two then 2 else 1;
input timePeriodsMACD = { "One", "Two", "Three", "Four", "Five", default "Six" };
def timePeriodsNumMACD = if timePeriodsMACD == timePeriodsMACD.Six then 6 else if timePeriodsMACD == timePeriodsMACD.Five then 5 else if timePeriodsMACD == timePeriodsMACD.Four then 4 else if timePeriodsMACD == timePeriodsMACD.Three then 3 else if timePeriodsMACD == timePeriodsMACD.Two then 2 else 1;
# Config Mode
def tpLong;
def tpShort;
def tpEMA;
def tpMACD;
If configMode == configMode.automatic {
if GetAggregationPeriod() == AggregationPeriod.MIN {
if mode == mode.superScalp and timeMode == timeMode.shorter{
tpLong = 6;
tpShort = 6;
tpEMA = 6;
tpMACD = 6;
} else if mode == mode.superScalp {
tpLong = 6;
tpShort = 4;
tpEMA = 6;
tpMACD = 6;
} else {
tpLong = 6;
tpShort = 4;
tpEMA = 5;
tpMACD = 6;
}
} else if GetAggregationPeriod() == AggregationPeriod.TWO_MIN {
if mode == mode.superScalp {
tpLong = 6;
tpShort = 4;
tpEMA = 6;
tpMACD = 6;
} else {
tpLong = 6;
tpShort = 4;
tpEMA = 6;
tpMACD = 6;
}
} else if GetAggregationPeriod() == AggregationPeriod.THREE_MIN {
if mode == mode.superScalp {
tpLong = 6;
tpShort = 4;
tpEMA = 6;
tpMACD = 6;
} else {
tpLong = 6;
tpShort = 4;
tpEMA = 6;
tpMACD = 6;
}
} else if GetAggregationPeriod() == AggregationPeriod.FOUR_MIN {
if mode == mode.superScalp {
tpLong = 6;
tpShort = 4;
tpEMA = 6;
tpMACD = 6;
} else {
tpLong = 6;
tpShort = 5;
tpEMA = 6;
tpMACD = 6;
}
} else if GetAggregationPeriod() == AggregationPeriod.FIVE_MIN {
if mode == mode.superScalp {
tpLong = 5;
tpShort = 6;
tpEMA = 6;
tpMACD = 6;
} else {
tpLong = 4;
tpShort = 6;
tpEMA = 5;
tpMACD = 6;
}
} else if GetAggregationPeriod() == AggregationPeriod.TEN_MIN {
if mode == mode.superScalp {
tpLong = 5;
tpShort = 6;
tpEMA = 4;
tpMACD = 6;
} else {
tpLong = 5;
tpShort = 6;
tpEMA = 6;
tpMACD = 6;
}
} else {
if mode == mode.superScalp {
tpLong = 4;
tpShort = 2;
tpEMA = 6;
tpMACD = 6;
} else {
tpLong = 3;
tpShort = 4;
tpEMA = 6;
tpMACD = 5;
}
}
} else {
tpLong = timePeriodsNumLong;
tpShort = timePeriodsNumShort;
tpEMA = timePeriodsNumEMA;
tpMACD = timePeriodsNumMACD;
}
# Indicator Settings
# RSI
input rsiLength = 16;
input rsiOverBought = 68;
input rsiOverSold = 30;
input rsiAverageType = AverageType.WILDERS;
# Stochastic
input smiKPeriod = 4;
input smiDPeriod = 2;
input smiEnterBelow = 0;
input smiExitBelow = 0;
# CPMO
input cpmoLength1 = 14;
input cpmoLength2 = 9;
input cpmoSignalLength = 10;
# MACD
input MACDFastLength = 7;
input MACDSlowLength = 19;
input MACDLength = 5;
input MACDAverageType = AverageType.EXPONENTIAL;
# EMA
input ema = 200;
################################################################
########## EMA ###########
################################################################
def priceUp = if close > ExpAverage(close, ema) then 1 else 0;
def timeLong = if priceUp then tpLong else tpEMA;
def timeLongMACD = if priceUp then tpMACD else tpEMA;
def priceDown = if close < ExpAverage(close, ema) then 1 else 0;
def timeShort = if priceDown then tpShort else tpEMA;
def timeShortMACD = if priceDown then tpMACD else tpEMA;
################################################################
########## RSI #########
################################################################
# 4 Hour
def rsiClose = close(period = xxxlAggregation);
def NetChgAvg = MovingAverage(rsiAverageType, rsiClose - rsiClose[1], rsiLength);
def TotChgAvg = MovingAverage(rsiAverageType, AbsValue(rsiClose - rsiClose[1]), rsiLength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
################################################################
########## SMI #########
################################################################
# Stochastic Extra Extra High
def min_low_xxxl = Lowest(low(period = xxxlAggregation), smiKPeriod);
def max_high_xxxl = Highest(high(period = xxxlAggregation), smiKPeriod);
def rel_diff_xxxl = close(period = xxxlAggregation) - (max_high_xxxl + min_low_xxxl) / 2;
def diff_xxxl = max_high_xxxl - min_low_xxxl;
def avgrel_xxxl = ExpAverage(ExpAverage(rel_diff_xxxl, smiDPeriod), smiDPeriod);
def avgdiff_xxxl = ExpAverage(ExpAverage(diff_xxxl, smiDPeriod), smiDPeriod);
def SMI_xxxl = if avgdiff_xxxl != 0 then avgrel_xxxl / (avgdiff_xxxl / 2) * 100 else 0;
def AvgSMI_xxxl = ExpAverage(SMI_xxxl, smiDPeriod);
# Stochastic Extra Extra High
def min_low_xxl = Lowest(low(period = xxlAggregation), smiKPeriod);
def max_high_xxl = Highest(high(period = xxlAggregation), smiKPeriod);
def rel_diff_xxl = close(period = xxlAggregation) - (max_high_xxl + min_low_xxl) / 2;
def diff_xxl = max_high_xxl - min_low_xxl;
def avgrel_xxl = ExpAverage(ExpAverage(rel_diff_xxl, smiDPeriod), smiDPeriod);
def avgdiff_xxl = ExpAverage(ExpAverage(diff_xxl, smiDPeriod), smiDPeriod);
def SMI_xxl = if avgdiff_xxl != 0 then avgrel_xxl / (avgdiff_xxl / 2) * 100 else 0;
def AvgSMI_xxl = ExpAverage(SMI_xxl, smiDPeriod);
# 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_xxl / (avgdiff_xhl / 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);
def smiCrossBelowExit = if SMI_xh crosses below 40 then 1 else 0;
def smiCrossAboveExit = if SMI_xh crosses above 40 then 1 else 0;
################################################################
########## MACD ###########
################################################################
def price_l = close(period = lowestAggregation);
def price_m = close(period = middleAggregation);
def price_h = close(period = highestAggregation);
def price_xh = close(period = extraHighAggregation);
def price_xxl = close(period = xxlAggregation);
def price_xxxl = close(period = xxxlAggregation);
def macDValue_l = MovingAverage(MACDAverageType, price_l, MACDFastLength) - MovingAverage(MACDAverageType, price_xh, MACDSlowLength);
def macDAvg_l = MovingAverage(MACDAverageType, macDValue_l, MACDLength);
def macDValue_m = MovingAverage(MACDAverageType, price_m, MACDFastLength) - MovingAverage(MACDAverageType, price_xh, MACDSlowLength);
def macDAvg_m = MovingAverage(MACDAverageType, macDValue_m, MACDLength);
def macDValue_h = MovingAverage(MACDAverageType, price_h, MACDFastLength) - MovingAverage(MACDAverageType, price_xh, MACDSlowLength);
def macDAvg_h = MovingAverage(MACDAverageType, macDValue_h, MACDLength);
def macDValue_xh = MovingAverage(MACDAverageType, price_xh, MACDFastLength) - MovingAverage(MACDAverageType, price_xh, MACDSlowLength);
def macDAvg_xh = MovingAverage(MACDAverageType, macDValue_xh, MACDLength);
def macDValue_xxl = MovingAverage(MACDAverageType, price_xxl, MACDFastLength) - MovingAverage(MACDAverageType, price_xh, MACDSlowLength);
def macDAvg_xxl = MovingAverage(MACDAverageType, macDValue_xxl, MACDLength);
def macDValue_xxxl = MovingAverage(MACDAverageType, price_xxxl, MACDFastLength) - MovingAverage(MACDAverageType, price_xh, MACDSlowLength);
def macDAvg_xxxl = MovingAverage(MACDAverageType, macDValue_xxxl, MACDLength);
################################################################
########## CPMO ###########
################################################################
def PrimaryPMO_l = reference PMO(price = close(period = lowestAggregation), length1 = cpmoLength1, length2 = cpmoLength2);
def PrimarySignalLine_l = ExpAverage(PrimaryPMO_l, cpmoSignalLength);
################################################################
########## CALC ###########
################################################################
def smiEnter = if smiEnterBelow <= 0 then -40 else if smiEnterBelow >= 40 then 0 else smiEnterBelow - 40;
def smiExit = if smiExitBelow <= 0 then -40 else if smiEnterBelow >= 40 then 0 else smiEnterBelow - 40;
def smiEnterShort = smiEnter * (-1);
def smiExitShort = smiEnter * (-1);
def smiSafeGuard = if mode == mode.superScalp then 100 else 50;
def smiSafeGuardShort = if mode == mode.superScalp then -100 else -50;
def macDLong;
if timeLongMACD == 6 {
macDLong = if macDValue_xxxl > macDAvg_xxxl and macDValue_xxl > macDAvg_xxl then 1 else 0;
} else if timeLongMACD == 5 {
macDLong = if macDValue_xxl > macDAvg_xxl and macDValue_xh > macDAvg_xh then 1 else 0;
} else if timeLongMACD == 4 {
macDLong = if macDValue_xh > macDAvg_xh and macDValue_h > macDAvg_h then 1 else 0;
} else if timeLongMACD == 3 {
macDLong = if macDValue_h > macDAvg_h and macDValue_m > macDAvg_m then 1 else 0;
} else if timeLongMACD == 2 {
macDLong = if macDValue_m > macDAvg_m and macDValue_l > macDAvg_l then 1 else 0;
} else {
macDLong = if macDValue_l > macDAvg_l then 1 else 0;
}
def macDValueExit;
def macDAvgExit;
if priceUp {
macDValueExit = if macDValue_xxxl < macDAvg_xxxl then macDValue_xh else macDValue_xxl;
macDAvgExit = if macDValue_xxxl < macDAvg_xxxl then macDAvg_xh else macDAvg_xxl;
} else {
macDValueExit = if macDValue_xxl < macDAvg_xxl then macDValue_h else macDValue_xh;
macDAvgExit = if macDValue_xxl < macDAvg_xxl then macDAvg_h else macDAvg_xh;
}
def macDShort;
if timeLongMACD == 6 {
macDShort = if macDValue_xxxl < macDAvg_xxxl and macDValue_xxl < macDAvg_xxl then 1 else 0;
} else if timeLongMACD == 5 {
macDShort = if macDValue_xxl < macDAvg_xxl and macDValue_xh < macDAvg_xh then 1 else 0;
} else if timeLongMACD == 4 {
macDShort = if macDValue_xh < macDAvg_xh and macDValue_h < macDAvg_h then 1 else 0;
} else if timeLongMACD == 3 {
macDShort = if macDValue_h < macDAvg_h and macDValue_m < macDAvg_m then 1 else 0;
} else if timeLongMACD == 2 {
macDShort = if macDValue_m < macDAvg_m and macDValue_l < macDAvg_l then 1 else 0;
} else {
macDShort = if macDValue_l < macDAvg_l then 1 else 0;
}
def macDValueExitShort;
def macDAvgExitShort;
if priceDown {
macDValueExitShort = if macDValue_xxxl < macDAvg_xxxl then macDValue_xh else macDValue_xxl;
macDAvgExitShort = if macDValue_xxxl < macDAvg_xxxl then macDAvg_xh else macDAvg_xxl;
} else {
macDValueExitShort = macDValue_xh;
macDAvgExitShort = macDAvg_xh;
}
#################################################################
############ SCAN Variables #########
#################################################################
plot Uptrend;
plot DownTrend;
if tradetype == tradetype.long or tradetype == tradetype.both {
if timeLong == 6 {
if (SMI_xxxl > AvgSMI_xxxl or SMI_xxxl <= smiEnter) and (SMI_xxl > AvgSMI_xxl or SMI_xxl <= smiEnter) and (SMI_xh > AvgSMI_xh or SMI_xh <= smiEnter) and SMI_h > AvgSMI_h and SMI_h <= smiSafeGuard and SMI_m > AvgSMI_m and SMI_l > AvgSMI_l and macDLong {
Uptrend = 1;
} else {
Uptrend = 0;
}
} else if timeLong == 5 {
if (SMI_xxl > AvgSMI_xxl or SMI_xxl <= smiEnter) and (SMI_xh > AvgSMI_xh or SMI_xh <= smiEnter) and SMI_h > AvgSMI_h and SMI_h <= smiSafeGuard and SMI_m > AvgSMI_m and SMI_l > AvgSMI_l and macDLong {
Uptrend = 1;
} else {
Uptrend = 0;
}
} else if timeLong == 4 {
if (SMI_xh > AvgSMI_xh or SMI_xh <= smiEnter) and SMI_h > AvgSMI_h and SMI_h <= smiSafeGuard and SMI_m > AvgSMI_m and SMI_l > AvgSMI_l and macDLong {
Uptrend = 1;
} else {
Uptrend = 0;
}
} else if timeLong == 3 {
if (SMI_h > AvgSMI_h or SMI_h <= smiEnter) and SMI_m > AvgSMI_m and SMI_l > AvgSMI_l and macDLong {
Uptrend = 1;
} else {
Uptrend = 0;
}
} else if timeLong == 2 {
if SMI_h <= 40 and SMI_m > AvgSMI_m and SMI_l > AvgSMI_l and macDLong {
Uptrend = 1;
} else {
Uptrend = 0;
}
} else {
if PrimaryPMO_l > PrimarySignalLine_l {
Uptrend = 1;
} else {
Uptrend = 0;
}
}
} else {
Uptrend = 0;
}
if tradetype == tradetype.short or tradetype == tradetype.both {
if timeShort == 6 {
if (SMI_xxxl < AvgSMI_xxxl or SMI_xxxl >= smiEnterShort) and (SMI_xxl < AvgSMI_xxl or SMI_xxl >= smiEnterShort) and (SMI_xh < AvgSMI_xh or SMI_xh >= smiEnterShort) and SMI_h < AvgSMI_h and SMI_h >= smiSafeGuardShort and SMI_m < AvgSMI_m and SMI_l < AvgSMI_l and macDShort {
DownTrend = 1;
} else {
DownTrend = 0;
}
} else if timeShort == 5 {
if (SMI_xxl < AvgSMI_xxl or SMI_xxl >= smiEnterShort) and (SMI_xh < AvgSMI_xh or SMI_xh >= smiEnterShort) and SMI_h < AvgSMI_h and SMI_h >= smiSafeGuardShort and SMI_m < AvgSMI_m and SMI_l < AvgSMI_l and macDShort {
DownTrend = 1;
} else {
DownTrend = 0;
}
} else if timeShort == 4 {
if (SMI_xh < AvgSMI_xh or SMI_xh >= smiEnterShort) and SMI_h < AvgSMI_h and SMI_m < AvgSMI_m and SMI_h >= smiSafeGuardShort and SMI_l < AvgSMI_l and macDShort {
DownTrend = 1;
} else {
DownTrend = 0;
}
} else if timeShort == 3 {
if (SMI_h < AvgSMI_h or SMI_h >= smiEnterShort) and SMI_h >= smiSafeGuardShort and SMI_m < AvgSMI_m and SMI_l < AvgSMI_l and macDShort {
DownTrend = 1;
} else {
DownTrend = 0;
}
} else if timeShort == 2 {
if SMI_h >= -40 and SMI_m < AvgSMI_m and SMI_l < AvgSMI_l and macDShort {
DownTrend = 1;
} else {
DownTrend = 0;
}
} else {
if PrimaryPMO_l < PrimarySignalLine_l {
DownTrend = 1;
} else {
DownTrend = 0;
}
}
} else {
DownTrend = 0;
}
plot ExitUpTrend;
plot ExitDownTrend;
#Exit UpTrend
if RSI >= rsiOverBought {
ExitUpTrend = 1;
} else if smiCrossBelowExit {
ExitUpTrend = 1;
} else if (SMI_xxxl > AvgSMI_xxxl and SMI_xxl > AvgSMI_xxl) or (SMI_xxl < smiExit and SMI_xxl > AvgSMI_xxl) and priceUp{
ExitUpTrend = if SMI_xh < AvgSMI_xh and SMI_h < AvgSMI_h and SMI_m < AvgSMI_m and SMI_l < AvgSMI_l or macDValueExit < macdAvgExit then 1 else 0;
} else if (SMI_xxl > AvgSMI_xxl and SMI_xh > AvgSMI_xh) or (SMI_xh < smiExit and SMI_xh > AvgSMI_xh) {
ExitUpTrend = if SMI_h < AvgSMI_h and SMI_m < AvgSMI_m and SMI_l < AvgSMI_l or macDValueExit < macdAvgExit then 1 else 0;
} else if (SMI_xh > AvgSMI_xh and SMI_h > AvgSMI_h) or (SMI_h < smiExit and SMI_h > AvgSMI_h) {
ExitUpTrend = if SMI_m < AvgSMI_m and SMI_l < AvgSMI_l or macDValueExit < macdAvgExit then 1 else 0;
} else if (SMI_h > AvgSMI_h and SMI_m > AvgSMI_m) or (SMI_m < smiExit and SMI_m > AvgSMI_m) {
ExitUpTrend = if PrimaryPMO_l < PrimarySignalLine_l or macDValueExit < macdAvgExit then 1 else 0;
} else {
ExitUpTrend = if SMI_l < AvgSMI_l then 1 else 0;
}
# Exit DownTrend
if RSI <= rsiOverSold {
ExitDownTrend = 1;
} else if smiCrossAboveExit {
ExitDownTrend = 1;
} else if (SMI_xxxl < AvgSMI_xxxl and SMI_xxl < AvgSMI_xxl) or (SMI_xxl > smiExitShort and SMI_xxl < AvgSMI_xxl) and priceDown {
ExitDownTrend = if SMI_xh > AvgSMI_xh and SMI_h > AvgSMI_h and SMI_m > AvgSMI_m and SMI_l > AvgSMI_l or macDValueExitShort > macdAvgExitShort then 1 else 0;
} else if (SMI_xxl < AvgSMI_xxl and SMI_xh < AvgSMI_xh) or (SMI_xh > smiExitShort and SMI_xh < AvgSMI_xh) {
ExitDownTrend = if SMI_h > AvgSMI_h and SMI_m > AvgSMI_m and SMI_l > AvgSMI_l or macDValueExitShort > macdAvgExitShort then 1 else 0;
} else if (SMI_xh < AvgSMI_xh and SMI_h < AvgSMI_h) or (SMI_h > smiExitShort and SMI_h < AvgSMI_h) {
ExitDownTrend = if SMI_m > AvgSMI_m and SMI_l > AvgSMI_l or macDValueExitShort > macdAvgExitShort then 1 else 0;
} else if (SMI_h < AvgSMI_h and SMI_m < AvgSMI_m) or (SMI_m > smiExitShort and SMI_m < AvgSMI_m) {
ExitDownTrend = if PrimaryPMO_l > PrimarySignalLine_l or macDValueExitShort > macdAvgExitShort then 1 else 0;
} else {
ExitDownTrend = if 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();
################################################################
########## 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 Active 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 Active 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");
```

**Screenshots**

Last 30 days on 1m Time Frame (again, it repaints though)

**
**

Scans

Scans

--Shared by @Mogden16--

Long Scan - https://tos.mx/yCjar0k

Short Scan - https://tos.mx/RzpkMyK

Last edited: