I request combining 3 indicators into 1 paintbar study

Status
Not open for further replies.

hockeycoachdoug

Active member
2019 Donor
VIP
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:
Solution
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
#...

YungTraderFromMontana

Well-known member
Here is the strategy portion, copy the latest version and append the following code to make it into a strategy. please remember threshold, the indicators that are enabled and the MACD neutral evaluation and timeframes all will effect the strategy in the back test.

The strategy will go long and short on the positions leveraging the auto buy and sell auto order. please share your results and findings. Have fun this long holiday weekend testing various combinations.

oHQZdij.png


Ruby:
#STRATEGY
def SS = if bullish then 100 else if bearish then -100 else if enableNeutralMACDPainter
then if macd_Val_1 > macd_Avg1 then 10 else -10 else 0;

def sBuy = SS crosses above 0;
def sSell = SS crosses below 0;

AddOrder(OrderType.BUY_AUTO, condition = Sbuy
, price =  open[-1], 1000, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "BE");

AddOrder(OrderType.SELL_AUTO, condition = sSell
, price = open[-1], 1000, tickcolor = Color.RED, arrowcolor = Color.RED, name = "SE");
After testing all of these nothing beats this, looks insanely profitable.
https://tos.mx/Qg1zQKSsometimes simple is best.
 

YungTraderFromMontana

Well-known member
Amazing work... will test this further. Let me know if you want to see any other adjustments or implementations.

Since MTF's are involved, we need to see how it all plays out in live markets, but you're defiantly on to something here.
I'll live test for a few hours next week, I think our best next step is to find a better determination of trending. The adx becomes difficult to use on smaller timeframes. I'm gonna make a new thread and take suggestions from the community, thanks for all your help and also thank you @HighBredCloud for the amazing suggestion.
 

HighBredCloud

Well-known member
@diazlaz can you please check IF the Mobius Heikin Ashi SuperTrend is working correctly because after turning everything off except for that particular HA SuperTrend I received different results. Please see below. On the right is the original Mobius Heikin Ashi Supertrend and on the left is the one found in the 2.1 version. Not sure if there is anything missing from original script...thanks.

KCD6x8o.png
 

diazlaz

Well-known member
2019 Donor
VIP
Hi @HighBredCloud

D9Bj7WU.png


ok - here is why the difference:

when I ported over the original indicator, I notice a potential bug in the original port, and I attempted to correct it. know not sure if it's a big or not, but welcome the feedback and review from the community.

the original port utilize the close price not the HACLOSE for the following pieces of the calculation. I corrected it to use the haclose. notice these lines in the original code:

AsKwyKT.png


i replaced close with haclose, it made a small difference.

then the other change is that the original script input for AtrMult is .70, in the CSA script it defaults to 1.0. if you make the AtrMult the same and revert back to the close instead to haclose is identical.

Welcome feedback on the behavior? keep it as close or haclose and what default AtrMult should we be using?
 

diazlaz

Well-known member
2019 Donor
VIP
Here is another example using SPY 1D/1M.

The graph on the left is using the regular close price, the one on the right is using the haclose. I find the one in the right is smoother and tends to produce less signals and whipsaw moves.

q0Vgxnu.png


thoughts?
 

horserider

Well-known member
VIP
@diazlaz I commend you on your patience and coding. If you wish to try the ADX code below and see if it improves the current code have at it. I have not tested if it does or not as I do not use this study at all. Just took a look at it to see why all the interest and thought I read somewhere of a complaint the ADX bar was not working as they wished.

Code:
#ADX TRENDING 

input DI_length = 8;
input ADX_length = 8;
input ADXTrending = 25; #ADX
input showADXBar = yes;

def DX = if (diplus(di_length) + diminus(di_length) > 0) then 100 * AbsValue(diplus(di_length) - diminus(di_length)) / (diplus(di_length) + diminus(di_length)) else 0;
def ADX = WildersAverage(DX, adx_length);

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

YungTraderFromMontana

Well-known member
@diazlaz can we make a second study but include scripts meant to determine trending periods from consolidation periods. We can see where they overlap and ideally find more accurate readings. The same threshold concept and all, just with indicators like the adx bar. I'm gonna look around for these type of studies today.
 

diazlaz

Well-known member
2019 Donor
VIP
@diazlaz I commend you on your patience and coding. If you wish to try the ADX code below and see if it improves the current code have at it. I have not tested if it does or not as I do not use this study at all. Just took a look at it to see why all the interest and thought I read somewhere of a complaint the ADX bar was not working as they wished.

Code:
#ADX TRENDING

input DI_length = 8;
input ADX_length = 8;
input ADXTrending = 25; #ADX
input showADXBar = yes;

def DX = if (diplus(di_length) + diminus(di_length) > 0) then 100 * AbsValue(diplus(di_length) - diminus(di_length)) / (diplus(di_length) + diminus(di_length)) else 0;
def ADX = WildersAverage(DX, adx_length);

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);
Thanks @horserider for the tip and update, will look at it this evening.
 

diazlaz

Well-known member
2019 Donor
VIP
@diazlaz can we make a second study but include scripts meant to determine trending periods from consolidation periods. We can see where they overlap and ideally find more accurate readings. The same threshold concept and all, just with indicators like the adx bar. I'm gonna look around for these type of studies today.
Sure provide me with a specification and we can try
 

dolomick

Member
There is one mtf, if it's not used there is no lag. I know it seems like a lot of work to end up with using one of the inputs but this whole thing was an experiment.
Has no one suggested adding RSI to this? Kind of surprising. I find SMI incredibly useful myself, although it gives fairly similar signals to TMO. So far /ES on the four minute does surprisingly well compared to all other sub five minute timeframes. Here is my preferred setup for using it on the /ES (only backtesting, haven't used live). This does not use MTF so hopefully would not repaint.

https://tos.mx/O9KJB5b
My chart shows P&L for twenty days, 4 minute timeframe. Trading two contracts yields $19,200K with one red day of about $560 dollars near the beginning. Seems like a threshold of 3-4 works best most of the time. On a related note, does anyone have a simple MA crossover strategy chart they could share that I could compare this to?
 

YungTraderFromMontana

Well-known member
Has no one suggested adding RSI to this? Kind of surprising. I find SMI incredibly useful myself, although it gives fairly similar signals to TMO. So far /ES on the four minute does surprisingly well compared to all other sub five minute timeframes. Here is my preferred setup for using it on the /ES (only backtesting, haven't used live). This does not use MTF so hopefully would not repaint.

https://tos.mx/O9KJB5b
My chart shows P&L for twenty days, 4 minute timeframe. Trading two contracts yields $19,200K with one red day of about $560 dollars near the beginning. Seems like a threshold of 3-4 works best most of the time. On a related note, does anyone have a simple MA crossover strategy chart they could share that I could compare this to?
Yes, no repaint on this combo. That is the best p/l I've ever seen come from this study. Nice work, it is steady growth too. No simple ma study on the 4 minute would ever beat that.
 
Last edited:

J007RMC

Well-known member
2019 Donor
With all the updates to this script can one say this holds true
1min chart - 5 min aggregation
3min chart - 15 min aggregation
5min chart - around 30min aggregation
15min chart - around 1 hour aggregation
edit: as chart timeframe goes higher like 10 min chart and up use a 2-3 times multiplier.
 

diazlaz

Well-known member
2019 Donor
VIP
Yes, no repaint on this combo. That is the best p/l I've ever seen come from this study. Nice work, it is steady growth too. No simple ma study on the 4 minute would ever beat that.
thanks All - can someone help me improve this.

Here is a good pattern in which the current parameters are not efficient, if we can solve for this type of pattern, I think it will make the indicators/csa better well rounded for partial trending conditions.

using dolomick share, MSFT 1M on 1/15/2020. on 1/15 most of all timeframes are negative.

C8gOT75.png
 
Status
Not open for further replies.

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.
Top