Momentum Paint Candles

hockeycoachdoug

Active member
2019 Donor
VIP
----------------------------------------------------------------------------------------------------
mod note:
original can be found:
https://usethinkscript.com/threads/a-trend-momentum-and-cycle-trading-system-v3-0-csa.1596/

----------------------------------------------------------------------------------------------------
I watched a webinar awhile back that made the premise that combining a trend based indicator, a momentum based indicator and a cycle based indicator gives a good indication of directional bias. I would like to combine these 3 components into one paintbar type indicator and am hoping one of you coding pros might find value in this and be willing to code it here for the community.
For the trend indicator I want to use supertrend available here by Mobius. Here is the link SuperTrend by Mobius
For the momentum indicator I want to use True Momentum Oscillator (TMO). Here is the link TMO for TOS
For the cycle indicator I want to use TOP Cycle Trader. I am posting the code for this indicator here-

Code:
declare lower;
#plot Data = close;
input   FastCycleLength = 5;
input   SlowCycleLength = 8;
#def   CycleLineColor=DefineGlobalColor(Color.RED);
#input   CycleHistColor=Color.BLUE;
#input   ZeroLineColor1 = GetColor(1);
DefineGlobalColor("CycleLineColor", Color.RED);
DefineGlobalColor("CyclehistColor", Color.BLUE);
DefineGlobalColor("ZeroLineColor", Color.YELLOW);
def H = high;
def L = low;
#def FastVar(0),SlowVar(0),DiffVar(0);

def FastVar = ExpAverage((H + L) / 2, FastCycleLength);
def SlowVar = Average((H + L) / 2, SlowCycleLength);
def DiffVar = FastVar - SlowVar;

plot pDiffVar = DiffVar;
pDiffVar.SetDefaultColor(GlobalColor("CycleLineColor"));
plot pDiffVar2 = DiffVar;
pDiffVar2.SetDefaultColor(GlobalColor("CycleHistColor"));
plot pZeroLine = 0;
pZeroLine.SetDefaultColor(GlobalColor("ZeroLineColor"));
#Plot1(DiffVar,"Cycle",CycleLineColor);
#Plot2(DiffVar,"CycleHist",CycleHistColor);
#Plot3(0    ,"Zero",ZeroLineColor);

Here is how I envision the paintbar working-
When the supertrend indicator is long that would equal +1, when its short -1.
When the TMO is green that would equal +1. when its red its -1.
When the TOP Cycle Trader is above zero that would equal +1, when its below zero -1.
When all 3 indicators are equal to +1 making +3 total the price bars would paint green.
When all 3 indicators are equal to -1 making -3 total the price bars would paint red.
If the combination of all 3 indicators equals anything else, the price bars would paint gray meaning all 3 indicators were not in agreement.

I am open to any and all suggestions. I considered MACD for the momentum indicator but thought TMO was better. Considered Doncian channel for trend but thought supertrend was better. I am hoping one of you coders out there find this idea worthy of putting in the effort to code and share with us here.

I also want to create a scan/ watchlist using this where I can add a number of stock symbols to a watchlist and have the following columns showing symbol, color of bar on a daily basis (or long term) (red, green, or gray), color of bar on a 15 or 30 minute basis (short term)(red, green, or gray, and a column showing average volatility for some period of bars to use as a sort column to find the symbols that are moving.

I want to use this in 3 ways. First as a way to confirm directional bias of trade I am in ( I should be long if bars are green). second with the scanner portion, when both a long term (daily) and a short term (15 or 30 min) are both same color then enter a trade in that colors direction. Lastly as a portfolio management feature. Take a portion of money and break into 5-10 slots each represented by a sector ETF such as 50K broken into 5 trading slots of 10K committed to each ETF. When daily bars are green for a specific ETF, that slot is long all 10K, when its red that slot is in cash.
Thank you in advance.
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Can someone please tell me what the gray candles represent? I turned everything to NO with the exception of CCI SuperTrend and the candles are all gray at all times...with the 1.7 version the candles were ONLY GREEN and RED...now with the 1.8 version do the gray candles mean no trade?
The candles will be grey if you're threshold is not met. If your threshold is 6 and your using all 10 studies then if there is 5 bullish and 5 bearish that will be your only grey candle scenario because neither bearish nor bullish exceeds is >= 6
 
Post # 70 was just illustrating a simple way to do what is being made very complicated. It was matching the gray areas with yellow and if the gray is to be areas of indecision where you would not trade or hold if in a trade to see next direction it seems the yellow bars do better. I guess it is all up to interpretation of what anyone sees.
 
Post # 70 was just illustrating a simple way to do what is being made very complicated. It was matching the gray areas with yellow and if the gray is to be areas of indecision where you would not trade or hold if in a trade to see next direction it seems the yellow bars do better. I guess it is all up to interpretation of what anyone sees.
And I'm saying it's easy to interpret the coloring of the candles like that looking back but in the moment it changes to much to be useful
 
@YungTraderFromMontana Here is your study colored candles.

2020-01-11-TOS-CHARTS.png
 
That's not what I mean, I am trying to say I want to fill in the left over grey candles from my combo study with the macd reading. Check the chart I posted and color the gray candles based on the led bar below.
Thanks All.

So only apply this condition to candles, that fall into gray category, then eval gray against the macd and color them green or red. Will make these dark red and dark green. Correct?
 
@diazlaz @YungTraderFromMontana Gentleman please consider the following...In addition to the Heikin Ashi MTF I requested earlier...I also suggest Mobius version of Heikin Ashi it is different than standard Heikin Ashi...I have put all SuperTrends side by side before and with the existing Mobius SuperTrend that is in the CSA...including TTM along with the newly requested Mobius Heikin Ashi and @Townsend Heikin Ashi MTF...My conclusion is that TTM is probably the one that is the least helpful...

I've done several comparisons between SuperTrends before on here and I think that adding those two would be a nice compliment. Check it out for yourselves and see if its worth putting it there...I think it is. Another study that I urge you guys to check out is the Schaff Trend Cycle that is found in TOS...Its similar to TMO but it allows you to stay in the trend much longer than TMO in most instances. I've personally used TMO and Schaff side by side before and they work great together.

I really like where this CSA is heading... @diazlaz you've done a great job incorporating EVERYONE's request to accommodate their style of trading with an easy to use indicator. Can't wait to see when an actual strategy is incorporated to this...there will be many based on the several indicators here already...Awesome job once again.

Code:
# Mobius
# SuperTrend HeikenAshi
# Chat Room Request
# V03.10.2015
# Up = (HIGH + LOW) / 2 + Multiplier * ATR
# Down = (HIGH + LOW) / 2 – Multiplier * ATR
# When the change of trend occurs, the indicator flips

# For RP: Add AR trend, Aberrant Vol, R State, PTR

input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;
input BubbleOn = no;
input ShowLabel = no;
input AlertOn = no;
input PlotLine = no;

def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close) / 2);
HAhigh = Max(high, close[1]);
HAlow = Min(low, close[1]);
haclose = (HAopen + HAclose[1] + HAlow + close) / 4;
def v = volume;
def bar = barNumber();
def EOD = if SecondsTillTime(1545) == 0 and
             SecondsFromTime(1545) == 0
          then 1
          else 0;
def NotActive = if SecondsFromTime(1545) > 0
                then 1
                else 0;
def ATR = MovingAverage(AvgType, TrueRange(HAhigh, HAclose, HAlow), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1]
         then Round(UP / tickSize(), 0) * tickSize()
         else Round(DN / tickSize(), 0) * tickSize();
plot SuperTrend = ST;
SuperTrend.SetHiding(!PlotLine);
SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);
SuperTrend.SetPaintingStrategy(PaintingStrategy.Line);
AssignPriceColor(if PaintBars and close < ST
                 then Color.RED
                 else if PaintBars and close > ST
                      then Color.GREEN
                      else Color.CURRENT);
plot ST_point = if isNaN(close[-1])
                then ST
                else double.nan;
ST_point.SetStyle(Curve.Points);
ST_point.SetLineWeight(3);
ST_point.SetDefaultColor(Color.Yellow);
# End Code SuperTrend HeikenAshi
 
Thanks All.

So only apply this condition to candles, that fall into gray category, then eval gray against the macd and color them green or red. Will make these dark red and dark green. Correct?
Any idea when you'll have time to do this request?
Also how do you post your screenshots? Through imgur? It's is annoying that you can't just attach saved pics.
 
Last edited:
do you add this code to the original code ??? please explain thanks


I think I found a breakthrough when it comes to the accuracy of the settings I was using. Results were already really accurate but by chance I stumbled across this extra condition that seemed to greatly increase the response. That condition being coloring all grey bars left after using your paintbar study with my conditions. If you don't understand look at the chart I'm posting and imagine all grey candles colored by the corresponding led study below. https://tos.mx/oJFkW6B
This is the code for that study
Code:
#====== MACD.value is above MACD.avg (signal line)======
input fastLength_1 = 12;#hint fastLength_1:For the MACD plot that evaluates the MACD.Value being above the MACD.Avg (signal line).
input slowLength_1 = 26;#hint slowLength_1:For the MACD plot that evaluates the MACD.Value being above the MACD.Avg (signal line).
input MACDLength_1 = 9;#hint MACDLength_1:For the MACD plot that evaluates the MACD.Value being above the MACD.Avg (signal line).
input AverageType_1 = {SMA, default EMA};#hint AverageType_1:For the MACD plot that evaluates the MACD.Value being above the MACD.Avg (signal line).
def macd_Val_1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Value;
def macd_Avg1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Avg;
def MACD_trig = if MACD().value > MACD().avg then 1 else 0;
#def MACD_Value = MACD(MACDLength = MACDLength, AverageType = "EMA").Diff;
plot Macd_Line1 = 35;
Macd_Line1.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
Macd_Line1.SetLineWeight(5);
Macd_Line1.AssignValueColor(if macd_Val_1 > macd_Avg1 then Color.Green else Color.Red);
#== end ====
I hope you can also see the potential. If you are able to add this to the next version I will then easily make a strategy because the grey candles will be eliminated.
 
ok everyone, In this version 1.9; I incorporated the MACD evaluation on the neutral paintbars. set the input of enableNeutralMACDPainter to yes, and all the neutral bars/conditions will then be further evaluated and painted based on the MACD condition. the MACD will paint with DARK reds and greens.

I will be working on integrating the rest of the indicator requests (5 to 6 new modules) throughout this week starting with HA's and will implement them in order of the threads.

Please take it for a spin and happy trading. Please provide any feedback for improvement or results as you all test it and what is working for you all.

Ruby:
#trend, a momentum and a cycle based indicator for ThinkorSwim V1.9
#@hockeycoachdoug Community Request
#
#VERSION
# 2020.01.09 V1.9 @diazlaz - Integrated PaintBars MACD Neutral Condition trigger
#                          - set enableNeutralMACDPainter to yes (default is no) and
#                          - neutral gray will be evaluated by MACD (Dark Red/Green)
# 2020.01.09 V1.8 @diazlaz - Integrated Super Trend w/CCI and ATR
#                          - Integrated CCI + TTM squeeze + TTM trend Combo
#                          - Set treshold defaults to 7 (7 out of 10), removed scanmode.
# 2020.01.04 V1.7 @diazlaz - Integrated Slim Ribbon.
# 2020.01.02 V1.6 @diazlaz - Integrated DMI and BOP, restructured INPUTS to each module.
#                            threshold increased to 4 by default.
# 2020.01.01 V1.5 @diazlaz - Integrated ADX Trending States and BAR Line
# 2020.01.01 V1.4 @diazlaz - Integrated TTM Trends, modules selection
#                            and added threshold for signals
# 2019.12.31 V1.2 @diazlaz - Integrated FREMA
# 2019.12.30 V1.1 @diazlaz - Labels, Additional Dashboard, Lower Study
# 2019.12.30 V1.0 @diazlaz - Community Ask/Release
#
#LINK
#https://usethinkscript.com/threads/i-request-help-combining-3-indicators-into-1-paintbar-study.1390/
#
#INSTRUCTION
#Here is how I envision the paintbar working:
#When the supertrend indicator is long that would equal +1, when its short -1.
#When the TMO is green that would equal +1. when its red its -1.
#When the TOP Cycle Trader is above zero that would equal +1, when its below zero -1.
#When all 3 indicators are equal to +1 making +3 total the price bars would paint #green.
#When all 3 indicators are equal to -1 making -3 total the price bars would paint red.
#If the combination of all 3 indicators equals anything else, the price bars would #paint gray meaning all 3 indicators were not in agreement.
#
#Now includes: TTM Trend, Super Trend, Frema, TMO, TOP, DMI , BOP, Slim Ribbon and
#ADX as Trending/Non-Trending, Super Trend w/CCI and ATR combo and
#a CCI + TTM squeeze + TTM trend Combo with LONG/SHORT/HOLD signal selection
#based on threshold specified and indicators enabled.
#

declare upper;

#INPUTS
input showLabels = yes;
input PaintBars = yes;
input enableNeutralMACDPainter = no;

input threshold = 7;

input enableTTM = yes;
input enableSuperTrend = yes;
input enableFrema = yes;
input enableTMO = yes;
input enableSlim = yes;
input enableTOP = yes;
input enableDMI = yes;
input enableBOP = yes;
input enableSuperTrendCCIATR = yes;
input enableCCITTM = yes;

input displace = 0;

#CORE
DefineGlobalColor("CycleLineColor", Color.RED);
DefineGlobalColor("CyclehistColor", Color.BLUE);
DefineGlobalColor("ZeroLineColor", Color.YELLOW);
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Neutral", Color.MAGENTA); #Color.YELLOW
DefineGlobalColor("Off", Color.DARK_GRAY);
DefineGlobalColor("On", Color.GREEN);
DefineGlobalColor("Sync1", Color.YELLOW);
DefineGlobalColor("Sync2", Color.CYAN);
DefineGlobalColor("Up", Color.GREEN);
DefineGlobalColor("Down", Color.RED);
DefineGlobalColor("NUp", Color.DARK_GREEN);
DefineGlobalColor("NDown", Color.DARK_RED);
DefineGlobalColor("Neutral", Color.BLUE);
DefineGlobalColor("Neutral2", Color.PLUM);

def h = high;
def l = low;
def o = open;
def c = close;
def na = Double.NaN;

AddLabel(showLabels, "A trend, momentum and cycle Trading System v1.9", Color.CYAN);

#TTM Trend
def TrendUp = if TTM_Trend().TrendUp == 1 then 1 else 0;
def TrendDown = if TTM_Trend().TrendDown == 1 then 1 else 0;
def sTTM = if TrendUp then 100 else if TrendDown then -100 else 0;
def sBullish_TTM = if(enableTTM and sTTM == 100,1,0);
def sBearish_TTM = enableTTM and sTTM == -100;
AddLabel(showlabels and enableTTM, "TTM", if IsNan(sTTM) then COLOR.DARK_GRAY else
if sTTM[-displace] > 0 then COLOR.GREEN else
if sTTM[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#SuperTrend (Mobius)
input AtrMult = 1.0; #SuperTrend
input nATR = 4; #SuperTrend
input AvgType = AverageType.HULL; #SuperTrend

def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;
def sSuperTrend = if close < ST then -100 else 100;
def sBullish_SuperTrend = enableSuperTrend and sSuperTrend == 100;
def sBearish_SuperTrend = enableSuperTrend and sSuperTrend == -100;
AddLabel(showlabels and enableSuperTrend, "SuperTrend", if IsNan(sSuperTrend) then COLOR.DARK_GRAY else
if sSuperTrend[-displace] > 0 then COLOR.GREEN else
if sSuperTrend[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#FREMA
input AA = .1; #FREMA

def CC;
def zeroLine = 0;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;
CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2) * RE1 + RE1[1];
RE3 = Power(CC, 4) * RE2 + RE2[1];
RE4 = Power(CC, 8) * RE3 + RE3[1];
RE5 = Power(CC, 16) * RE4 + RE4[1];
RE6 = Power(CC, 32) * RE5 + RE5[1];
RE7 = Power(CC, 64) * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];
def EMA_Signal = EMA – AA * RE8;
def sFrema = if (EMA_Signal > zeroLine) then 100 else -100;
def sBullish_Frema = enableFrema and sFrema == 100;
def sBearish_Frema = enableFrema and sFrema == -100;
AddLabel(showlabels and enableFrema, "Frema", if IsNan(sFrema) then COLOR.DARK_GRAY else
if sFrema[-displace] > 0 then COLOR.GREEN else
if sFrema[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#TMO
input length = 14; #TMO
input calcLength = 5; #TMO
input smoothLength = 3; #TMO

def data = fold i = 0 to length
           with s
           do s + (if c > getValue(o, i)
                   then 1
                   else if c < getValue(o, i)
                        then - 1
                        else 0);
def EMA5 = ExpAverage(data, calcLength);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);
def sMain = if Main > Signal then 100 else -100;
def sSignal = if Main > Signal then 100 else - 100;
def ob = if isNaN(c) then double.nan else round(length * .7);
def os = if isNaN(c) then double.nan else -round(length * .7);
def sTMO = if Main > Signal then 100 else -100;
def sBullish_TMO = enableTMO and sTMO == 100;
def sBearish_TMO = enableTMO and sTMO == -100;
AddLabel(showlabels and enableTMO, "TMO", if IsNan(sTMO) then COLOR.DARK_GRAY else
if sTMO[-displace] > 0 then COLOR.GREEN else
if sTMO[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#SLIM
input sSuperFast = 8;
input sFast = 13;
input sSlow = 21;

def SuperFastM1 = ExpAverage(close[-displace], sSuperFast);
def FastM1 = ExpAverage(close[-displace], sFast);
def SlowM1 = ExpAverage(close[-displace], sSlow);
def buyM1 = SuperFastM1 > FastM1 and FastM1 > SlowM1 and low > SuperFastM1;
def stopbuyM1 = SuperFastM1 <= FastM1;
def buynowM1 = !buyM1[1] and buyM1;
def buysignalM1 = CompoundValue(1, if buynowM1 and !stopbuyM1 then 1
else if buysignalM1[1] == 1 and stopbuyM1 then 0 else buysignalM1[1], 0);
def Buy_SignalM1 = buysignalM1[1] == 0 and buysignalM1 == 1;
def Momentum_DownM1 = buysignalM1[1] == 1 and buysignalM1 == 0;
def sellM1 = SuperFastM1 < FastM1 and FastM1 < SlowM1 and high < SuperFastM1;
def stopsellM1 = SuperFastM1 >= FastM1;
def sellnowM1 = !sellM1[1] and sellM1;
def sellsignalM1 = CompoundValue(1, if sellnowM1 and !stopsellM1 then 1
else if sellsignalM1[1] == 1 and stopsellM1 then 0 else sellsignalM1[1], 0);
def Sell_SignalM1 = sellsignalM1[1] == 0 and sellsignalM1;
def Momentum_UpM1 = sellsignalM1[1] == 1 and sellsignalM1 == 0;
def sStateM1 = if Buy_SignalM1 then 100 else if Momentum_UpM1 then 10 else if Sell_SignalM1 then -100 else if Momentum_DownM1 then -10 else sStateM1[1];
def sBullish_SLIM = enableSLIM and sStateM1 == 100;
def sBearish_SLIM = enableSLIM and sStateM1 == -100;
AddLabel(showlabels and enableSLIM, "SLIM", if IsNan(sStateM1) then COLOR.DARK_GRAY else
if sStateM1[-displace] >= 100 then COLOR.GREEN else
if sStateM1[-displace] <= -100 then COLOR.RED
else COLOR.YELLOW);

#TOP Cycle Trader
input FastCycleLength = 5; #TOP
input SlowCycleLength = 8; #TOP

def FastVar = ExpAverage((H + L) / 2, FastCycleLength);
def SlowVar = Average((H + L) / 2, SlowCycleLength);
def DiffVar = FastVar - SlowVar;
def pDiffVar = DiffVar;
def pDiffVar2 = DiffVar;
def sTOP = if DiffVar > 0 then 100 else -100;
def sBullish_TOP = enableTOP and sTOP == 100;
def sBearish_TOP = enableTOP and sTOP == -100;
AddLabel(showlabels and enableTOP, "TOP", if IsNan(sTOP) then COLOR.DARK_GRAY else
if sTOP[-displace] > 0 then COLOR.GREEN else
if sTOP[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#DMITrend
input DMIlength = 13;

def hiDiff = high - high[1];
def loDiff = low[1] - low;
def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM =  if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
def ATRDMI = WildersAverage(TrueRange(high, close, low), DMIlength);
Def DIPlus = 100 * WildersAverage(plusDM, DMIlength) / ATRDMI;
Def DIMinus = 100 * WildersAverage(minusDM, DMIlength) / ATRDMI;
def sDMI = if DIPlus > DIMinus then 100 else if DIMinus > DIPlus then -100 else 0;
def sBullish_DMI = enableDMI and sDMI == 100;
def sBearish_DMI = enableDMI and sDMI == -100;
AddLabel(showlabels and enableDMI, "DMI", if IsNan(sDMI) then COLOR.DARK_GRAY else
if sDMI[-displace] > 0 then COLOR.GREEN else
if sDMI[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#BOP indicator
input averageType = {Simple, Exponential, default Weighted, Wilders, Hull,  Disabled};
input BoPlength = 16;

def rawBMP = if high != low then (close - open) / (high - low) else 1;
def BMP;
switch (averageType) {
case Simple:
    BMP = Average(rawBMP, BoPlength);
case Exponential:
    BMP = ExpAverage(rawBMP, BoPlength);
case Weighted:
    BMP = wma(rawBMP, BoPlength);
case Wilders:
    BMP = WildersAverage(rawBMP, BoPlength);
case Hull:
    BMP = HullMovingAvg(rawBMP, BoPlength);
case Disabled:
    BMP = rawBMP;
}
def sBOP = if BMP > 0 then 100 else -100;
def sBullish_BOP = enableBOP and sBOP == 100;
def sBearish_BOP = enableBOP and sBOP == -100;
AddLabel(showlabels and enableBOP, "BOP", if IsNan(sBOP) then COLOR.DARK_GRAY else
if sBOP[-displace] > 0 then COLOR.GREEN else
if sBOP[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

# SUPERTREND BY MOBIUS AND CCI ATR TREND COMBINED
input lengthCCI = 50;
input lengthATR = 21;
input AtrFactor = 1.0;
def pricedata = hl2;
def ATRcci = Average(TrueRange(h, c, l), lengthATR) * AtrFactor;
def price = c + l + h;
def linDev = LinDev(price, lengthCCI);
def CCI = if linDev == 0
          then 0
          else (price - Average(price, lengthCCI)) / linDev / 0.015;
def MT1 = if CCI > 0
          then Max(MT1[1], pricedata - ATRcci)
          else Min(MT1[1], pricedata + ATRcci);
def sSuperTrendCCIATR = if c < MT1 and c < ST then -100 else if C > MT1 and c >ST then 100 else 0;
def sBullish_SuperTrendCCIATR = enableSuperTrendCCIATR and sSuperTrendCCIATR == 100;
def sBearish_SuperTrendCCIATR = enableSuperTrendCCIATR and sSuperTrendCCIATR == -100;
AddLabel(showlabels and enableSuperTrendCCIATR, "SuperTrendCCI", if IsNan(sSuperTrendCCIATR) then COLOR.DARK_GRAY else
if sSuperTrendCCIATR[-displace] > 0 then COLOR.GREEN else
if sSuperTrendCCIATR[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));


# CCI + TTM squeeze + TTM trend
def CCIBuy = CCI(length = 14).CCI > 0 and CCI(length = 50).CCI > 0;
def CCISell = CCI(length = 14).CCI < 0 and CCI(length = 50).CCI < 0;
def sTrendUp = TTM_Trend().TrendUp;
def sTrendDn = TTM_Trend().TrendDown;
def SqueezeUp = TTM_Squeeze().Histogram >= 0;
def SqueezeDn = TTM_Squeeze().Histogram <= 0;
def Buy = CCIBuy and sTrendUp and SqueezeUp;
def Sell = CCISell and sTrendDn and SqueezeDn;
def sCCITTM = if buy then 100 else if sell then -100 else 0;
def sBullish_CCITTM = enableCCITTM and sCCITTM == 100;
def sBearish_CCITTM = enableCCITTM and sCCITTM == -100;
AddLabel(showlabels and enableCCITTM, "TTM CCI", if IsNan(sCCITTM) then COLOR.DARK_GRAY else
if sCCITTM[-displace] > 0 then COLOR.GREEN else
if sCCITTM[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#ADX TRENDING
input ADXlength = 8; #ADX
input ADXTrending = 25; #ADX
input showADXBar = yes;

def ADX = DMI(ADXlength).ADX;
plot ADXCross = LowestAll(low);
ADXCross.SetPaintingStrategy(PaintingStrategy.LINE);
ADXCross.AssignValueColor(
    if ADX > ADXTrending then Color.LIME
    else Color.DARK_GRAY);
ADXCross.SetLineWeight(5);
ADXCross.SetHiding(!showADXBar);

#MACD Neutal Eval
input fastLength_1 = 12;
input slowLength_1 = 26;
input MACDLength_1 = 9;
input AverageType_1 = {SMA, default EMA};
def macd_Val_1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Value;
def macd_Avg1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Avg;
def MACD_trig = if MACD().value > MACD().avg then 1 else 0;

AddLabel(showlabels,
if ADX > ADXTrending then "Trending" else
"Non Trending",
if IsNan(c) then COLOR.DARK_GRAY else
if ADX > ADXTrending then COLOR.GREEN else
COLOR.DARK_GRAY);

AddLabel(showlabels,
"MACD",
if IsNan(c) then COLOR.DARK_GRAY else
if macd_Val_1 > macd_Avg1 then COLOR.DARK_GREEN else
COLOR.DARK_RED);

#STATE
def sResults = sSuperTrend + sTMO + sTOP + sFrema + sTTM + sDMI + sBOP + sStateM1;
def sBullish = sBullish_TTM + sBullish_SuperTrend + sBullish_Frema + sBullish_TMO + sBullish_TOP + sBullish_DMI + sBullish_BOP + sBullish_SLIM + sBullish_SuperTrendCCIATR + sBullish_CCITTM;
def sBearish = sBearish_TTM + sBearish_SuperTrend + sBearish_Frema + sBearish_TMO + sBearish_TOP + sBearish_DMI + sBearish_BOP + sBearish_SLIM + sBearish_SuperTrendCCIATR + sBearish_CCITTM;
def bullish = if(sBullish >= threshold,1,0);
def bearish = if(sBearish >= threshold,1,0);
def sState = if bullish then 100 else if bearish then -100 else 0;
def sState2 = if sState != 0 then sState else sState2[1];

#COLORBARS
AssignPriceColor(
if PaintBars then
    if bullish then COLOR.GREEN else if bearish then COLOR.RED
     else
     if enableNeutralMACDPainter then
      if macd_Val_1 > macd_Avg1 then COLOR.DARK_GREEN else COLOR.DARK_RED
     else
    COLOR.GRAY
else COLOR.CURRENT);

AddLabel(showlabels,
if bullish[-displace] then "LONG" else
if bearish[-displace] then "SHORT"
else "HOLD",
if IsNan(c) then COLOR.DARK_GRAY else
if bullish[-displace] then COLOR.GREEN else
if bearish[-displace] then COLOR.RED
else COLOR.GRAY);

#END OF trend, a momentum and a cycle based indicator for ThinkorSwim V1.9
 
Last edited:
@diazlaz Just some feedback to preempt any requests from anyone to turn this study into a scannable form. Version 1.7 is scannable but when I looked into converting version 1,8 into a scan it appears that with the addition of the following two sub studies, the scanner barfs with a complexity message and thus may not be scanned

# SUPERTREND BY MOBIUS AND CCI ATR TREND COMBINED
# CCI + TTM squeeze + TTM trend
 
@diazlaz Just some feedback to preempt any requests from anyone to turn this study into a scannable form. Version 1.7 is scannable but when I looked into converting version 1,8 into a scan it appears that with the addition of the following two sub studies, the scanner barfs with a complexity message and thus may not be scanned

# SUPERTREND BY MOBIUS AND CCI ATR TREND COMBINED
# CCI + TTM squeeze + TTM trend
thanks Tom - yeah it's getting quite complex for sure ;) - Hopefully the community down selects to a few approaches/plans and then scanners can be customized based on the trading plan/style. It's an interesting experiment to see if this leads to viable edge.
 
would it be possible to make a scanner out of it ??? again thanks great stuff



ok everyone, In this version 1.9; I incorporated the MACD evaluation on the neutral paintbars. set the input of enableNeutralMACDPainter to yes, and all the neutral bars/conditions will then be further evaluated and painted based on the MACD condition. the MACD will paint with DARK reds and greens.

I will be working on integrating the rest of the indicator requests (5 to 6 new modules) throughout this week starting with HA's and will implement them in order of the threads.

Please take it for a spin and happy trading. Please provide any feedback for improvement or results as you all test it and what is working for you all.

Ruby:
#trend, a momentum and a cycle based indicator for ThinkorSwim V1.9
#@hockeycoachdoug Community Request
#
#VERSION
# 2020.01.09 V1.9 @diazlaz - Integrated PaintBars MACD Neutral Condition trigger
#                          - set enableNeutralMACDPainter to yes (default is no) and
#                          - neutral gray will be evaluated by MACD (Dark Red/Green)
# 2020.01.09 V1.8 @diazlaz - Integrated Super Trend w/CCI and ATR
#                          - Integrated CCI + TTM squeeze + TTM trend Combo
#                          - Set treshold defaults to 7 (7 out of 10), removed scanmode.
# 2020.01.04 V1.7 @diazlaz - Integrated Slim Ribbon.
# 2020.01.02 V1.6 @diazlaz - Integrated DMI and BOP, restructured INPUTS to each module.
#                            threshold increased to 4 by default.
# 2020.01.01 V1.5 @diazlaz - Integrated ADX Trending States and BAR Line
# 2020.01.01 V1.4 @diazlaz - Integrated TTM Trends, modules selection
#                            and added threshold for signals
# 2019.12.31 V1.2 @diazlaz - Integrated FREMA
# 2019.12.30 V1.1 @diazlaz - Labels, Additional Dashboard, Lower Study
# 2019.12.30 V1.0 @diazlaz - Community Ask/Release
#
#LINK
#https://usethinkscript.com/threads/i-request-help-combining-3-indicators-into-1-paintbar-study.1390/
#
#INSTRUCTION
#Here is how I envision the paintbar working:
#When the supertrend indicator is long that would equal +1, when its short -1.
#When the TMO is green that would equal +1. when its red its -1.
#When the TOP Cycle Trader is above zero that would equal +1, when its below zero -1.
#When all 3 indicators are equal to +1 making +3 total the price bars would paint #green.
#When all 3 indicators are equal to -1 making -3 total the price bars would paint red.
#If the combination of all 3 indicators equals anything else, the price bars would #paint gray meaning all 3 indicators were not in agreement.
#
#Now includes: TTM Trend, Super Trend, Frema, TMO, TOP, DMI , BOP, Slim Ribbon and
#ADX as Trending/Non-Trending, Super Trend w/CCI and ATR combo and
#a CCI + TTM squeeze + TTM trend Combo with LONG/SHORT/HOLD signal selection
#based on threshold specified and indicators enabled.
#

declare upper;

#INPUTS
input showLabels = yes;
input PaintBars = yes;
input enableNeutralMACDPainter = no;

input threshold = 7;

input enableTTM = yes;
input enableSuperTrend = yes;
input enableFrema = yes;
input enableTMO = yes;
input enableSlim = yes;
input enableTOP = yes;
input enableDMI = yes;
input enableBOP = yes;
input enableSuperTrendCCIATR = yes;
input enableCCITTM = yes;

input displace = 0;

#CORE
DefineGlobalColor("CycleLineColor", Color.RED);
DefineGlobalColor("CyclehistColor", Color.BLUE);
DefineGlobalColor("ZeroLineColor", Color.YELLOW);
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Neutral", Color.MAGENTA); #Color.YELLOW
DefineGlobalColor("Off", Color.DARK_GRAY);
DefineGlobalColor("On", Color.GREEN);
DefineGlobalColor("Sync1", Color.YELLOW);
DefineGlobalColor("Sync2", Color.CYAN);
DefineGlobalColor("Up", Color.GREEN);
DefineGlobalColor("Down", Color.RED);
DefineGlobalColor("NUp", Color.DARK_GREEN);
DefineGlobalColor("NDown", Color.DARK_RED);
DefineGlobalColor("Neutral", Color.BLUE);
DefineGlobalColor("Neutral2", Color.PLUM);

def h = high;
def l = low;
def o = open;
def c = close;
def na = Double.NaN;

AddLabel(showLabels, "A trend, momentum and cycle Trading System v1.9", Color.CYAN);

#TTM Trend
def TrendUp = if TTM_Trend().TrendUp == 1 then 1 else 0;
def TrendDown = if TTM_Trend().TrendDown == 1 then 1 else 0;
def sTTM = if TrendUp then 100 else if TrendDown then -100 else 0;
def sBullish_TTM = if(enableTTM and sTTM == 100,1,0);
def sBearish_TTM = enableTTM and sTTM == -100;
AddLabel(showlabels and enableTTM, "TTM", if IsNan(sTTM) then COLOR.DARK_GRAY else
if sTTM[-displace] > 0 then COLOR.GREEN else
if sTTM[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#SuperTrend (Mobius)
input AtrMult = 1.0; #SuperTrend
input nATR = 4; #SuperTrend
input AvgType = AverageType.HULL; #SuperTrend

def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;
def sSuperTrend = if close < ST then -100 else 100;
def sBullish_SuperTrend = enableSuperTrend and sSuperTrend == 100;
def sBearish_SuperTrend = enableSuperTrend and sSuperTrend == -100;
AddLabel(showlabels and enableSuperTrend, "SuperTrend", if IsNan(sSuperTrend) then COLOR.DARK_GRAY else
if sSuperTrend[-displace] > 0 then COLOR.GREEN else
if sSuperTrend[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#FREMA
input AA = .1; #FREMA

def CC;
def zeroLine = 0;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;
CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2) * RE1 + RE1[1];
RE3 = Power(CC, 4) * RE2 + RE2[1];
RE4 = Power(CC, 8) * RE3 + RE3[1];
RE5 = Power(CC, 16) * RE4 + RE4[1];
RE6 = Power(CC, 32) * RE5 + RE5[1];
RE7 = Power(CC, 64) * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];
def EMA_Signal = EMA – AA * RE8;
def sFrema = if (EMA_Signal > zeroLine) then 100 else -100;
def sBullish_Frema = enableFrema and sFrema == 100;
def sBearish_Frema = enableFrema and sFrema == -100;
AddLabel(showlabels and enableFrema, "Frema", if IsNan(sFrema) then COLOR.DARK_GRAY else
if sFrema[-displace] > 0 then COLOR.GREEN else
if sFrema[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#TMO
input length = 14; #TMO
input calcLength = 5; #TMO
input smoothLength = 3; #TMO

def data = fold i = 0 to length
           with s
           do s + (if c > getValue(o, i)
                   then 1
                   else if c < getValue(o, i)
                        then - 1
                        else 0);
def EMA5 = ExpAverage(data, calcLength);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);
def sMain = if Main > Signal then 100 else -100;
def sSignal = if Main > Signal then 100 else - 100;
def ob = if isNaN(c) then double.nan else round(length * .7);
def os = if isNaN(c) then double.nan else -round(length * .7);
def sTMO = if Main > Signal then 100 else -100;
def sBullish_TMO = enableTMO and sTMO == 100;
def sBearish_TMO = enableTMO and sTMO == -100;
AddLabel(showlabels and enableTMO, "TMO", if IsNan(sTMO) then COLOR.DARK_GRAY else
if sTMO[-displace] > 0 then COLOR.GREEN else
if sTMO[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#SLIM
input sSuperFast = 8;
input sFast = 13;
input sSlow = 21;

def SuperFastM1 = ExpAverage(close[-displace], sSuperFast);
def FastM1 = ExpAverage(close[-displace], sFast);
def SlowM1 = ExpAverage(close[-displace], sSlow);
def buyM1 = SuperFastM1 > FastM1 and FastM1 > SlowM1 and low > SuperFastM1;
def stopbuyM1 = SuperFastM1 <= FastM1;
def buynowM1 = !buyM1[1] and buyM1;
def buysignalM1 = CompoundValue(1, if buynowM1 and !stopbuyM1 then 1
else if buysignalM1[1] == 1 and stopbuyM1 then 0 else buysignalM1[1], 0);
def Buy_SignalM1 = buysignalM1[1] == 0 and buysignalM1 == 1;
def Momentum_DownM1 = buysignalM1[1] == 1 and buysignalM1 == 0;
def sellM1 = SuperFastM1 < FastM1 and FastM1 < SlowM1 and high < SuperFastM1;
def stopsellM1 = SuperFastM1 >= FastM1;
def sellnowM1 = !sellM1[1] and sellM1;
def sellsignalM1 = CompoundValue(1, if sellnowM1 and !stopsellM1 then 1
else if sellsignalM1[1] == 1 and stopsellM1 then 0 else sellsignalM1[1], 0);
def Sell_SignalM1 = sellsignalM1[1] == 0 and sellsignalM1;
def Momentum_UpM1 = sellsignalM1[1] == 1 and sellsignalM1 == 0;
def sStateM1 = if Buy_SignalM1 then 100 else if Momentum_UpM1 then 10 else if Sell_SignalM1 then -100 else if Momentum_DownM1 then -10 else sStateM1[1];
def sBullish_SLIM = enableSLIM and sStateM1 == 100;
def sBearish_SLIM = enableSLIM and sStateM1 == -100;
AddLabel(showlabels and enableSLIM, "SLIM", if IsNan(sStateM1) then COLOR.DARK_GRAY else
if sStateM1[-displace] >= 100 then COLOR.GREEN else
if sStateM1[-displace] <= -100 then COLOR.RED
else COLOR.YELLOW);

#TOP Cycle Trader
input FastCycleLength = 5; #TOP
input SlowCycleLength = 8; #TOP

def FastVar = ExpAverage((H + L) / 2, FastCycleLength);
def SlowVar = Average((H + L) / 2, SlowCycleLength);
def DiffVar = FastVar - SlowVar;
def pDiffVar = DiffVar;
def pDiffVar2 = DiffVar;
def sTOP = if DiffVar > 0 then 100 else -100;
def sBullish_TOP = enableTOP and sTOP == 100;
def sBearish_TOP = enableTOP and sTOP == -100;
AddLabel(showlabels and enableTOP, "TOP", if IsNan(sTOP) then COLOR.DARK_GRAY else
if sTOP[-displace] > 0 then COLOR.GREEN else
if sTOP[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#DMITrend
input DMIlength = 13;

def hiDiff = high - high[1];
def loDiff = low[1] - low;
def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM =  if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
def ATRDMI = WildersAverage(TrueRange(high, close, low), DMIlength);
Def DIPlus = 100 * WildersAverage(plusDM, DMIlength) / ATRDMI;
Def DIMinus = 100 * WildersAverage(minusDM, DMIlength) / ATRDMI;
def sDMI = if DIPlus > DIMinus then 100 else if DIMinus > DIPlus then -100 else 0;
def sBullish_DMI = enableDMI and sDMI == 100;
def sBearish_DMI = enableDMI and sDMI == -100;
AddLabel(showlabels and enableDMI, "DMI", if IsNan(sDMI) then COLOR.DARK_GRAY else
if sDMI[-displace] > 0 then COLOR.GREEN else
if sDMI[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#BOP indicator
input averageType = {Simple, Exponential, default Weighted, Wilders, Hull,  Disabled};
input BoPlength = 16;

def rawBMP = if high != low then (close - open) / (high - low) else 1;
def BMP;
switch (averageType) {
case Simple:
    BMP = Average(rawBMP, BoPlength);
case Exponential:
    BMP = ExpAverage(rawBMP, BoPlength);
case Weighted:
    BMP = wma(rawBMP, BoPlength);
case Wilders:
    BMP = WildersAverage(rawBMP, BoPlength);
case Hull:
    BMP = HullMovingAvg(rawBMP, BoPlength);
case Disabled:
    BMP = rawBMP;
}
def sBOP = if BMP > 0 then 100 else -100;
def sBullish_BOP = enableBOP and sBOP == 100;
def sBearish_BOP = enableBOP and sBOP == -100;
AddLabel(showlabels and enableBOP, "BOP", if IsNan(sBOP) then COLOR.DARK_GRAY else
if sBOP[-displace] > 0 then COLOR.GREEN else
if sBOP[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

# SUPERTREND BY MOBIUS AND CCI ATR TREND COMBINED
input lengthCCI = 50;
input lengthATR = 21;
input AtrFactor = 1.0;
def pricedata = hl2;
def ATRcci = Average(TrueRange(h, c, l), lengthATR) * AtrFactor;
def price = c + l + h;
def linDev = LinDev(price, lengthCCI);
def CCI = if linDev == 0
          then 0
          else (price - Average(price, lengthCCI)) / linDev / 0.015;
def MT1 = if CCI > 0
          then Max(MT1[1], pricedata - ATRcci)
          else Min(MT1[1], pricedata + ATRcci);
def sSuperTrendCCIATR = if c < MT1 and c < ST then -100 else if C > MT1 and c >ST then 100 else 0;
def sBullish_SuperTrendCCIATR = enableSuperTrendCCIATR and sSuperTrendCCIATR == 100;
def sBearish_SuperTrendCCIATR = enableSuperTrendCCIATR and sSuperTrendCCIATR == -100;
AddLabel(showlabels and enableSuperTrendCCIATR, "SuperTrendCCI", if IsNan(sSuperTrendCCIATR) then COLOR.DARK_GRAY else
if sSuperTrendCCIATR[-displace] > 0 then COLOR.GREEN else
if sSuperTrendCCIATR[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));


# CCI + TTM squeeze + TTM trend
def CCIBuy = CCI(length = 14).CCI > 0 and CCI(length = 50).CCI > 0;
def CCISell = CCI(length = 14).CCI < 0 and CCI(length = 50).CCI < 0;
def sTrendUp = TTM_Trend().TrendUp;
def sTrendDn = TTM_Trend().TrendDown;
def SqueezeUp = TTM_Squeeze().Histogram >= 0;
def SqueezeDn = TTM_Squeeze().Histogram <= 0;
def Buy = CCIBuy and sTrendUp and SqueezeUp;
def Sell = CCISell and sTrendDn and SqueezeDn;
def sCCITTM = if buy then 100 else if sell then -100 else 0;
def sBullish_CCITTM = enableCCITTM and sCCITTM == 100;
def sBearish_CCITTM = enableCCITTM and sCCITTM == -100;
AddLabel(showlabels and enableCCITTM, "TTM CCI", if IsNan(sCCITTM) then COLOR.DARK_GRAY else
if sCCITTM[-displace] > 0 then COLOR.GREEN else
if sCCITTM[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#ADX TRENDING
input ADXlength = 8; #ADX
input ADXTrending = 25; #ADX
input showADXBar = yes;

def ADX = DMI(ADXlength).ADX;
plot ADXCross = LowestAll(low);
ADXCross.SetPaintingStrategy(PaintingStrategy.LINE);
ADXCross.AssignValueColor(
    if ADX > ADXTrending then Color.LIME
    else Color.DARK_GRAY);
ADXCross.SetLineWeight(5);
ADXCross.SetHiding(!showADXBar);

#MACD Neutal Eval
input fastLength_1 = 12;
input slowLength_1 = 26;
input MACDLength_1 = 9;
input AverageType_1 = {SMA, default EMA};
def macd_Val_1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Value;
def macd_Avg1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Avg;
def MACD_trig = if MACD().value > MACD().avg then 1 else 0;

AddLabel(showlabels,
if ADX > ADXTrending then "Trending" else
"Non Trending",
if IsNan(c) then COLOR.DARK_GRAY else
if ADX > ADXTrending then COLOR.GREEN else
COLOR.DARK_GRAY);

AddLabel(showlabels,
"MACD",
if IsNan(c) then COLOR.DARK_GRAY else
if macd_Val_1 > macd_Avg1 then COLOR.DARK_GREEN else
COLOR.DARK_RED);

#STATE
def sResults = sSuperTrend + sTMO + sTOP + sFrema + sTTM + sDMI + sBOP + sStateM1;
def sBullish = sBullish_TTM + sBullish_SuperTrend + sBullish_Frema + sBullish_TMO + sBullish_TOP + sBullish_DMI + sBullish_BOP + sBullish_SLIM + sBullish_SuperTrendCCIATR + sBullish_CCITTM;
def sBearish = sBearish_TTM + sBearish_SuperTrend + sBearish_Frema + sBearish_TMO + sBearish_TOP + sBearish_DMI + sBearish_BOP + sBearish_SLIM + sBearish_SuperTrendCCIATR + sBearish_CCITTM;
def bullish = if(sBullish >= threshold,1,0);
def bearish = if(sBearish >= threshold,1,0);
def sState = if bullish then 100 else if bearish then -100 else 0;
def sState2 = if sState != 0 then sState else sState2[1];

#COLORBARS
AssignPriceColor(
if PaintBars then
    if bullish then COLOR.GREEN else if bearish then COLOR.RED
     else
     if enableNeutralMACDPainter then
      if macd_Val_1 > macd_Avg1 then COLOR.DARK_GREEN else COLOR.DARK_RED
     else
    COLOR.GRAY
else COLOR.CURRENT);

AddLabel(showlabels,
if bullish[-displace] then "LONG" else
if bearish[-displace] then "SHORT"
else "HOLD",
if IsNan(c) then COLOR.DARK_GRAY else
if bullish[-displace] then COLOR.GREEN else
if bearish[-displace] then COLOR.RED
else COLOR.GRAY);

#END OF trend, a momentum and a cycle based indicator for ThinkorSwim V1.9
 
thanks Tom - yeah it's getting quite complex for sure ;) - Hopefully the community down selects to a few approaches/plans and then scanners can be customized based on the trading plan/style. It's an interesting experiment to see if this leads to viable edge.
Here is a strategy that I think would be effective if you can get it into order form.
Inputs: FREMA, SLIM, DMI, TTM CCI. Threshold = 3.
Buy = Candles are green (threshold met or MACD fill is green) and it is trending.
Sell Buy = Candles are red(threshold met or MACD fill is red) and it is trending
Short Sell = Candles are red(threshold met or MACD fill is red) and it is trending
Cover short = Candles are green (threshold met or MACD fill is green) and it is trending.
This can definitely be expanded on but this will be an amazing start. Diazlaz if you do this request I'll backtest to find the most practical and effective timeframe or tick count soon after.
Also as far as trending goes you would never open a position in a non-trending period and if you have a position open you would just hold, the goal is to capture as much of the price movement in as little as possible trades. I think this will succeed at that.
Here is a chart with the same inputs that would be used in the strategy on a SPY 1000 tick chart, feel free to mess with ticker and timeframe.
https://tos.mx/bCuHptZ
 
Here is a strategy that I think would be effective if you can get it into order form.
Inputs: FREMA, SLIM, DMI, TTM CCI. Threshold = 3.
Buy = Candles are green (threshold met or MACD fill is green) and it is trending.
Sell Buy = Candles are red(threshold met or MACD fill is red) and it is trending
Short Sell = Candles are red(threshold met or MACD fill is red) and it is trending
Cover short = Candles are green (threshold met or MACD fill is green) and it is trending.
This can definitely be expanded on but this will be an amazing start. Diazlaz if you do this request I'll backtest to find the most practical and effective timeframe or tick count soon after.
Also as far as trending goes you would never open a position in a non-trending period and if you have a position open you would just hold, the goal is to capture as much of the price movement in as little as possible trades. I think this will succeed at that.
Here is a chart with the same inputs that would be used in the strategy on a SPY 1000 tick chart, feel free to mess with ticker and timeframe.
https://tos.mx/bCuHptZ
sounds good @YungTraderFromMontana as requested a slimmer version - Version 2.0 for your backtest. thanks! looking forward to your results and feedback. let me know if you need any other changes or adjustments as you test.

Ruby:
#trend, a momentum and a cycle based indicator for ThinkorSwim V1.9
#@hockeycoachdoug Community Request
#
#VERSION
# 2020.01.13 V2.0 @diazlaz - Special Edition YungTraderFromMontana BackTest Edition
#                          - FREMA, SLIM, DMI, TTM CCI. Threshold = 3
# 2020.01.09 V1.9 @diazlaz - Integrated PaintBars MACD Neutral Condition trigger
#                          - set enableNeutralMACDPainter to yes (default is no) and
#                          - neutral gray will be evaluated by MACD (Dark Red/Green)
# 2020.01.09 V1.8 @diazlaz - Integrated Super Trend w/CCI and ATR
#                          - Integrated CCI + TTM squeeze + TTM trend Combo
#                          - Set treshold defaults to 7 (7 out of 10), removed scanmode.
# 2020.01.04 V1.7 @diazlaz - Integrated Slim Ribbon.
# 2020.01.02 V1.6 @diazlaz - Integrated DMI and BOP, restructured INPUTS to each module.
#                            threshold increased to 4 by default.
# 2020.01.01 V1.5 @diazlaz - Integrated ADX Trending States and BAR Line
# 2020.01.01 V1.4 @diazlaz - Integrated TTM Trends, modules selection
#                            and added threshold for signals
# 2019.12.31 V1.2 @diazlaz - Integrated FREMA
# 2019.12.30 V1.1 @diazlaz - Labels, Additional Dashboard, Lower Study
# 2019.12.30 V1.0 @diazlaz - Community Ask/Release
#
#LINK
#https://usethinkscript.com/threads/i-request-help-combining-3-indicators-into-1-paintbar-study.1390/
#
#INSTRUCTION
#Buy = Candles are green (threshold met or MACD fill is green) and it is trending.
#Sell Buy = Candles are red(threshold met or MACD fill is red) and it is trending
#Short Sell = Candles are red(threshold met or MACD fill is red) and it is trending
#Cover short = Candles are green (threshold met or MACD fill is green) and it is trending.
#
#Inputs: FREMA, SLIM, DMI, TTM CCI. Threshold = 3, enableNeutralMACDPainter set to yes
#

declare upper;

#INPUTS
input showLabels = yes;
input PaintBars = yes;
input enableNeutralMACDPainter = yes;

input threshold = 3;

input enableFrema = yes;
input enableSlim = yes;
input enableDMI = yes;
input enableCCITTM = yes;

input displace = 0;

#CORE
DefineGlobalColor("CycleLineColor", Color.RED);
DefineGlobalColor("CyclehistColor", Color.BLUE);
DefineGlobalColor("ZeroLineColor", Color.YELLOW);
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Neutral", Color.MAGENTA); #Color.YELLOW
DefineGlobalColor("Off", Color.DARK_GRAY);
DefineGlobalColor("On", Color.GREEN);
DefineGlobalColor("Sync1", Color.YELLOW);
DefineGlobalColor("Sync2", Color.CYAN);
DefineGlobalColor("Up", Color.GREEN);
DefineGlobalColor("Down", Color.RED);
DefineGlobalColor("NUp", Color.DARK_GREEN);
DefineGlobalColor("NDown", Color.DARK_RED);
DefineGlobalColor("Neutral", Color.BLUE);
DefineGlobalColor("Neutral2", Color.PLUM);

def h = high;
def l = low;
def o = open;
def c = close;
def na = Double.NaN;

AddLabel(showLabels, "A trend, momentum and cycle Trading System v2.0", Color.CYAN);

#FREMA
input AA = .1; #FREMA

def CC;
def zeroLine = 0;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;
CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2) * RE1 + RE1[1];
RE3 = Power(CC, 4) * RE2 + RE2[1];
RE4 = Power(CC, 8) * RE3 + RE3[1];
RE5 = Power(CC, 16) * RE4 + RE4[1];
RE6 = Power(CC, 32) * RE5 + RE5[1];
RE7 = Power(CC, 64) * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];
def EMA_Signal = EMA – AA * RE8;
def sFrema = if (EMA_Signal > zeroLine) then 100 else -100;
def sBullish_Frema = enableFrema and sFrema == 100;
def sBearish_Frema = enableFrema and sFrema == -100;
AddLabel(showlabels and enableFrema, "Frema", if IsNan(sFrema) then COLOR.DARK_GRAY else
if sFrema[-displace] > 0 then COLOR.GREEN else
if sFrema[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));


#SLIM
input sSuperFast = 8;
input sFast = 13;
input sSlow = 21;

def SuperFastM1 = ExpAverage(close[-displace], sSuperFast);
def FastM1 = ExpAverage(close[-displace], sFast);
def SlowM1 = ExpAverage(close[-displace], sSlow);
def buyM1 = SuperFastM1 > FastM1 and FastM1 > SlowM1 and low > SuperFastM1;
def stopbuyM1 = SuperFastM1 <= FastM1;
def buynowM1 = !buyM1[1] and buyM1;
def buysignalM1 = CompoundValue(1, if buynowM1 and !stopbuyM1 then 1
else if buysignalM1[1] == 1 and stopbuyM1 then 0 else buysignalM1[1], 0);
def Buy_SignalM1 = buysignalM1[1] == 0 and buysignalM1 == 1;
def Momentum_DownM1 = buysignalM1[1] == 1 and buysignalM1 == 0;
def sellM1 = SuperFastM1 < FastM1 and FastM1 < SlowM1 and high < SuperFastM1;
def stopsellM1 = SuperFastM1 >= FastM1;
def sellnowM1 = !sellM1[1] and sellM1;
def sellsignalM1 = CompoundValue(1, if sellnowM1 and !stopsellM1 then 1
else if sellsignalM1[1] == 1 and stopsellM1 then 0 else sellsignalM1[1], 0);
def Sell_SignalM1 = sellsignalM1[1] == 0 and sellsignalM1;
def Momentum_UpM1 = sellsignalM1[1] == 1 and sellsignalM1 == 0;
def sStateM1 = if Buy_SignalM1 then 100 else if Momentum_UpM1 then 10 else if Sell_SignalM1 then -100 else if Momentum_DownM1 then -10 else sStateM1[1];
def sBullish_SLIM = enableSLIM and sStateM1 == 100;
def sBearish_SLIM = enableSLIM and sStateM1 == -100;
AddLabel(showlabels and enableSLIM, "SLIM", if IsNan(sStateM1) then COLOR.DARK_GRAY else
if sStateM1[-displace] >= 100 then COLOR.GREEN else
if sStateM1[-displace] <= -100 then COLOR.RED
else COLOR.YELLOW);

#DMITrend
input DMIlength = 13;

def hiDiff = high - high[1];
def loDiff = low[1] - low;
def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM =  if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
def ATRDMI = WildersAverage(TrueRange(high, close, low), DMIlength);
Def DIPlus = 100 * WildersAverage(plusDM, DMIlength) / ATRDMI;
Def DIMinus = 100 * WildersAverage(minusDM, DMIlength) / ATRDMI;
def sDMI = if DIPlus > DIMinus then 100 else if DIMinus > DIPlus then -100 else 0;
def sBullish_DMI = enableDMI and sDMI == 100;
def sBearish_DMI = enableDMI and sDMI == -100;
AddLabel(showlabels and enableDMI, "DMI", if IsNan(sDMI) then COLOR.DARK_GRAY else
if sDMI[-displace] > 0 then COLOR.GREEN else
if sDMI[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

# CCI + TTM squeeze + TTM trend
def CCIBuy = CCI(length = 14).CCI > 0 and CCI(length = 50).CCI > 0;
def CCISell = CCI(length = 14).CCI < 0 and CCI(length = 50).CCI < 0;
def sTrendUp = TTM_Trend().TrendUp;
def sTrendDn = TTM_Trend().TrendDown;
def SqueezeUp = TTM_Squeeze().Histogram >= 0;
def SqueezeDn = TTM_Squeeze().Histogram <= 0;
def Buy = CCIBuy and sTrendUp and SqueezeUp;
def Sell = CCISell and sTrendDn and SqueezeDn;
def sCCITTM = if buy then 100 else if sell then -100 else 0;
def sBullish_CCITTM = enableCCITTM and sCCITTM == 100;
def sBearish_CCITTM = enableCCITTM and sCCITTM == -100;
AddLabel(showlabels and enableCCITTM, "TTM CCI", if IsNan(sCCITTM) then COLOR.DARK_GRAY else
if sCCITTM[-displace] > 0 then COLOR.GREEN else
if sCCITTM[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#ADX TRENDING
input ADXlength = 8; #ADX
input ADXTrending = 25; #ADX
input showADXBar = yes;

def ADX = DMI(ADXlength).ADX;
plot ADXCross = LowestAll(low);
ADXCross.SetPaintingStrategy(PaintingStrategy.LINE);
ADXCross.AssignValueColor(
    if ADX > ADXTrending then Color.LIME
    else Color.DARK_GRAY);
ADXCross.SetLineWeight(5);
ADXCross.SetHiding(!showADXBar);

#MACD Evaluation
input fastLength_1 = 12;
input slowLength_1 = 26;
input MACDLength_1 = 9;
input AverageType_1 = {SMA, default EMA};
def macd_Val_1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Value;
def macd_Avg1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Avg;
def MACD_trig = if MACD().value > MACD().avg then 1 else 0;

AddLabel(showlabels,
if ADX > ADXTrending then "Trending" else
"Non Trending",
if IsNan(c) then COLOR.DARK_GRAY else
if ADX > ADXTrending then COLOR.GREEN else
COLOR.DARK_GRAY);

AddLabel(showlabels,
"MACD",
if IsNan(c) then COLOR.DARK_GRAY else
if macd_Val_1 > macd_Avg1 then COLOR.DARK_GREEN else
COLOR.DARK_RED);

#STATE
def sResults = sFrema + sDMI + sStateM1;
def sBullish = sBullish_Frema + sBullish_DMI + sBullish_SLIM + sBullish_CCITTM;
def sBearish = sBearish_Frema + sBearish_DMI + sBearish_SLIM + sBearish_CCITTM;
def bullish = if(sBullish >= threshold,1,0);
def bearish = if(sBearish >= threshold,1,0);
def sState = if bullish then 100 else if bearish then -100 else 0;
def sState2 = if sState != 0 then sState else sState2[1];

#COLORBARS
AssignPriceColor(
if PaintBars then
    if bullish then COLOR.GREEN else if bearish then COLOR.RED
     else
     if enableNeutralMACDPainter then
      if macd_Val_1 > macd_Avg1 then COLOR.DARK_GREEN else COLOR.DARK_RED
     else
    COLOR.GRAY
else COLOR.CURRENT);

AddLabel(showlabels,
if bullish[-displace] then "LONG" else
if bearish[-displace] then "SHORT"
else "HOLD",
if IsNan(c) then COLOR.DARK_GRAY else
if bullish[-displace] then COLOR.GREEN else
if bearish[-displace] then COLOR.RED
else COLOR.GRAY);

#END OF trend, a momentum and a cycle based indicator for ThinkorSwim V2.0
 
sounds good @YungTraderFromMontana as requested a slimmer version - Version 2.0 for your backtest. thanks! looking forward to your results and feedback. let me know if you need any other changes or adjustments as you test.

Ruby:
#trend, a momentum and a cycle based indicator for ThinkorSwim V1.9
#@hockeycoachdoug Community Request
#
#VERSION
# 2020.01.13 V2.0 @diazlaz - Special Edition YungTraderFromMontana BackTest Edition
#                          - FREMA, SLIM, DMI, TTM CCI. Threshold = 3
# 2020.01.09 V1.9 @diazlaz - Integrated PaintBars MACD Neutral Condition trigger
#                          - set enableNeutralMACDPainter to yes (default is no) and
#                          - neutral gray will be evaluated by MACD (Dark Red/Green)
# 2020.01.09 V1.8 @diazlaz - Integrated Super Trend w/CCI and ATR
#                          - Integrated CCI + TTM squeeze + TTM trend Combo
#                          - Set treshold defaults to 7 (7 out of 10), removed scanmode.
# 2020.01.04 V1.7 @diazlaz - Integrated Slim Ribbon.
# 2020.01.02 V1.6 @diazlaz - Integrated DMI and BOP, restructured INPUTS to each module.
#                            threshold increased to 4 by default.
# 2020.01.01 V1.5 @diazlaz - Integrated ADX Trending States and BAR Line
# 2020.01.01 V1.4 @diazlaz - Integrated TTM Trends, modules selection
#                            and added threshold for signals
# 2019.12.31 V1.2 @diazlaz - Integrated FREMA
# 2019.12.30 V1.1 @diazlaz - Labels, Additional Dashboard, Lower Study
# 2019.12.30 V1.0 @diazlaz - Community Ask/Release
#
#LINK
#https://usethinkscript.com/threads/i-request-help-combining-3-indicators-into-1-paintbar-study.1390/
#
#INSTRUCTION
#Buy = Candles are green (threshold met or MACD fill is green) and it is trending.
#Sell Buy = Candles are red(threshold met or MACD fill is red) and it is trending
#Short Sell = Candles are red(threshold met or MACD fill is red) and it is trending
#Cover short = Candles are green (threshold met or MACD fill is green) and it is trending.
#
#Inputs: FREMA, SLIM, DMI, TTM CCI. Threshold = 3, enableNeutralMACDPainter set to yes
#

declare upper;

#INPUTS
input showLabels = yes;
input PaintBars = yes;
input enableNeutralMACDPainter = yes;

input threshold = 3;

input enableFrema = yes;
input enableSlim = yes;
input enableDMI = yes;
input enableCCITTM = yes;

input displace = 0;

#CORE
DefineGlobalColor("CycleLineColor", Color.RED);
DefineGlobalColor("CyclehistColor", Color.BLUE);
DefineGlobalColor("ZeroLineColor", Color.YELLOW);
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Neutral", Color.MAGENTA); #Color.YELLOW
DefineGlobalColor("Off", Color.DARK_GRAY);
DefineGlobalColor("On", Color.GREEN);
DefineGlobalColor("Sync1", Color.YELLOW);
DefineGlobalColor("Sync2", Color.CYAN);
DefineGlobalColor("Up", Color.GREEN);
DefineGlobalColor("Down", Color.RED);
DefineGlobalColor("NUp", Color.DARK_GREEN);
DefineGlobalColor("NDown", Color.DARK_RED);
DefineGlobalColor("Neutral", Color.BLUE);
DefineGlobalColor("Neutral2", Color.PLUM);

def h = high;
def l = low;
def o = open;
def c = close;
def na = Double.NaN;

AddLabel(showLabels, "A trend, momentum and cycle Trading System v2.0", Color.CYAN);

#FREMA
input AA = .1; #FREMA

def CC;
def zeroLine = 0;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;
CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2) * RE1 + RE1[1];
RE3 = Power(CC, 4) * RE2 + RE2[1];
RE4 = Power(CC, 8) * RE3 + RE3[1];
RE5 = Power(CC, 16) * RE4 + RE4[1];
RE6 = Power(CC, 32) * RE5 + RE5[1];
RE7 = Power(CC, 64) * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];
def EMA_Signal = EMA – AA * RE8;
def sFrema = if (EMA_Signal > zeroLine) then 100 else -100;
def sBullish_Frema = enableFrema and sFrema == 100;
def sBearish_Frema = enableFrema and sFrema == -100;
AddLabel(showlabels and enableFrema, "Frema", if IsNan(sFrema) then COLOR.DARK_GRAY else
if sFrema[-displace] > 0 then COLOR.GREEN else
if sFrema[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));


#SLIM
input sSuperFast = 8;
input sFast = 13;
input sSlow = 21;

def SuperFastM1 = ExpAverage(close[-displace], sSuperFast);
def FastM1 = ExpAverage(close[-displace], sFast);
def SlowM1 = ExpAverage(close[-displace], sSlow);
def buyM1 = SuperFastM1 > FastM1 and FastM1 > SlowM1 and low > SuperFastM1;
def stopbuyM1 = SuperFastM1 <= FastM1;
def buynowM1 = !buyM1[1] and buyM1;
def buysignalM1 = CompoundValue(1, if buynowM1 and !stopbuyM1 then 1
else if buysignalM1[1] == 1 and stopbuyM1 then 0 else buysignalM1[1], 0);
def Buy_SignalM1 = buysignalM1[1] == 0 and buysignalM1 == 1;
def Momentum_DownM1 = buysignalM1[1] == 1 and buysignalM1 == 0;
def sellM1 = SuperFastM1 < FastM1 and FastM1 < SlowM1 and high < SuperFastM1;
def stopsellM1 = SuperFastM1 >= FastM1;
def sellnowM1 = !sellM1[1] and sellM1;
def sellsignalM1 = CompoundValue(1, if sellnowM1 and !stopsellM1 then 1
else if sellsignalM1[1] == 1 and stopsellM1 then 0 else sellsignalM1[1], 0);
def Sell_SignalM1 = sellsignalM1[1] == 0 and sellsignalM1;
def Momentum_UpM1 = sellsignalM1[1] == 1 and sellsignalM1 == 0;
def sStateM1 = if Buy_SignalM1 then 100 else if Momentum_UpM1 then 10 else if Sell_SignalM1 then -100 else if Momentum_DownM1 then -10 else sStateM1[1];
def sBullish_SLIM = enableSLIM and sStateM1 == 100;
def sBearish_SLIM = enableSLIM and sStateM1 == -100;
AddLabel(showlabels and enableSLIM, "SLIM", if IsNan(sStateM1) then COLOR.DARK_GRAY else
if sStateM1[-displace] >= 100 then COLOR.GREEN else
if sStateM1[-displace] <= -100 then COLOR.RED
else COLOR.YELLOW);

#DMITrend
input DMIlength = 13;

def hiDiff = high - high[1];
def loDiff = low[1] - low;
def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM =  if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
def ATRDMI = WildersAverage(TrueRange(high, close, low), DMIlength);
Def DIPlus = 100 * WildersAverage(plusDM, DMIlength) / ATRDMI;
Def DIMinus = 100 * WildersAverage(minusDM, DMIlength) / ATRDMI;
def sDMI = if DIPlus > DIMinus then 100 else if DIMinus > DIPlus then -100 else 0;
def sBullish_DMI = enableDMI and sDMI == 100;
def sBearish_DMI = enableDMI and sDMI == -100;
AddLabel(showlabels and enableDMI, "DMI", if IsNan(sDMI) then COLOR.DARK_GRAY else
if sDMI[-displace] > 0 then COLOR.GREEN else
if sDMI[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

# CCI + TTM squeeze + TTM trend
def CCIBuy = CCI(length = 14).CCI > 0 and CCI(length = 50).CCI > 0;
def CCISell = CCI(length = 14).CCI < 0 and CCI(length = 50).CCI < 0;
def sTrendUp = TTM_Trend().TrendUp;
def sTrendDn = TTM_Trend().TrendDown;
def SqueezeUp = TTM_Squeeze().Histogram >= 0;
def SqueezeDn = TTM_Squeeze().Histogram <= 0;
def Buy = CCIBuy and sTrendUp and SqueezeUp;
def Sell = CCISell and sTrendDn and SqueezeDn;
def sCCITTM = if buy then 100 else if sell then -100 else 0;
def sBullish_CCITTM = enableCCITTM and sCCITTM == 100;
def sBearish_CCITTM = enableCCITTM and sCCITTM == -100;
AddLabel(showlabels and enableCCITTM, "TTM CCI", if IsNan(sCCITTM) then COLOR.DARK_GRAY else
if sCCITTM[-displace] > 0 then COLOR.GREEN else
if sCCITTM[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#ADX TRENDING
input ADXlength = 8; #ADX
input ADXTrending = 25; #ADX
input showADXBar = yes;

def ADX = DMI(ADXlength).ADX;
plot ADXCross = LowestAll(low);
ADXCross.SetPaintingStrategy(PaintingStrategy.LINE);
ADXCross.AssignValueColor(
    if ADX > ADXTrending then Color.LIME
    else Color.DARK_GRAY);
ADXCross.SetLineWeight(5);
ADXCross.SetHiding(!showADXBar);

#MACD Evaluation
input fastLength_1 = 12;
input slowLength_1 = 26;
input MACDLength_1 = 9;
input AverageType_1 = {SMA, default EMA};
def macd_Val_1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Value;
def macd_Avg1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Avg;
def MACD_trig = if MACD().value > MACD().avg then 1 else 0;

AddLabel(showlabels,
if ADX > ADXTrending then "Trending" else
"Non Trending",
if IsNan(c) then COLOR.DARK_GRAY else
if ADX > ADXTrending then COLOR.GREEN else
COLOR.DARK_GRAY);

AddLabel(showlabels,
"MACD",
if IsNan(c) then COLOR.DARK_GRAY else
if macd_Val_1 > macd_Avg1 then COLOR.DARK_GREEN else
COLOR.DARK_RED);

#STATE
def sResults = sFrema + sDMI + sStateM1;
def sBullish = sBullish_Frema + sBullish_DMI + sBullish_SLIM + sBullish_CCITTM;
def sBearish = sBearish_Frema + sBearish_DMI + sBearish_SLIM + sBearish_CCITTM;
def bullish = if(sBullish >= threshold,1,0);
def bearish = if(sBearish >= threshold,1,0);
def sState = if bullish then 100 else if bearish then -100 else 0;
def sState2 = if sState != 0 then sState else sState2[1];

#COLORBARS
AssignPriceColor(
if PaintBars then
    if bullish then COLOR.GREEN else if bearish then COLOR.RED
     else
     if enableNeutralMACDPainter then
      if macd_Val_1 > macd_Avg1 then COLOR.DARK_GREEN else COLOR.DARK_RED
     else
    COLOR.GRAY
else COLOR.CURRENT);

AddLabel(showlabels,
if bullish[-displace] then "LONG" else
if bearish[-displace] then "SHORT"
else "HOLD",
if IsNan(c) then COLOR.DARK_GRAY else
if bullish[-displace] then COLOR.GREEN else
if bearish[-displace] then COLOR.RED
else COLOR.GRAY);

#END OF trend, a momentum and a cycle based indicator for ThinkorSwim V2.0
Sorry for the complete dependence on you but I honestly don't know how to code this strategy. Can you refer to my instructions and make the conditions adequate for thinkscript (meaning put the instructions for entrys and exits in code form. Here is the code you just posted but with orders where you can plug in buy and sell conditions. Although tos's backtests aren't 100% accurate, it would be a good way to make improvements and see immediate results in a backtest report. I think I'll start a separate thread once I perfect this strategy looking for suggestions and feedback from the community. Thanks so much for the help and quick responses.
Code:
#trend, a momentum and a cycle based indicator for ThinkorSwim V1.9
#@hockeycoachdoug Community Request
#
#VERSION
# 2020.01.13 V2.0 @diazlaz - Special Edition YungTraderFromMontana BackTest Edition
#                          - FREMA, SLIM, DMI, TTM CCI. Threshold = 3
# 2020.01.09 V1.9 @diazlaz - Integrated PaintBars MACD Neutral Condition trigger
#                          - set enableNeutralMACDPainter to yes (default is no) and
#                          - neutral gray will be evaluated by MACD (Dark Red/Green)
# 2020.01.09 V1.8 @diazlaz - Integrated Super Trend w/CCI and ATR
#                          - Integrated CCI + TTM squeeze + TTM trend Combo
#                          - Set treshold defaults to 7 (7 out of 10), removed scanmode.
# 2020.01.04 V1.7 @diazlaz - Integrated Slim Ribbon.
# 2020.01.02 V1.6 @diazlaz - Integrated DMI and BOP, restructured INPUTS to each module.
#                            threshold increased to 4 by default.
# 2020.01.01 V1.5 @diazlaz - Integrated ADX Trending States and BAR Line
# 2020.01.01 V1.4 @diazlaz - Integrated TTM Trends, modules selection
#                            and added threshold for signals
# 2019.12.31 V1.2 @diazlaz - Integrated FREMA
# 2019.12.30 V1.1 @diazlaz - Labels, Additional Dashboard, Lower Study
# 2019.12.30 V1.0 @diazlaz - Community Ask/Release
#
#LINK
#https://usethinkscript.com/threads/i-request-help-combining-3-indicators-into-1-paintbar-study.1390/
#
#INSTRUCTION
#Buy = Candles are green (threshold met or MACD fill is green) and it is trending.
#Sell Buy = Candles are red(threshold met or MACD fill is red) and it is trending
#Short Sell = Candles are red(threshold met or MACD fill is red) and it is trending
#Cover short = Candles are green (threshold met or MACD fill is green) and it is trending.
#
#Inputs: FREMA, SLIM, DMI, TTM CCI. Threshold = 3, enableNeutralMACDPainter set to yes
#

declare upper;

#INPUTS
input showLabels = yes;
input PaintBars = yes;
input enableNeutralMACDPainter = yes;

input threshold = 3;

input enableFrema = yes;
input enableSlim = yes;
input enableDMI = yes;
input enableCCITTM = yes;

input displace = 0;

#CORE
DefineGlobalColor("CycleLineColor", Color.RED);
DefineGlobalColor("CyclehistColor", Color.BLUE);
DefineGlobalColor("ZeroLineColor", Color.YELLOW);
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Neutral", Color.MAGENTA); #Color.YELLOW
DefineGlobalColor("Off", Color.DARK_GRAY);
DefineGlobalColor("On", Color.GREEN);
DefineGlobalColor("Sync1", Color.YELLOW);
DefineGlobalColor("Sync2", Color.CYAN);
DefineGlobalColor("Up", Color.GREEN);
DefineGlobalColor("Down", Color.RED);
DefineGlobalColor("NUp", Color.DARK_GREEN);
DefineGlobalColor("NDown", Color.DARK_RED);
DefineGlobalColor("Neutral", Color.BLUE);
DefineGlobalColor("Neutral2", Color.PLUM);

def h = high;
def l = low;
def o = open;
def c = close;
def na = Double.NaN;

AddLabel(showLabels, "A trend, momentum and cycle Trading System v2.0", Color.CYAN);

#FREMA
input AA = .1; #FREMA

def CC;
def zeroLine = 0;
def RE1;
def RE2;
def RE3;
def RE4;
def RE5;
def RE6;
def RE7;
def RE8;
def EMA;
CC = if CC[1] == 0 then .9 else 1 – AA;
EMA = AA * close + CC * EMA[1];
RE1 = CC * EMA + EMA[1];
RE2 = Power(CC, 2) * RE1 + RE1[1];
RE3 = Power(CC, 4) * RE2 + RE2[1];
RE4 = Power(CC, 8) * RE3 + RE3[1];
RE5 = Power(CC, 16) * RE4 + RE4[1];
RE6 = Power(CC, 32) * RE5 + RE5[1];
RE7 = Power(CC, 64) * RE6 + RE6[1];
RE8 = Power(CC, 128) * RE7 + RE7[1];
def EMA_Signal = EMA – AA * RE8;
def sFrema = if (EMA_Signal > zeroLine) then 100 else -100;
def sBullish_Frema = enableFrema and sFrema == 100;
def sBearish_Frema = enableFrema and sFrema == -100;
AddLabel(showlabels and enableFrema, "Frema", if IsNan(sFrema) then COLOR.DARK_GRAY else
if sFrema[-displace] > 0 then COLOR.GREEN else
if sFrema[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));


#SLIM
input sSuperFast = 8;
input sFast = 13;
input sSlow = 21;

def SuperFastM1 = ExpAverage(close[-displace], sSuperFast);
def FastM1 = ExpAverage(close[-displace], sFast);
def SlowM1 = ExpAverage(close[-displace], sSlow);
def buyM1 = SuperFastM1 > FastM1 and FastM1 > SlowM1 and low > SuperFastM1;
def stopbuyM1 = SuperFastM1 <= FastM1;
def buynowM1 = !buyM1[1] and buyM1;
def buysignalM1 = CompoundValue(1, if buynowM1 and !stopbuyM1 then 1
else if buysignalM1[1] == 1 and stopbuyM1 then 0 else buysignalM1[1], 0);
def Buy_SignalM1 = buysignalM1[1] == 0 and buysignalM1 == 1;
def Momentum_DownM1 = buysignalM1[1] == 1 and buysignalM1 == 0;
def sellM1 = SuperFastM1 < FastM1 and FastM1 < SlowM1 and high < SuperFastM1;
def stopsellM1 = SuperFastM1 >= FastM1;
def sellnowM1 = !sellM1[1] and sellM1;
def sellsignalM1 = CompoundValue(1, if sellnowM1 and !stopsellM1 then 1
else if sellsignalM1[1] == 1 and stopsellM1 then 0 else sellsignalM1[1], 0);
def Sell_SignalM1 = sellsignalM1[1] == 0 and sellsignalM1;
def Momentum_UpM1 = sellsignalM1[1] == 1 and sellsignalM1 == 0;
def sStateM1 = if Buy_SignalM1 then 100 else if Momentum_UpM1 then 10 else if Sell_SignalM1 then -100 else if Momentum_DownM1 then -10 else sStateM1[1];
def sBullish_SLIM = enableSLIM and sStateM1 == 100;
def sBearish_SLIM = enableSLIM and sStateM1 == -100;
AddLabel(showlabels and enableSLIM, "SLIM", if IsNan(sStateM1) then COLOR.DARK_GRAY else
if sStateM1[-displace] >= 100 then COLOR.GREEN else
if sStateM1[-displace] <= -100 then COLOR.RED
else COLOR.YELLOW);

#DMITrend
input DMIlength = 13;

def hiDiff = high - high[1];
def loDiff = low[1] - low;
def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM =  if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
def ATRDMI = WildersAverage(TrueRange(high, close, low), DMIlength);
Def DIPlus = 100 * WildersAverage(plusDM, DMIlength) / ATRDMI;
Def DIMinus = 100 * WildersAverage(minusDM, DMIlength) / ATRDMI;
def sDMI = if DIPlus > DIMinus then 100 else if DIMinus > DIPlus then -100 else 0;
def sBullish_DMI = enableDMI and sDMI == 100;
def sBearish_DMI = enableDMI and sDMI == -100;
AddLabel(showlabels and enableDMI, "DMI", if IsNan(sDMI) then COLOR.DARK_GRAY else
if sDMI[-displace] > 0 then COLOR.GREEN else
if sDMI[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

# CCI + TTM squeeze + TTM trend
def CCIBuy = CCI(length = 14).CCI > 0 and CCI(length = 50).CCI > 0;
def CCISell = CCI(length = 14).CCI < 0 and CCI(length = 50).CCI < 0;
def sTrendUp = TTM_Trend().TrendUp;
def sTrendDn = TTM_Trend().TrendDown;
def SqueezeUp = TTM_Squeeze().Histogram >= 0;
def SqueezeDn = TTM_Squeeze().Histogram <= 0;
def Buy = CCIBuy and sTrendUp and SqueezeUp;
def Sell = CCISell and sTrendDn and SqueezeDn;
def sCCITTM = if buy then 100 else if sell then -100 else 0;
def sBullish_CCITTM = enableCCITTM and sCCITTM == 100;
def sBearish_CCITTM = enableCCITTM and sCCITTM == -100;
AddLabel(showlabels and enableCCITTM, "TTM CCI", if IsNan(sCCITTM) then COLOR.DARK_GRAY else
if sCCITTM[-displace] > 0 then COLOR.GREEN else
if sCCITTM[-displace] < 0 then COLOR.RED
else GlobalColor("Off"));

#ADX TRENDING
input ADXlength = 8; #ADX
input ADXTrending = 25; #ADX
input showADXBar = yes;

def ADX = DMI(ADXlength).ADX;
plot ADXCross = LowestAll(low);
ADXCross.SetPaintingStrategy(PaintingStrategy.LINE);
ADXCross.AssignValueColor(
    if ADX > ADXTrending then Color.LIME
    else Color.DARK_GRAY);
ADXCross.SetLineWeight(5);
ADXCross.SetHiding(!showADXBar);

#MACD Evaluation
input fastLength_1 = 12;
input slowLength_1 = 26;
input MACDLength_1 = 9;
input AverageType_1 = {SMA, default EMA};
def macd_Val_1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Value;
def macd_Avg1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Avg;
def MACD_trig = if MACD().value > MACD().avg then 1 else 0;

AddLabel(showlabels,
if ADX > ADXTrending then "Trending" else
"Non Trending",
if IsNan(c) then COLOR.DARK_GRAY else
if ADX > ADXTrending then COLOR.GREEN else
COLOR.DARK_GRAY);

AddLabel(showlabels,
"MACD",
if IsNan(c) then COLOR.DARK_GRAY else
if macd_Val_1 > macd_Avg1 then COLOR.DARK_GREEN else
COLOR.DARK_RED);

#STATE
def sResults = sFrema + sDMI + sStateM1;
def sBullish = sBullish_Frema + sBullish_DMI + sBullish_SLIM + sBullish_CCITTM;
def sBearish = sBearish_Frema + sBearish_DMI + sBearish_SLIM + sBearish_CCITTM;
def bullish = if(sBullish >= threshold,1,0);
def bearish = if(sBearish >= threshold,1,0);
def sState = if bullish then 100 else if bearish then -100 else 0;
def sState2 = if sState != 0 then sState else sState2[1];

#COLORBARS
AssignPriceColor(
if PaintBars then
    if bullish then COLOR.GREEN else if bearish then COLOR.RED
     else
     if enableNeutralMACDPainter then
      if macd_Val_1 > macd_Avg1 then COLOR.DARK_GREEN else COLOR.DARK_RED
     else
    COLOR.GRAY
else COLOR.CURRENT);

AddLabel(showlabels,
if bullish[-displace] then "LONG" else
if bearish[-displace] then "SHORT"
else "HOLD",
if IsNan(c) then COLOR.DARK_GRAY else
if bullish[-displace] then COLOR.GREEN else
if bearish[-displace] then COLOR.RED
else COLOR.GRAY);

# Bullish Orders
AddOrder(OrderType.BUY_TO_OPEN, condition = (Fill here) , price = close, 100, tickcolor = Color.GREEN, arrowcolor = Color.GREEN);
AddOrder(OrderType.SELL_TO_CLOSE, condition =  , price = open, 100, tickcolor = Color.RED, arrowcolor = Color.RED);

# Bearish Orders
AddOrder(OrderType.SELL_TO_OPEN, condition =   , price = open, 100, tickcolor = Color.RED, arrowcolor = Color.RED);
AddOrder(OrderType.BUY_TO_CLOSE, condition =   , price = close, 100, tickcolor = Color.GREEN, arrowcolor = Color.GREEN);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
565 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top