#### YungTraderFromMontana

##### Well-known member

I recently finished a heavily refined version of Yungt's Ultimate breakout indicator that the community would love to see in a scan. Unfortunately because of its complexity I'm having extreme difficulties making it scannable. I was hoping one of you more experienced coders would be able to do it, the things you come up with always pleasantly surprise me.

@mashume @BenTen @markos @horserider @diazlaz

Here's the code, the last two plots are the end goal.

My plan was to separate the variables of each study and make separate custom scans that would combine to complete the scan. The biggest issue with this is I use the "or" statement in the plot code at the end and using this approach would seem to only make "and" possible. I know this is extremely difficult but I assure you the end result is worth it. To me at least it has been the best breakout indicator I've seen so far but it sucks to not be able to scan with it. The last thing I want to add is I'd be fine with a approximation of the scan that is more lenient then intended. This way you wouldn't miss any signals and the only downside would be sorting through tickers. I hope someone can figure this out, it's a puzzle for sure.

@mashume @BenTen @markos @horserider @diazlaz

Here's the code, the last two plots are the end goal.

My plan was to separate the variables of each study and make separate custom scans that would combine to complete the scan. The biggest issue with this is I use the "or" statement in the plot code at the end and using this approach would seem to only make "and" possible. I know this is extremely difficult but I assure you the end result is worth it. To me at least it has been the best breakout indicator I've seen so far but it sucks to not be able to scan with it. The last thing I want to add is I'd be fine with a approximation of the scan that is more lenient then intended. This way you wouldn't miss any signals and the only downside would be sorting through tickers. I hope someone can figure this out, it's a puzzle for sure.

Code:

```
declare upper;
input ThresholdMult = 4;
input LookbackLength = 4;
input LookbackPeriod = 2;
input TimeFrame2 = {"15 MIN", "1 MIN", "2 MIN", "3 MIN", "4 MIN", "5 MIN", "10 MIN", "20 MIN", "30 MIN", "1 HOUR", "2 HOURS", "4 HOURS", DAY, "2 DAYS", "3 DAYS", "4 DAYS", default WEEK, MONTH, "OPT EXP"};
input TimeFrame3 = {"30 MIN", "1 MIN", "2 MIN", "3 MIN", "4 MIN", "5 MIN", "10 MIN", "15 MIN", "20 MIN", "1 HOUR", "2 HOURS", "4 HOURS", DAY, "2 DAYS", "3 DAYS", "4 DAYS", WEEK, default MONTH, "OPT EXP"};
input HideSwings = no;
input HideCurrentTF = no;
input HideTimeFrame2 = no;
input HideTimeFrame3 = no;
input conso = .02;
input outo = .01;
input length222 = 4;
input averageType4 = AverageType.WILDERS;
#TMO True Momentum Oscillator with Higher Aggregation _Mobius
#Tuesday, May 15, 2018 12:36 PM
## OneNote Archive Name: TMO True Momentum Oscillator with Higher Aggregation _Mobius
## Archive Section: Momentum
## Suggested Tos Name: TrueMomentumOscillator_w_HigherAggregation_Mobius
## Archive Date: 5.15.2018
## Archive Notes:
## 08:43 Mobius: Well give it a few days to get altered, muched, distorted and twisted. Then when it get back to being used as intended someone will start making money with it.
## 08:45 Mobius: Oh and in my view - It's highest and best use is as designed with a secondary aggregation plotted either on it or with it around 5 to 10 time higher.
## "##" indicates an addition or adjustment by the OneNote Archivist
## Original Code Follows
input lengthyuh = 10;
input calcLength = 5;
input smoothLength = 3;
input agg = AggregationPeriod.day;
def o = open(period = agg);
def cl = close(period = agg);
def data = fold i = 0 to lengthyuh
with s
do s + (if cl > getValue(o, i)
then 1
else if cl < getValue(o, i)
then - 1
else 0);
def EMA5 = ExpAverage(data, calcLength);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);
def zero = if isNaN(cl) then double.nan else 0;
def BuyEntryyuh = 3;
def SellEntryyuh = 3;
def displacement = (main - signal) * 10;
def QByuh = Highest(displacement, BuyEntryyuh);
def QSyuh = Lowest(displacement, SellEntryyuh);
def midyuh = (qbyuh + qbyuh + Qsyuh)/3;
def middleyuh = (qbyuh + qsyuh + Qsyuh)/3;
input price = close;
input stdevLength = 5;
input avgOfStdevLength = 10;
input DYMILength = 8;
input DYMILengthLowerLimit = 3;
input DYMILengthUpperLimit = 30;
Assert(DYMILengthLowerLimit > 0, "'dymi length lower limit' must be positive: " + DYMILengthLowerLimit);
Assert(DYMILength between DYMILengthLowerLimit and DYMILengthUpperLimit, "'dymi length' must be between lower and upper limit: " + DYMILength);
def std = StDev(price, stdevLength);
def ratio = std / Average(std, avgOfStdevLength);
def dynamicLength = Floor(DYMILength / ratio);
def limitedLength = if dynamicLength < DYMILengthLowerLimit then DYMILengthLowerLimit else if dynamicLength > DYMILengthUpperLimit then DYMILengthUpperLimit else dynamicLength;
def sf = 2 / (limitedLength + 1);
def bn = Max(BarNumber(), 0);
# 10^-5 precision for ema multiplier
def expIndex = Max(1, bn - Ceil(-5 / Lg(1 - sf)));
def fromIndex = if IsNaN(expIndex) then 1 else expIndex;
def chg = price - price[1];
def absChg = AbsValue(chg);
def netChgAvg = fold indexN = fromIndex to bn + 1 with accuN do sf * (if IsNaN(GetValue(chg, bn - indexN)) then 0 else GetValue(chg, bn - indexN)) + (1 - sf) * accuN;
def totChgAvg = fold indexT = fromIndex to bn + 1 with accuT do sf * (if IsNaN(GetValue(absChg, bn - indexT)) then 0 else GetValue(absChg, bn - indexT)) + (1 - sf) * accuT;
def RSI = if totChgAvg == 0 then 50 else 50 * (netChgAvg / totChgAvg + 1);
def DYMI = RSI;
def OverBought = 18;
def OverSold = -18;
def d = 0;
def ATR = MovingAverage(averageType4, TrueRange(high / close, close / close, low / close) * 100, length222);
def BuyEntry5 = 15;
def SellEntry5 = 15;
def QB5 = Highest(ATR, BuyEntry5);
def QS5 = Lowest(ATR, SellEntry5);
def xxx = QB5[1];
def bbb = QS5[1];
def midline3 = (xxx + bbb) / 2;
def SwingsLagBar = 1;
def BuyEntry = 3;
def SellEntry = 3;
def QB = Highest(high, BuyEntry);
def QS = Lowest(low, SellEntry);
plot xx = QB[1];
plot bb = QS[1];
plot midline = (QB[1] + QS[1]) / 2;
def length = 1;
def displace = 0;
def price4 = close;
def SMA = Average(price4[-displace], length);
#--------------------------------------------------------------
def _highInPeriod1 = Highest(high, LookbackPeriod);
def _lowInPeriod1 = Lowest(low, LookbackPeriod);
#--------------------------------------------------------------
def marketLow1 = if _lowInPeriod1 < _lowInPeriod1[-LookbackPeriod] then _lowInPeriod1 else _lowInPeriod1[-LookbackPeriod];
def _markedLow1 = low == marketLow1;
rec _lastMarkedLow1 = CompoundValue(1, if IsNaN(_markedLow1) then _lastMarkedLow1[1] else if _markedLow1 then low else _lastMarkedLow1[1], low);
#--------------------------------------------------------------
def marketHigh1 = if _highInPeriod1 > _highInPeriod1[-LookbackPeriod] then _highInPeriod1 else _highInPeriod1[-LookbackPeriod];
def _markedHigh1 = high == marketHigh1;
rec _lastMarkedHigh1 = CompoundValue(1, if IsNaN(_markedHigh1) then _lastMarkedHigh1[1] else if _markedHigh1 then high else _lastMarkedHigh1[1], high);
#--------------------------------------------------------------
plot Resistance1 = _lastMarkedHigh1;
plot Support1 = _lastMarkedLow1;
#--------------------------------------------------------------
Resistance1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance1.SetDefaultColor(Color.MAGENTA);
Resistance1.SetHiding(HideCurrentTF);
#--------------------------------------------------------------
Support1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support1.SetDefaultColor(Color.YELLOW);
Support1.SetHiding(HideCurrentTF);
#--------------------------------------------------------------
def LowSwingForw = Lowest(low, SwingsLagBar)[-SwingsLagBar];
def LowSwingBack = Lowest(low, LookbackPeriod)[1];
def SwingLow = if low < LowSwingForw and low <= LowSwingBack then 1 else 0;
plot LowSwing = if SwingLow then low else Double.NaN;
LowSwing.Hide();
#--------------------------------------------------------------
def HighSwingForw = Highest(high, SwingsLagBar)[-SwingsLagBar];
def HighSwingBack = Highest(high, LookbackPeriod)[1];
def SwingHigh = if high > HighSwingForw and high >= HighSwingBack then 1 else 0;
plot HighSwing = if SwingHigh then high else Double.NaN;
HighSwing.Hide();
#--------------------------------------------------------------
HighSwing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
HighSwing.SetLineWeight(5);
HighSwing.SetDefaultColor(Color.MAGENTA);
HighSwing.SetHiding(HideSwings);
LowSwing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
LowSwing.SetLineWeight(5);
LowSwing.SetDefaultColor(Color.YELLOW);
LowSwing.SetHiding(HideSwings);
#--------------------------------------------------------------
Alert(HighSwing, "SupRes : Swing High", Alert.BAR, Sound.Bell);
Alert(LowSwing, "SupRes : Swing Low", Alert.BAR, Sound.Bell);
#--------------------------------------------------------------
AddLabel(HighSwing, "SupRes : Swing High", Color.MAGENTA);
AddLabel(LowSwing, "SupRes : Swing Low", Color.YELLOW);
#--------------------------------------------------------------
def _highInPeriod2 = Highest(high(period = TimeFrame2), LookbackPeriod);
def _lowInPeriod2 = Lowest(low(period = TimeFrame2), LookbackPeriod);
#--------------------------------------------------------------
def marketLow2 = if _lowInPeriod2 < _lowInPeriod2[-LookbackPeriod] then _lowInPeriod2 else _lowInPeriod2[-LookbackPeriod];
def _markedLow2 = low(period = TimeFrame2) == marketLow2;
rec _lastMarkedLow2 = CompoundValue(1, if IsNaN(_markedLow2) then _lastMarkedLow2[1] else if _markedLow2 then low(period = TimeFrame2) else _lastMarkedLow2[1], low(period = TimeFrame2));
#--------------------------------------------------------------
def marketHigh2 = if _highInPeriod2 > _highInPeriod2[-LookbackPeriod] then _highInPeriod2 else _highInPeriod2[-LookbackPeriod];
def _markedHigh2 = high(period = TimeFrame2) == marketHigh2;
rec _lastMarkedHigh2 = CompoundValue(1, if IsNaN(_markedHigh2) then _lastMarkedHigh2[1] else if _markedHigh2 then high(period = TimeFrame2) else _lastMarkedHigh2[1], high(period = TimeFrame2));
#--------------------------------------------------------------
plot Resistance2 = _lastMarkedHigh2;
Resistance2.Hide();
plot Support2 = _lastMarkedLow2;
Support2.Hide();
#--------------------------------------------------------------
Resistance2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance2.SetDefaultColor(Color.MAGENTA);
Resistance2.SetHiding(HideTimeFrame2);
#--------------------------------------------------------------
Support2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support2.SetDefaultColor(Color.YELLOW);
Support2.SetHiding(HideTimeFrame2);
#--------------------------------------------------------------
def _highInPeriod3 = Highest(high(period = TimeFrame3), LookbackPeriod);
def _lowInPeriod3 = Lowest(low(period = TimeFrame3), LookbackPeriod);
#--------------------------------------------------------------
def marketLow3 = if _lowInPeriod3 < _lowInPeriod3[-LookbackPeriod] then _lowInPeriod3 else _lowInPeriod3[-LookbackPeriod];
def _markedLow3 = low(period = TimeFrame3) == marketLow3;
rec _lastMarkedLow3 = CompoundValue(1, if IsNaN(_markedLow3) then _lastMarkedLow3[1] else if _markedLow3 then low(period = TimeFrame3) else _lastMarkedLow3[1], low(period = TimeFrame3));
#--------------------------------------------------------------
def marketHigh3 = if _highInPeriod3 > _highInPeriod3[-LookbackPeriod] then _highInPeriod3 else _highInPeriod3[-LookbackPeriod];
def _markedHigh3 = high(period = TimeFrame3) == marketHigh3;
rec _lastMarkedHigh3 = CompoundValue(1, if IsNaN(_markedHigh3) then _lastMarkedHigh3[1] else if _markedHigh3 then high(period = TimeFrame3) else _lastMarkedHigh3[1], high(period = TimeFrame3));
#--------------------------------------------------------------
plot Resistance3 = _lastMarkedHigh3;
Resistance3.Hide();
plot Support3 = _lastMarkedLow3;
Support3.Hide();
#--------------------------------------------------------------
Resistance3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance3.SetDefaultColor(Color.MAGENTA);
Resistance3.SetHiding(HideTimeFrame3);
#--------------------------------------------------------------
Support3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support3.SetDefaultColor(Color.YELLOW);
Support3.SetHiding(HideTimeFrame3);
input nFE1 = 1;
input nfe2 = 2;
input nfe3 = 3;
input nfe4 = 4;
input nfe5 = 5;
input nfe6 = 6;
input nfe7 = 7;
input nfe8 = 8;
input nfe9 = 9;
input nfe10 = 10;
input nfe11 = 11;
input nfe12 = 12;
input nfe13 = 13;
input nfe14 = 14;
input nfe15 = 15;
input nfe16 = 16;
input nfe17 = 17;
input nfe18 = 18;
input nfe19 = 19;
input nfe20 = 20;
# Calculations
def gamma = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nFE1) /
(Highest(high, nFE1) - Lowest(low, nFE1)))
/ Log(nFE1);
def gamma2 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe2) /
(Highest(high, nfe2) - Lowest(low, nfe2)))
/ Log(nfe2);
def gamma3 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe3) /
(Highest(high, nfe3) - Lowest(low, nfe3)))
/ Log(nfe3);
def gamma4 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe4) /
(Highest(high, nfe4) - Lowest(low, nfe4)))
/ Log(nfe4);
def gamma5 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe5) /
(Highest(high, nfe5) - Lowest(low, nfe5)))
/ Log(nfe5);
def gamma6 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe6) /
(Highest(high, nfe6) - Lowest(low, nfe6)))
/ Log(nfe6);
def gamma7 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe7) /
(Highest(high, nfe7) - Lowest(low, nfe7)))
/ Log(nfe7);
def gamma8 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe8) /
(Highest(high, nfe8) - Lowest(low, nfe8)))
/ Log(nfe8);
def gamma9 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe9) /
(Highest(high, nfe9) - Lowest(low, nfe9)))
/ Log(nfe9);
def gamma10 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe10) /
(Highest(high, nfe10) - Lowest(low, nfe10)))
/ Log(nfe10);
def gamma11 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe11) /
(Highest(high, nfe11) - Lowest(low, nfe11)))
/ Log(nfe11);
def gamma12 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe12) /
(Highest(high, nfe12) - Lowest(low, nfe12)))
/ Log(nfe12);
def gamma13 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe13) /
(Highest(high, nfe13) - Lowest(low, nfe13)))
/ Log(nfe13);
def gamma14 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe14) /
(Highest(high, nfe14) - Lowest(low, nfe14)))
/ Log(nfe14);
def gamma15 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe15) /
(Highest(high, nfe15) - Lowest(low, nfe15)))
/ Log(nfe15);
def gamma16 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe16) /
(Highest(high, nfe16) - Lowest(low, nfe16)))
/ Log(nfe16);
def gamma17 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe17) /
(Highest(high, nfe17) - Lowest(low, nfe17)))
/ Log(nfe17);
def gamma18 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe18) /
(Highest(high, nfe18) - Lowest(low, nfe18)))
/ Log(nfe18);
def gamma19 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe19) /
(Highest(high, nfe19) - Lowest(low, nfe19)))
/ Log(nfe19);
def gamma20 = Log(Sum((Max(high, close[1]) - Min(low, close[1])), nfe20) /
(Highest(high, nfe20) - Lowest(low, nfe20)))
/ Log(nfe20);
def gammasector1 = (gamma2 + gamma3 + gamma4 + gamma5) / 4;
def gammasector2 = (gamma6 + gamma7 + gamma8 + gamma9 + gamma10) / 5;
def gammasector3 = (gamma11 + gamma12 + gamma13 + gamma14 + gamma15) / 5;
def gammasector4 = (gamma16 + gamma17 + gamma18 + gamma19 + gamma20) / 5;
def twoofthree3 = (gammasector2[1] > gammasector2) or (gammasector3[1] > gammasector3);
def twoofthree2 = (gammasector2[1] > gammasector2) and (gammasector4[1] > gammasector4);
def twoofthree = twoofthree3 or twoofthree2;
def feblast = gammasector1[1] > gammasector1 and gammasector2[1] > gammasector2 and gammasector3[1] > gammasector3 and gammasector4[1] > gammasector4;
def break3 = (gammasector1[1] > gammasector1) and (gammasector2[1] > gammasector2) and (gammasector3[1] > gammasector3) and (gammasector4[1] > gammasector4);
def lower_close1 = (close crosses below Support1[1]);
def higher_close1 = (close crosses above Resistance1[1]);
def lower_close2 = (close crosses below Support2[1]);
def higher_close2 = (close crosses above Resistance2[1]);
def lower_close3 = (close crosses below Support2[1]);
def higher_close3 = (close crosses above Resistance2[1]);
def x = (hl2 > xx);
def c = (close[1] < xx[1]);
def v = (close[2] < xx[2]);
def b = x and (c or v);
def y = (close > bb);
def w = (close[1] < bb[1]);
def e = (close[2] < bb[2]);
def r = y and (w or e);
def allbreakdown = lower_close1 or lower_close2 or lower_close3;
def allbreakup = (higher_close1 or higher_close2 or higher_close3);
input BuyEntry2 = 5;
input SellEntry2 = 5;
def QB2 = Highest(high, BuyEntry2);
def QS2 = Lowest(low, SellEntry2);
plot trueqb2 = QB2[1];
trueqb2.SetDefaultColor(GetColor(27));
plot trueqs2 = QS2[1];
trueqs2.SetDefaultColor(GetColor(27));
def ath = (((trueqb2 - trueqb2[10]) / 100) < .10);
def atl = (((trueqs2 - trueqs2[10]) / 100) >= -.10);
def length67 = 10;
def displace2 = 0;
def AvgExp = ExpAverage(close[-displace2], length67);
input length69 = 4;
def factor = .869;
input mode = {default Range, ATR};
def range;
switch (mode) {
case Range:
range = Highest(high, length69) - Lowest(low, length69);
case ATR:
range = reference ATR();
}
def RangeRatio = (range / range[length69]) / 20;
def RangeFactor = factor / 20;
def goodtrade = RangeRatio[1] < RangeFactor[1] and RangeRatio > RangeFactor;
def badhammer = (((high - close) < ((close + open) / 2) - low)) and (open > QB[1]);
plot comboupstrongstrongstrong = (high > QB[1]) and (c[1] < QB[2]) and (((high - QB[1]) / 100) < outo) and (((QB[1] - AvgExp) / 100) < conso) and (low < midline[1]);
plot comboupstrongstrong = (high > QB[1]) and (c[1] < QB[2]) and (((open - QB[1]) / 100) < outo) and (((QB[1] - AvgExp) / 100) < conso) and (open[1] or open[2] or open[3] < midline) and comboupstrongstrongstrong is false and (open < QB[1]) and (open[1] > QS[2]) and (close[1] < midline[2]);
plot comboupstrong = (high > QB[1]) and (close[1] < QB[2]) and (((open - QB[1]) / 100) < outo) and (((QB[1] - AvgExp) / 100) < conso) and comboupstrongstrongstrong is false and comboupstrongstrong is false and (high > open) and (low < midline) and (high > open);
def any = comboupstrong or comboupstrongstrong or comboupstrongstrongstrong;
def fg = (high - close) < ((close - open) * 2);
def fgbear = (close - low) < ((open - close) * 2);
def goodcandle = ((high - close) < (hl2 - low)) or (open > high[1]);
def goodsellcandle = (close - low) < (high - hl2);
def allfe = ((gammasector1 + gammasector2 + gammasector3 + gammasector4) / 4);
def length6969 = 5;
input length13 = 16;
input length1 = 4;
input length2 = 5;
input length3 = 6;
input length4 = 7;
input length5 = 8;
input length6 = 9;
input length7 = 10;
input length8 = 11;
input length9 = 12;
input length10 = 13;
input length11 = 14;
input length12 = 15;
input averageType = AverageType.EXPONENTIAL;
input lengthave = 2;
def ll = Lowest(low, length1);
def hh = Highest(high, length1);
def atr1 = MovingAverage(averageType, TrueRange(high, close, low), length1);
def tmp_H = (Log(hh - ll) - Log(atr1)) / (Log(length1));
def H;
if tmp_H > 1
then {
H = 1;
} else if tmp_H < 0 {
H = 0;
} else {
H = tmp_H;
}
def ll2 = Lowest(low, length2);
def hh2 = Highest(high, length2);
def atr2 = MovingAverage(averageType, TrueRange(high, close, low), length2);
def tmp_H2 = (Log(hh2 - ll2) - Log(atr2)) / (Log(length2));
def H2;
if tmp_H2 > 1
then {
H2 = 1;
} else if tmp_H2 < 0 {
H2 = 0;
} else {
H2 = tmp_H2;
}
def ll3 = Lowest(low, length3);
def hh3 = Highest(high, length3);
def atr3 = MovingAverage(averageType, TrueRange(high, close, low), length3);
def tmp_H3 = (Log(hh3 - ll3) - Log(atr3)) / (Log(length3));
def H3;
if tmp_H3 > 1
then {
H3 = 1;
} else if tmp_H3 < 0 {
H3 = 0;
} else {
H3 = tmp_H3;
}
def ll4 = Lowest(low, length4);
def hh4 = Highest(high, length4);
def atr4 = MovingAverage(averageType, TrueRange(high, close, low), length4);
def tmp_H4 = (Log(hh4 - ll4) - Log(atr4)) / (Log(length4));
def H4;
if tmp_H4 > 1
then {
H4 = 1;
} else if tmp_H4 < 0 {
H4 = 0;
} else {
H4 = tmp_H4;
}
def ll5 = Lowest(low, length5);
def hh5 = Highest(high, length5);
def atr5 = MovingAverage(averageType, TrueRange(high, close, low), length5);
def tmp_H5 = (Log(hh5 - ll5) - Log(atr5)) / (Log(length5));
def H5;
if tmp_H5 > 1
then {
H5 = 1;
} else if tmp_H5 < 0 {
H5 = 0;
} else {
H5 = tmp_H5;
}
def ll6 = Lowest(low, length6);
def hh6 = Highest(high, length6);
def atr6 = MovingAverage(averageType, TrueRange(high, close, low), length6);
def tmp_H6 = (Log(hh6 - ll6) - Log(atr6)) / (Log(length6));
def H6;
if tmp_H6 > 1
then {
H6 = 1;
} else if tmp_H6 < 0 {
H6 = 0;
} else {
H6 = tmp_H6;
}
def ll7 = Lowest(low, length7);
def hh7 = Highest(high, length7);
def atr7 = MovingAverage(averageType, TrueRange(high, close, low), length7);
def tmp_H7 = (Log(hh7 - ll7) - Log(atr7)) / (Log(length7));
def H7;
if tmp_H7 > 1
then {
H7 = 1;
} else if tmp_H7 < 0 {
H7 = 0;
} else {
H7 = tmp_H7;
}
def ll8 = Lowest(low, length8);
def hh8 = Highest(high, length8);
def atr8 = MovingAverage(averageType, TrueRange(high, close, low), length8);
def tmp_h8 = (Log(hh8 - ll8) - Log(atr8)) / (Log(length8));
def H8;
if tmp_h8 > 1
then {
H8 = 1;
} else if tmp_h8 < 0 {
H8 = 0;
} else {
H8 = tmp_h8;
}
def ll9 = Lowest(low, length9);
def hh9 = Highest(high, length9);
def atr9 = MovingAverage(averageType, TrueRange(high, close, low), length9);
def tmp_H9 = (Log(hh9 - ll9) - Log(atr9)) / (Log(length9));
def H9;
if tmp_H9 > 1
then {
H9 = 1;
} else if tmp_H9 < 0 {
H9 = 0;
} else {
H9 = tmp_H9;
}
def ll10 = Lowest(low, length10);
def hh10 = Highest(high, length10);
def atr10 = MovingAverage(averageType, TrueRange(high, close, low), length10);
def tmp_H10 = (Log(hh10 - ll10) - Log(atr10)) / (Log(length10));
def H10;
if tmp_H10 > 1
then {
H10 = 1;
} else if tmp_H10 < 0 {
H10 = 0;
} else {
H10 = tmp_H10;
}
def ll11 = Lowest(low, length11);
def hh11 = Highest(high, length11);
def atr11 = MovingAverage(averageType, TrueRange(high, close, low), length11);
def tmp_H11 = (Log(hh11 - ll11) - Log(atr11)) / (Log(length11));
def H11;
if tmp_H11 > 1
then {
H11 = 1;
} else if tmp_H11 < 0 {
H11 = 0;
} else {
H11 = tmp_H11;
}
def ll12 = Lowest(low, length12);
def hh12 = Highest(high, length12);
def atr12 = MovingAverage(averageType, TrueRange(high, close, low), length12);
def tmp_H12 = (Log(hh12 - ll12) - Log(atr12)) / (Log(length12));
def H12;
if tmp_H12 > 1
then {
H12 = 1;
} else if tmp_H12 < 0 {
H12 = 0;
} else {
H12 = tmp_H12;
}
def ll13 = Lowest(low, length13);
def hh13 = Highest(high, length13);
def atr13 = MovingAverage(averageType, TrueRange(high, close, low), length13);
def tmp_H13 = (Log(hh13 - ll13) - Log(atr13)) / (Log(length13));
def H13;
if tmp_H13 > 1
then {
H13 = 1;
} else if tmp_H13 < 0 {
H13 = 0;
} else {
H13 = tmp_H13;
}
plot gamma_max = Max(gamma4, Max(gamma5,
Max(gamma6, Max(gamma7, Max(gamma8, Max(gamma9, Max(gamma10,
Max(gamma11, Max(gamma12, Max(gamma13, Max(gamma14, gamma15)))))))))));
plot gamma_min = Min(gamma4, Min(gamma5,
Min(gamma6, Min(gamma7, Min(gamma8, Min(gamma9, Min(gamma10,
Min(gamma11, Min(gamma12, Min(gamma13, Min(gamma14, gamma15)))))))))));
def he_max = max(h, max(h2, max(h3,
max(h4, max(h5, max(h6, max(h7, max(h8,
max(h9, max(h10, max(h11, h12)))))))))));
def he_min = min(h, min(h2, min(h3,
min(h4, min(h5, min(h6, min(h7, min(h8,
min(h9, min(h10, min(h11, h12)))))))))));
def AverageOverRange = SImpleMovingAvg(price = (high[1] - low[1]), length = lookbackLength);
def CurrentRange = high - low;
plot tallCandle = if CurrentRange <= (AverageOverRange * ThresholdMult) then 1 else double.nan;
def f_prime = (gamma_min * -1) + 1;
def f_prime2 = (gamma_max * -1) + 1;
def bothlow = (he_min + f_prime2) / 2;
def bothup = (he_max + f_prime) / 2;
def displacement1 = (bothlow - bothlow[1]);
def displacement12 = bothup - bothup[1];
plot midline5 = (bothup + bothlow)/2;
plot vardisplacement = (bothup * (displacement1 ));
plot vardisplacement2 = (bothlow * (displacement12 ));
plot vardiv = (vardisplacement + vardisplacement2) / 2;
plot ni = .06769;
plot g = .716969;
plot buy = vardiv > .06969 or (bothup > g and vardiv > .016969);
def dymichange = dymi - dymi[3];
def buy2 = (dymichange > dymichange[3]) and (dymichange > 20 or dymi > 92.69);
def buy2alt = (dymichange < dymichange[3]) and (dymichange < -20 or dymi < 8);
def dif = (qbyuh - qsyuh) > 2;
def factoupinstant = displacement > 16 and displacement >= qbyuh;
def factoupinstantsell = displacement < -16 and displacement <= qsyuh;
def factoup = displacement > -7 and (displacement >= qbyuh or (displacement > 10 and displacement > midyuh));
def factodown = displacement < 7 and (displacement <= qsyuh or (displacement < -10 and displacement < middleyuh)) and dif[1];
def decengtcand = if (close > open and (high - close > close - open) and (open - low < close - close)) then 1 else 0;
def decengtcand2 = if (close < open and (high - close > close - open)) then 1 else 0;
def breakups = ((allbreakup or (allbreakup[1]) or (allbreakup[2]) or allbreakup[3]));
def buys = (buy or buy[1] or buy[2] or buy[3] or buy2 or factoupinstant);
def buyssector = ((buy or buy[1] or buy[2] or buy[3]) and buy2);
def sellsector = ((buy or buy[1] or buy[2]) and buy2alt);
def breakdowns = ((allbreakdown or (allbreakdown[1]) or (allbreakdown[2])));
def sellbuy = (buy or buy[1] or buy[2] or buy2alt or factoupinstantsell);
plot goldenbuywfe = breakups and buys and (factoup or buyssector);
goldenbuywfe.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
goldenbuywfe.SetDefaultColor(GetColor(8));
plot goldenbuywfetest = ((allbreakup or allbreakup[1])) and (buy2);
plot goldenshort = breakdowns and sellbuy and (sellsector or factodown);
goldenshort.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
goldenshort.SetDefaultColor(GetColor(39));
#plot regularshort = ((allbreakdown or allbreakdown[1] or allbreakdown[2])) and fgbear;
```

Last edited by a moderator: