Heikin_Ashi Indicator For ThinkOrSwim

@BJ1951 Please avoid using ALL-CAPS as it s considered shouting and considered rude in most all online communities...

All-Caps is also the hardest to read, contrary to common beliefs... I did a study years ago when I did management work for a temporary employment agency and found that when signs were posted in All-Caps rather than standard text or Camel-Case the under-educated temps either wouldn't or couldn't read them... Switching to Camel-Case improved compliance tremendously...

But here we use standard text...
 
Thanks to everyone for their work as I would not have gotten this far without your contribution. I have referenced members of the community as you have either commented or contributed to the HA forums/discussions.

After conducting research on indicators/studies that would aid in my entry and exits as well as keeping me in the trend longer than usual, I came upon Sylvan Vervoort and his work. ( I have previously used the TrendPainter, Supertrend etc.) After reading “Trading with the Heikin-Ashi Candlestick Oscillator" and “Trading Medium-Term Divergences” I began searching the site for script that emulates his work.

@BenTen, @zkm, @mc01439, @HighBredCloud, @JBTrades, @markos, @tomsk @horserider @YungTraderFromMontana @diazlaz @J007RMC

Key components
TEMA, Reversal bubbles and/or arrows, MTF indicator, Addchart script used to create the HA , does not repaint.

Strategy – long and/or short. Enter and/or exit based on reversals (however, I utilize other indicators and signals such as the RSI, MTF, increased volume, stocks with strong catalyst, RV above 2.0 and Fib retracement.

Scan
The scan comprises of the MTF script along with the script for liquidity, relative volume and/or stocks that are near (2-5%) to their 52wk high and short interest. I scan for stocks that are low float.

Watchlist
The watchlist is based on the buy and sell signals.

Feedback from members

I would like feedback from members regarding changing those candles that are “in the trend” but have a different color. (see chart). This would eliminate the number of signals that appear. (especially where there is only one red or green candle in the middle of the current trend. I have tried using strategies such as increasing the lookback period, using the previous candle(s) script but with no success. Please see notes within the chart.

Also, can someone please provide the information for making the Fib lines shorter. Please see notes within the chart.

It is a work in progress. I have made profitable trades and this indicator has allowed me to find setups before major breakouts etc. (this is in combination with the Buy-the Dip).

This is a chart without the regular candles. This shows the HA with the buy and sell signals and the Multi Time Frames. This is the main trading chart. The chart with the candlesticks is used for reference during trading. (I use two monitors when trading)
i7GJm5H.jpg


This is the above chart with the regular candles.
O3grdOi.jpg


This chart shows the Fib Lines and notes on the feedback needed.
ZrGyZKw.jpg


This chart shows the HA candles without the new HA_smoothing chart
3pBHtFX.jpg


This chart shows the scan criteria
DllROT7.jpg


Code
Code:
#Heiken_Ashi based on Sylvan Verboort's Trading with HA Candlestick Oscillator
#Bon Bon _last update Jan 17th 2021
#Influenced by script from HoboTheClown / blt,http://www.thinkscripter.com, TD Hacolt etc.
#MTF based on HannTech's MTF_MACD script
#update 1/2/21 - changed the default moving average to TEMA.  Changed the period to 35.
#update changed reversal arrows to reversal bubbles with price

### YOU MUST HAVE THE STYLE SETTING FIT STUDIES ENABLED ###
#hint: The style setting Fit Studies must be enabled to use these bars.


input period = 50;
input hideCandles = yes;
input candleSmoothing = {default Valcu, Vervoort};
input show_bubble_labels = yes;
input bubbles = yes;
input arrows = yes;


#input smoothingLength = 3;

input movingAverageType = {default  TEMA, Exponential, Hull };

def openMA;
def closeMA;
def highMA;
def lowMA;

switch (movingAverageType) {
case Exponential:
    openMA = CompoundValue(1, ExpAverage(open, period), open);
    closeMA = CompoundValue(1, ExpAverage(close, period), close);
    highMA = CompoundValue(1, ExpAverage(high, period), high);
    lowMA = CompoundValue(1, ExpAverage(low, period), low);

case Hull:
    openMA = CompoundValue(1, HullMovingAvg(open, period), open);
    closeMA = CompoundValue(1,  HullMovingAvg(close, period), close);
    highMA = CompoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = CompoundValue(1,  HullMovingAvg(low, period), low);

case TEMA:
    openMA = CompoundValue(1, TEMA(open, period), open);
    closeMA = CompoundValue(1, TEMA(close, period), close);
    highMA = CompoundValue(1, TEMA(high, period), high);
    lowMA = CompoundValue(1, TEMA(low, period), low);

}


HidePricePlot(hideCandles);

def haOpen;
def haClose;

switch (candleSmoothing){
case Valcu:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);
case Vervoort:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0 ) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);

}

plot o = haOpen;
o.Hide();

def haLow =  Min(lowMA, haOpen);
def haHigh = Max(highMA, haOpen);

#Zero Lag System - MetaStock Crossover Formula
#zero-lagging principle
#Zero-lagging TEMA average on closing prices

#Medium-term price reversals - upward trend

def avg = 34;
def TMA1 = reference TEMA(haClose, avg); # triple exponential moving average (TEMA) of 34 bars
def TMA2 =  reference TEMA(TMA1, avg);
def Diff = TMA1 - TMA2;
def ZlHa = TMA1 + Diff; #Zero-lagging TEMA average on closing prices - medium term uptrend;

#Medium-term price reversals - downward trend
def TMA1_ = reference TEMA((high + low) / 2, avg);
def Diff2 = TMA1_ - TMA2;
def ZlCl = TMA1_ + Diff2; #Zero-lagging TEMA average on closing prices - medium term doenwardtrend;

def ZlDif = ZlCl - ZlHa; # Zero-Lag close - Zero-Lag HA(green candle) Uptrend when ZlDif is equal to or greater than zero

#uptrend {green candle}
def keep1 = if (haClose >= haOpen and haClose[1] >= haOpen[1]) then 1 else 0;
def keep2 = if ZlDif >= 0 then 1 else 0;
def keep3 = if (AbsValue(close - open) < ((high - low) * 0.35)) and high >= low[1] then 1 else 0;
def keeping = if (keep1 or keep2) then 1 else 0;
def keepall = if keeping or (keeping[1]) and close >= open or close >= (close[1]) then 1 else 0;

def utr = if keepall or (keepall[1]) and keep3 then 1 else 0;

#downtrend red candle

def keep1_ = if (haClose < haOpen and haClose[1] < haOpen[1]) then 1 else 0;
def keep2_ = if ZlDif < 0 then 1 else 0;
def keep3_ = if (AbsValue(close - open) < ((high - low) * 0.35)) and low <= high[1] then 1 else 0;
def keeping_ = if (keep1_ or keep2_) then 1 else 0;
def dkeepall_ = if keeping_ or (keeping_[1]) and close < open or close < (close[1]) then 1 else 0;

def dtr = if dkeepall_ or (dkeepall_[1] - 1) and keep3_ == 1 then 1 else 0;  #downtrend
def upw = if dtr and (dtr[1]) and utr then 1 else 0;
def dnw = if !utr and (utr[1] ) and dtr then 1 else 0;

def results = if upw then 1 else if dnw then 0 else results[1];

#Change the color of HA and Japanese Candles - turn off to show only HA on chart
AssignPriceColor(if haClose >= haOpen
                 then Color.GREEN else
                 if  haClose < haOpen
                 then Color.RED else Color.WHITE);


#Heiken_A script

#####################################################################################################
input charttype = ChartType.CANDLE;

def haopen_ = if haClose <= haOpen
              then haOpen + 0
             else Double.NaN;

def HAhi   = if haClose <= haOpen
              then haHigh
              else Double.NaN;

def HAlo =   if haClose <= haOpen
              then haLow
              else Double.NaN;


AddChart(growColor = Color.RED, neutralColor = Color.CURRENT, high = HAhi, low = HAlo, open = haopen_, close = haClose, type = ChartType.CANDLE);

def HAclose1 = ohlc4;
def HAopen1  = if haClose >= haOpen
               then CompoundValue(1, (haOpen[1] + haClose[1]) / 2, (open[1] + close[1]) / 2)  
               else Double.NaN;

def haopen_1 = if haOpen <= haClose
               then HAopen1 + 0  else Double.NaN;

def HAhigh1  = haHigh;
def HAlow1   = haLow;


AddChart(growColor = Color.GREEN, neutralColor = Color.CURRENT,  high = HAhigh1, low = HAlow1, open = haopen_1, close = haClose, type = ChartType.CANDLE);

#####################################################################################################
#Buy and sell signals
def trend =  haClose >= haOpen;
def trendup = trend and !trend[1];
def trendd =  haClose < haOpen;
def trendDown = trendd and !trendd[1];

AddChartBubble(bubbles and trendup and trendup, HAlow1, ("Reversal:"    + round(HAlow1, 2)), Color.GREEN, no);

AddChartBubble(bubbles and trendDown and trendDown, HAhigh1, ("Reversal:"  + round(HAhigh1,2)), Color.LIGHT_RED, yes);

#Arrows instead of bubbles
#def trend = haClose >= haOpen ;
#plot trendup = trend and !trend[1];
#trendup.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#trendup.SetDefaultColor(Color.CYAN);


#def trendd = haClose <= haOpen ;
#plot trendDown = trendd and !trendd[1];
#trendDown.SetDefaultColor(Color.MAGENTA);
#trendDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

I am looking forward to your feedback. Thanks.
Thanks to you and everyone for their work on this. But is there a link to the scan? I see the code but I am not sure how to input it. Thanks in advance.
 
@BonBon can you please help me set my chart up exactly like the first photo above, (with the MTF as well) before i throw my computer out the window and cry hahaaa, i looked through all 9 pages here and tried all the script mods for 2 hours and keep getting errors, thank you
 
@BJ1951 Please avoid using ALL-CAPS as it s considered shouting and considered rude in most all online communities...

All-Caps is also the hardest to read, contrary to common beliefs... I did a study years ago when I did management work for a temporary employment agency and found that when signs were posted in All-Caps rather than standard text or Camel-Case the under-educated temps either wouldn't or couldn't read them... Switching to Camel-Case improved compliance tremendously...

But here we use standard
We have problem seeing but will remember this thank you for your info .As you can tell not a typist.
 
@D_Tramp Yes... this is the script that I use for the watchlist.

Code:
input period = 50;
input hideCandles = no;
input candleSmoothing = {default Valcu, Vervoort};
input show_bubble_labels = yes;

input movingAverageType = {default Exponential, TEMA};

def openMA;
def closeMA;
def highMA;
def lowMA;

switch (movingAverageType) {

case Exponential:
    openMA = CompoundValue(1, ExpAverage(open, period), open);
    closeMA = CompoundValue(1, ExpAverage(close, period), close);
    highMA = CompoundValue(1, ExpAverage(high, period), high);
    lowMA = CompoundValue(1, ExpAverage(low, period), low);

case TEMA:
    openMA = CompoundValue(1, TEMA(open, period), open);
    closeMA = CompoundValue(1, TEMA(close, period), close);
    highMA = CompoundValue(1, TEMA(high, period), high);
    lowMA = CompoundValue(1, TEMA(low, period), low);
}


def haOpen = CompoundValue(1,( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0) / 2.0), open);
def haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);
def haLow =  Min(lowMA, Min(haclose, haOpen));
def haHigh = Max(highMA, Max(haclose, haOpen));

def trend = haclose >= haopen;
plot trendup = trend and !trend[1];

def trendd = haclose < haopen;
plot trendDown = trendd and !trendd[1];

def arrowup = trendup;
def arrowdown = trenddown;

def trigger = if arrowup then 100 else if arrowdown then -100 else trigger [1];

AddLabel(yes, if trigger == 100 then "👍" else if trigger == -100 then "👎" else "NA", if trigger ==100 then color.black else if trigger == -100 then color.black else color.white);

AssignbackgroundColor(if trigger == 100 then Color.Green else if trigger == -100 then Color.dark_Red else Color.black);

alert(Trendup,"Trend Up", alert.Bar, sound.bell);
alert(Trenddown,"Trend down", alert.Bar, sound.bell);

Hi, Does anyone know how to make this watchlist work on the TOS mobile? Maybe use a 1 for 👍 and 0 for 👎? I replaced the thumbs with 1 & 0 in the script, but it doesn't show up in mobile. Much appreciated if anyone knows how to modify it to work on mobile.
 
@JarJar168 The capabilities within mobile TOS are very limited... I was just playing in there for the first time in months and finally gave up because it just doesn't perform to my expectations... I've lost money every time I've tried to manage a trade in mobile and after tonight I'll probably never use it again other than to check where the markets are when I'm out and about but I don't leave my trading station when I'm in an active trade these days...
 
@JarJar168 The capabilities within mobile TOS are very limited... I was just playing in there for the first time in months and finally gave up because it just doesn't perform to my expectations... I've lost money every time I've tried to manage a trade in mobile and after tonight I'll probably never use it again other than to check where the markets are when I'm out and about but I don't leave my trading station when I'm in an active trade these days...
Thanks for your feedback and sharing your experience. I know mobile TOS is limited. Sometimes on the go, its easier to have more info to manage my trades.
 
Hi BonBon:

Entry - Heikin Signals – confirm with volume, catalysts, multiple time frame (main plot must reflect the trend of 3 or more time frames) RSI/Stoch/SVE, market cycle etc.
When you say main plot, are you referring to the Main_Heikin in the MTF study OR the upper Smoothed chart?

Exit - Heikin signal - confirm with SVE,Stoch, MTF etc.
Stop loss - just below the Heikin reverse signal, use trailing stop and stop loss.
You have mentioned stop loss below the reverse signal, how to determine it? is there a setting to turn on or a hastag in the code to be removed for that signal to appear?

Additionally, I combined the stochastic and the SVE_Stoc_RSi into one oscillator on the lower chart. This helps identify the 123 wave pullbacks, retracement etc.
Can you please provide code or direct me to the correct location for the combined stochastic and SVE_Stoc_RSI?


Additionally, in post #134, you have shown three variants
1. Smoothed HA with MTF in lower chart
2. ZigZag chart
3. Third reversal type along with automatic Fib retracements.

So, the code you posted in post #134 has the code for all the above 3 variants including Fib retracements? If not, can you please provide or direct me to the location to where i can find it?

Thank you! The indicator seems to be worthy of a test, try and adopt, but there seems to be a few missing parts and I have hard time to put it all together for a full indicator set to begin testing.

Appreciate your effort and time for all your help.
 
Here's an interesting refinement to consider.

When I first saw this thread I remembered that I was impressed with a use of TEMA awhile back. Finally I found it again. It was just a single post by @MasterSteve within a thread about an ORB indicator. Here's the specific post about how he uses a TEMA[30] and a EMA[20] on his chart: [ https://usethinkscript.com/threads/opening-range-breakout-indicator-for-thinkorswim.16/post-95 ]. Thanks @MasterSteve !

When used in combination with this Smoothed HA, it looks like it could be powerful. In essence, the strategy could be as follows:

ENTRY LONG (opposite for shorts)
1. Wait for Smoothed HA to change color (let's say bullish).
2. Check TEMA. Is it the bullish color (cyan)?
3. Check the 20 EMA. Is it the bullish color (green)?
4. Is price now closing above just TEMA? Good. Is price closing above both TEMA and the 20EMA? Better.
5. If the top 4 conditions are met, enter long.

SAFETY EXIT
If price retraces but never closes below a bullish TEMA/Bullish EMA it should be safe to stay in the trade. If price closes below the TEMA, this could be considered a safety exit. Re-entry long might be when price closes above the rising TEMA again. However, price closing and remaining below the TEMA (even while still rising) could be a harbinger for a coming trend reversal.

In the image below, you'll see that I've modified the TEMA and EMA to display bullish and bearish colors, which is key. Info about that and links to them are here: [ https://usethinkscript.com/threads/steves-1-000-option-trading-challenge-week-1-update.23/post-41365 ] . I have also included Bollinger Bands on the chart so that I can see the edges of the envelope. Something I like to watch for is when the Smoothed HA changes color after a Bollinger tight squeeze. This could be a good confirmation of trend change and not just a head fake.

Lastly, keep an eye on the TEMA/EMA crosses. While they are often 'late to the party' in terms of entries, they're usually good confirmation for the trade that you've entered.



Hi RickK can you please help me to figure out what I'm doing wrong with my setup because it doesn't look like yours? I've attached two pics. thanks in advance. Joe



 
@BenTen @Ilya @alexR @dominos101 @D_Tramp @Ghs @hexis777 @freedom Traders @JoeSD @AspaTrader @germanburrito @floydddd @rad14733 @barbaros @RickK @guyonabuffalo @Branch @bpVoodoo @Joseph patrick18

Thank you for your patience. Please see below the watchlist and the scan that correlates to the chart indicators. Ensure you use the same timeframe on your watchlist as your chart e.g. if you are using a 5 min time frame on the chart, use a 5 min timeframe for the watchlist.

Code:
#Bon Bon
# Multi time-frame Heikin Watchlist
#Created by BonBon 1/29/21
#Mirrors the Lower Level Multi_Time frame on the chart

input UsePeriod5 = AggregationPeriod.FIVE_MIN;
input UsePeriod15 = AggregationPeriod.FIFTEEN_MIN;
input UsePeriod30 = AggregationPeriod.thirty_MIN;
input UsePeriod60 = AggregationPeriod. HOUR;
input UsePeriod4hr = AggregationPeriod. FOUR_HOURS;
input UsePeriodday = AggregationPeriod.DAY;

input PaintBars = {default "yes", "no"};
input  Con_Cri = 3;
### Master Plot On/Off ###########

input Master_Heiken_Plot = Yes; #

## Heiken Aski Multi-Time Frame
## 2019 Paul Townsend v3

#Timeframe2 5 min

def aOpen5 = open(period = UsePeriod5);
def aClose5 = close(period = UsePeriod5);
def aHigh5 = high(period = UsePeriod5);
def aLow5 = low(period = UsePeriod5);

def haClose5 = (aOpen5 + aClose5 + aHigh5 + aLow5)/4;
def haOpen5 = (haOpen5[1] + haClose5[1])/2;

#def trend5 = if haClose5 >= haOpen5 then 1 else if haClose5[1] < haOpen5[1] then -1 else 0;

#Timeframe2 15 mins

def aOpen15 = open(period = UsePeriod15);
def aClose15 = close(period = UsePeriod15);
def aHigh15 = high(period = UsePeriod15);
def aLow15 = low(period = UsePeriod15);

def haClose15 = (aOpen15 + aClose15 + aHigh15 + aLow15) / 4;
def haOpen15 = (haOpen15[1] + haClose15[1]) / 2;

#def trend15 = if haClose15 >= haOpen15 then 1 else if haClose15[1] < haOpen15[1] then -1 else 0;

#Timeframe3  30 mins

def aOpen30 = open(period = UsePeriod30);
def aClose30 = close(period = UsePeriod30);
def aHigh30 = high(period = UsePeriod30);
def aLow30 = low(period = UsePeriod30);

def haClose30 = (aOpen30 + aClose30 + aHigh30 + aLow30) / 4;
def haOpen30 = (haOpen30[1] + haClose30[1]) / 2;

#def trend30 = if haClose30 >= haOpen30 then 1 else if haClose30[1] < haOpen30[1] then -1 else 0;

#Timeframe4  60mins

def aOpen60 = open(period = UsePeriod60);
def aClose60 = close(period = UsePeriod60);
def aHigh60 = high(period = UsePeriod60);
def aLow60 = low(period = UsePeriod60);

def haClose60 = (aOpen60 + aClose60 + aHigh60 + aLow60) / 4;
def haOpen60 = (haOpen60[1] + haClose60[1]) / 2;

#def trend60 = if haClose60 >= haOpen60 then 1 else if haClose60[1] < haOpen60[1] then -1 else 0;

#Timeframe5 4hrs

def aOpen4hr = open(period = UsePeriod4hr);
def aClose4hr = close(period = UsePeriod4hr);
def aHigh4hr = high(period = UsePeriod4hr);
def aLow4hr = low(period = UsePeriod4hr);

def haClose4hr = (aOpen4hr + aClose4hr + aHigh4hr + aLow4hr) / 4;
def haOpen4hr = (haOpen4hr[1] + haClose4hr[1]) / 2;

#def trend4hr = if haClose4hr >= haOpen4hr then 1 else if haClose4hr < haOpen4hr then -1 else 0;

#Timeframe6 Day

def aOpenday = open(period = UsePeriodday);
def aCloseday = close(period = UsePeriodday);
def aHighday = high(period = UsePeriodday);
def aLowday = low(period = UsePeriodday);

def haCloseday = (aOpenday + aCloseday + aHighday + aLowday) / 4;
def haOpenday = (haOpenday[1] + haCloseday[1]) / 2;

#def trendday = if haCloseday >= haOpenday then 1 else if haCloseday [1] < haOpenday[1] then -1 else 0;

#Up Trend
def Trend1 = if haClose5 >= haOpen5 then 1 else if haClose5[1] < haOpen5[1] then -1 else 0;
def Trend2 = if haClose15 >= haOpen15 then 1 else if haClose15[1] < haOpen15[1] then -1 else 0;
def Trend3 = if haClose30>= haOpen30 then 1 else if haClose30[1] < haOpen30[1] then -1 else 0;
def Trend4 = if haClose60 >= haOpen60 then 1 else if haClose60[1] < haOpen60[1] then -1 else 0;
def Trend5_ = if haClose4hr >= haOpen4hr then 1 else if haClose4hr[1] < haOpen4hr[1] then -1 else 0;
def Trend6 = if  haCloseday >= haOpenday then 1 else if haCloseday[1] < haOpenday[1] then -1 else 0;

#Down Trend
def Trend1a = if haClose5 < haOpen5 then 1 else if haClose5[1] >= haOpen5[1] then -1 else 0;
def Trend2b = if haClose15 < haOpen15 then 1 else if haClose15[1] >= haOpen15[1] then -1 else 0;
def Trend3c = if haClose30 < haOpen30 then 1 else if haClose30[1] >= haOpen30[1] then -1 else 0;
def Trend4d = if haClose60 < haOpen60  then 1 else if haClose60[1] >= haOpen60[1] then -1 else 0;
def Trend5e= if haClose4hr < haOpen4hr then 1 else if haClose4hr[1] >= haOpen4hr[1] then -1 else 0;
def Trend6f = if  haCloseday < haOpenday  then 1 else if haCloseday[1] >= haOpenday[1] then -1 else 0;

def HA_MTF_TopUP = (Trend1 + Trend2 + Trend3 + Trend4) >=  Con_Cri ;
def HA_MTF_TopDN = (Trend1a + Trend2b + Trend3c + Trend4d) >=  Con_Cri;
def HA_MTF_NoTrend = (Trend1a + Trend2b + Trend3c + Trend4d) <  Con_Cri;

def mftnewup = if HA_MTF_TopUP == 1 then 1 else 0;
def newmtfdown = if HA_MTF_TopDN == 1 then 1 else 0;
def notrend = if HA_MTF_NoTrend == 1 then 1 else 0;

def MTF_Above = mftnewup; 
def MTF_Below = newmtfdown;
def MTF_NoTrend = notrend; 

addlabel(yes,if MTF_Above then "3+" else if MTF_Below then "3+"  else if MTF_NoTrend then "NIL" else"NA", if MTF_Above then color.white else if MTF_Below then color.white else if  MTF_NoTrend then color.black else color.white);

AssignbackgroundColor(if MTF_Above then color.dark_green else if MTF_Below then color.red else if MTF_NoTrend then color.gray else color.black);
 
Please see below the MTF Scan for the HA indicator and lower MTF indicator.

Ibr3EbZ.jpg



I placed the script for one MTF scan below. To add additional timeframes you will need to add a study and change the below default (input mid to the time period you wish to use. Keep doing this until you have added all the timeframes you need for your scan. See below video


You can also add a code within the original script (if it is saved in your studies) and this too will create a scan). Here are some videos to help create the scan. See below video.

-----------------------------------------------------------------------------------------

Code:
#Influenced by Hahn_Tech LTD MTF_MACDStudy and TD's HACOLT
# Scan created by Bon Bon - December 2020
# MTF Scan
#HA_5Mins

input midTermPeriod = {"1 min", "3 min", "15 min", "30 min", "weekly", "60 min", "120 min", "240 min","Daily","monthly", default "5 min"}; #[B]to change the default timeframe remove the 5 min and place it in the main section between the 3 min and 15 min.  Next remove the timeframe you will be using and place it in the default section. [/B]


def middleAggregation;

switch (midTermPeriod) {
    case "1 min":
        middleAggregation = AggregationPeriod.MIN;
    case "3 min":
        middleAggregation = AggregationPeriod.THREE_MIN;
    case "5 min":
        middleAggregation = AggregationPeriod.FIVE_MIN;
    case "15 min":
        middleAggregation = AggregationPeriod.FIFTEEN_MIN;
    case "30 min":
        middleAggregation = AggregationPeriod.THIRTY_MIN;
    case "60 min":
        middleAggregation = AggregationPeriod.HOUR;
    case "120 min":
        middleAggregation = AggregationPeriod.TWO_HOURS;
    case "240 min":
        middleAggregation = AggregationPeriod.four_hours;
       case "Daily":
        middleAggregation = AggregationPeriod.DAY;
    case "Weekly":
        middleAggregation = AggregationPeriod.WEEK;
    case "Monthly":
        middleAggregation = AggregationPeriod.MONTH;
}

def timeFrame = getAggregationPeriod();
def testTimeFrames = if timeFrame < middleAggregation  #middleAggregation < highestAggregation
then yes else no;

#AddLabel(yes, if testTimeFrames  then "Time Frames Are Correct" else "Time Frames Are Wrong", if testTimeFrames  then color.GREEN else color.RED);

input period = 50 ;
input hideCandles = no;
input candleSmoothing = {default Valcu, Vervoort};

def openMA = CompoundValue(1, TEMA(open, period), open);
def closeMA = CompoundValue(1, TEMA(close( period = middleaggregation)), close);
def highMA = CompoundValue(1, TEMA(high, period), high);
def lowMA = CompoundValue(1, TEMA(low, period), low);

def haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0) / 2.0), open);

def haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);

def up =  if haclose >= haopen then 1 else 0; #high color;
def down = if haclose < haopen then 1 else 0;

def arrowup = up;
def arrowdown = down;

def trigger = if arrowup then 100 else if arrowdown then -100 else trigger [1];

plot scan = up within 1 bars; # this can be changed based upon trading strategy
 
Last edited by a moderator:
Here's an interesting refinement to consider.

When I first saw this thread I remembered that I was impressed with a use of TEMA awhile back. Finally I found it again. It was just a single post by @MasterSteve within a thread about an ORB indicator. Here's the specific post about how he uses a TEMA[30] and a EMA[20] on his chart: [ https://usethinkscript.com/threads/opening-range-breakout-indicator-for-thinkorswim.16/post-95 ]. Thanks @MasterSteve !

When used in combination with this Smoothed HA, it looks like it could be powerful. In essence, the strategy could be as follows:

ENTRY LONG (opposite for shorts)
1. Wait for Smoothed HA to change color (let's say bullish).
2. Check TEMA. Is it the bullish color (cyan)?
3. Check the 20 EMA. Is it the bullish color (green)?
4. Is price now closing above just TEMA? Good. Is price closing above both TEMA and the 20EMA? Better.
5. If the top 4 conditions are met, enter long.

SAFETY EXIT
If price retraces but never closes below a bullish TEMA/Bullish EMA it should be safe to stay in the trade. If price closes below the TEMA, this could be considered a safety exit. Re-entry long might be when price closes above the rising TEMA again. However, price closing and remaining below the TEMA (even while still rising) could be a harbinger for a coming trend reversal.

In the image below, you'll see that I've modified the TEMA and EMA to display bullish and bearish colors, which is key. Info about that and links to them are here: [ https://usethinkscript.com/threads/steves-1-000-option-trading-challenge-week-1-update.23/post-41365 ] . I have also included Bollinger Bands on the chart so that I can see the edges of the envelope. Something I like to watch for is when the Smoothed HA changes color after a Bollinger tight squeeze. This could be a good confirmation of trend change and not just a head fake.

Lastly, keep an eye on the TEMA/EMA crosses. While they are often 'late to the party' in terms of entries, they're usually good confirmation for the trade that you've entered.

Looks pretty straightforward and easier to use.
 
@sunstar

A year ago I too was a newbie with creating scripts and trading. Numerous hours of research, reading and trial and error increased my comprehension of then TOS platform (creating scans, studies, watchlists, strategies etc.) and improving my trading plan. The goal is to use the information, make it your own and apply to your style of trading. Learning from this forum enabled me to share what I have learnt with others.

Please see below the shared fib script. I modified it from the original...added different colors to the trendline and also included the price to the left with the fib percentages. I also included the link showing the original thread and the script for support and resistance. One of my favorite strategies within my trading plan is to use the retracement between the 61.8% and 78.6% made by gappers to enter daily gapping/momentum trades (based on catalysts). I am currently working on a watchlist and scan for these setups and will share when completed.

https://tos.mx/WxiRzvT

Shared support and resistance created by Mobius
https://tos.mx/w9Zpw51
 
Hey Rick, your code works great on 1 minute or 5 minute chart. But when I got to 10 minute or 15 minute or higher, nothing shows up...its blank. Do you know why? Thanks in advance.

Sorry it took awhile for me to see this @Tradervic , I don't think I got an email notification that you made this post. Eventhough you replied to a specific post of mine, maybe it is because you didn't actually reply using my "@RickK" name. Or, maybe I just overlooked the email. I get a lot of junk.

Anyway, I suspect that the problem is that you didn't modify the settings of the indicator when you changed the chart timeframe. For example, if you have your chart on 1m and the indicator settings are 1m, 3m, 5m, 10m, 15m, etc. then it will display properly. However, if these settings stay at 1,3,5,10,15,etc and you change it to a 10 min chart then nothing will display because the indicator's lowest aggregation is 1m. Every time you change the chart timeframe, you need to change the settings of the indicator. In this example the indicator would need to be set to 10m, 15m, 20m, 30m,..... Ultimately, in almost ANY MTF indicator, the lowest setting for the indicator must be the same or higher than your chart timeframe.
 
@JarJar168 The capabilities within mobile TOS are very limited... I was just playing in there for the first time in months and finally gave up because it just doesn't perform to my expectations... I've lost money every time I've tried to manage a trade in mobile and after tonight I'll probably never use it again other than to check where the markets are when I'm out and about but I don't leave my trading station when I'm in an active trade these days...

To add to what @rad14733 (of which I fully agree), the only thing I use mobile TOS for is when (frequently) TOS desktop will freeze or drag when I'm in the middle of a trade. Or, God forbid, there's a power outage and I'm in the middle of a trade. Having mobile TOS open during these times allows you to get out of a trade quickly if it starts to move against you. I highly recommend having mobile TOS open when trading. It's disappointing that mobile TOS doesn't have a quick "flatten" button on the open positions screen (or the ability to "auto send" trade orders).
 
Buy/Cover Short:
1. Hull MA 31 -> Color change
2. Buy signal from the ZigZag indicator (BonBon's shared code)
3. TMO bouncing off from the green zone
4. All the Levels are green (15,30 and 60)

Sell or Short:
1. Hull MA 31 -> Color change
2. Sell signal from the ZigZag indicator (BonBon's shared code)
3. TMO rejected from the red zone
4. All the Levels are red (15,30 and 60)

Targets are fib levels and Stop Loss the previous candle high
@AspaTrader
See below the TMO with breakouts. This was in my bag of tricks (came across it last year and modified adding breakouts. I did not need all the code and only kept the TMO script.

https%3A//i.imgur.com/5vgGzc7.jpg[/img]']
5vgGzc7.jpg


https://tos.mx/MwNMpuW
 
Buy/Cover Short:
1. Hull MA 31 -> Color change
2. Buy signal from the ZigZag indicator (BonBon's shared code)
3. TMO bouncing off from the green zone
4. All the Levels are green (15,30 and 60)

Sell or Short:
1. Hull MA 31 -> Color change
2. Sell signal from the ZigZag indicator (BonBon's shared code)
3. TMO rejected from the red zone
4. All the Levels are red (15,30 and 60)

Targets are fib levels and Stop Loss the previous candle high
Using the MTF has left a lot of "second-guessing" out of entering trades (on the long and short side). Incorporating it within my trading plan has been very positive. I am still tweaking my indicators etc. for that just right fit for my trading style)!!!!
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
286 Online
Create Post

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