Half Trend (Halftrend) Scalper Indicator for ThinkorSwim

Can someone help me please?
Do the five-minute time frames not work conditional buy and sell orders, according to the study?

I don't know more details, but this is one of the buy/sell orders that I missed. It works for one minute and does not work for five minutes. I'm trying to send a picture, but I don't know how +20 TQQQ MKT GTC WHEN

TQQQ STUDY '{tho=true};AMIR_HALFTREND1("amplitude" = 2)."UpSignal" from 1 bars ago is true;5m' IS TRUE.
The syntax is correct. Technically there is no reason for it to work on the one minute and not on the five minute.
 
BenTen, Thanks for your very tight could using conditional logic rather than direct assignment like “trend = 0”! I’m not a TOS user yet, but your code will translate to an application I use that permits only assignment to another function or macro that is set to 0. Appreciated, Pat
 
I found that the only way to keep the trendline from showing as red is to have zero periods of expansion on the right edge. I actually like about 10 periods on the right side. Zero makes me feel claustrophobic being right up against the wall. But I guess I'll live with it unless someone can figure out why it wants to keep making the last period of the trendline red.
 
Is it possible to build a Label for HalfTrend Indicator? example: green when there's a signal
 
Last edited by a moderator:
Has anyone tried this in real trade? Was looking for HT code for tos and found this one.

Is the original settings good for holding a trend trade or would it be better to change for other instruments like /NQ? I am looking for a 5m TF setups for /ES and /NQ.
 
Has anyone tried this in real trade? Was looking for HT code for tos and found this one.

Is the original settings good for holding a trend trade or would it be better to change for other instruments like /NQ? I am looking for a 5m TF setups for /ES and /NQ.
Recommend you put it on your chart. Nothing beats personal experience ;) The only way you will know what works best for you is to play with the settings and see how the indicator line up w/ your strategy and with your other indicators. To determine if this indicator brings value, analyze it over different timeframes, across history and with multiple instruments.
 
Can someone help with a lower study to show signal/alert on condition when one or more higher timeframes are in sync (same trend -uptrend or downtrend) with trend in current chart. Eg: I am swing trading on 15 min and want to have signal/alert (as a lower study) when 15 min, 30 min and 1 hour are in the same trend (up or down ) as current 15 min. chart.
 
I have downloaded the Half Trend indicator and scanner and started paper trading the buy/sell signals. Would like to create a TOS alert when the indicator has an UP (Buy) or DOWN (Sell) arrow on the indicator.
# PRC_HalfTrend Scanner
# Original indicator study by Mobius Apr 2020
# Comment/uncomment desired plot at end of script
# 2020.08.20 -john5788
 
@Kallyone @Richard Lamkin
So.... It would seem from reading through this thread, alerts have been problematic.
It "could" be because the indicator has a lag.

Theoretically, if we set it to look back two bars, the alerts might fire.
BUT there may be other problems. I don't use this indicator. The following snippet is untested.

Add this to the bottom of your script:
Ruby:
Alert(UpSignal within 2 bars, "upSignal", Alert.Bar, Sound.Chimes);
Alert(DownSignal within 2 bars, "downSignal", Alert.Bar, Sound.Chimes);
 
Half Trend is a scalping indicator for ThinkorSwim converted by developer Mobius. This is my first time hearing about the script, but Half Trend seems to be quite popular among Forex traders. Also, it was only available for other platforms such as MT4. Now you can use it on ThinkorSwim :)



A quick search on Google will allow you to learn more about the Half Trend indicator, potential setups, and usage.

LMxEfKr.png


thinkScript Code

Code:
# PRC_HalfTrend | indicator
# 10.03.2017
# Ported by Mobius Apr 2020
# Arrows added by @shortyuk (https://usethinkscript.com/threads/half-trend-scalper-indicator-for-thinkorswim.3305/post-30413)

input Amplitude = 3;

def lowpricei;
def highpricei;
def lowma;
def highma;
def barindex = barNumber();
def nexttrend;
def maxlowprice;
def trend;
def minhighprice;
def up;
def down;

plot halftrend;

lowpricei = Lowest(low, Amplitude);
highpricei = Highest(high, Amplitude);
lowma = average(low, Amplitude);
highma = average(high, Amplitude);
if barindex > Amplitude and
          nexttrend[1] == 1
    {
     maxlowprice = Max(lowpricei, maxlowprice[1]);
     trend = if highma < maxlowprice[1] and close < low[1]
             then 1
             else trend[1];
     nexttrend = if highma < maxlowprice[1] and close < low[1]
                 then 0
                 else nexttrend[1];
     minhighprice = if highma < maxlowprice[1] and close < low[1]
                    then highpricei
                    else minhighprice[1];
    }
else if nexttrend[1] == 0
    {
     minhighprice = Min(highpricei, minhighprice[1]);
     trend = if lowma > minhighprice[1] and close > high[1]
             then 0
             else trend[1];
     nexttrend = if lowma > minhighprice[1] and close > high[1]
                 then 1
                 else nexttrend[1];
     maxlowprice = if lowma > minhighprice[1] and close > high[1]
                   then lowpricei
                   else maxlowprice[1];
    }
else
    {
     maxlowprice = maxlowprice[1];
     trend = trend[1];
     nexttrend = nexttrend[1];
     minhighprice = minhighprice[1];
    }
if trend == 0
    {
     up = if trend[1] <> 0
          then down[1]
          else Max(maxlowprice[1], up[1]);
    down = 0;
    }
else if trend[1] <> 1
    {
     down = up[1];
     up = 0;# up[1] este era el error
    }
else if trend == 1
    {
     down = Min(minhighprice, down[1]);
     up = up[1];
    }
else
    {
     up =up[1];
     down = down[1];
    }
if up > 0
    {
     halftrend = up;
    }
else
    {
    halftrend = down;
    }
halftrend.SetStyle(Curve.Firm);
halftrend.AssignValueColor(if up > 0 then color.cyan else color.red);
halftrend.SetLineWeight(2);

plot UpSignal = if up[1]<1 and up>0 then low else Double.NaN;
plot DownSignal = if down[1]<1 and down>0 then high else Double.NaN;
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
UpSignal.SetDefaultColor(Color.Cyan);
DownSignal.SetDefaultColor(Color.Red);
UpSignal.SetLineWeight(3);
DownSignal.SetLineWeight(3);
# End Code

Backtesting Snippet

Add the following to your existing script, then add the entire indicator as a new strategy:

Code:
AddOrder(OrderType.BUY_TO_OPEN, condition = UpSignal, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Long");
AddOrder(OrderType.SELL_TO_CLOSE, condition = DownSignal, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Cover");

You can find the scanner for this indicator here. Credit to @john5788
can someone add the option to paint the candles with the Buy and Sell signal with this great indicator? thanks in advance
 
can someone add the option to paint the candles with the Buy and Sell signal with this great indicator? thanks in advance
Might not work, given the problems with this indicator.
You can try adding this to the bottom of your script:
Ruby:
input paintcandles = yes ;
AssignBackgroundColor(if !paintcandles then color.current else
                      if upsignal then color.cyan else
                      if downsignal then color.magenta else color.current);
 
Is there any confirmation as to whether this repaints (i.e. refines its lines retroactively as time passes)?
 
Is there any confirmation as to whether this repaints (i.e. refines its lines retroactively as time passes)?

The forum "tries" to ensure that no backtesting scripts for repainters are posted. The results are just too false.
So if you see "AddOrder" in the script like at the bottom of the first post It should not be a repainter.
Also, the script itself will tell you if it repaints.
Read more here: https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-57833

No, the script in the 1st post does not repaint.
This indicator is a take-off on the popular 3-bar studies which are responsive to price action, so they are favored by scalpers.
This study makes an effort to weed out false reversals. It waits to confirm trend, so there is a lag. This means entry signals are later and exits later. For this reason, it is contraindicated on timeframes > 30min at which point the lag is too much.

FYI, the discussion of repainting in this thread, pertains to the MTF studies that have been submitted further down in this thread.
The problem with multiple time frames with this script is: between the repainting of the MTF and the lag, you will be waiting at least 10 candles to get a true signal if you were to overlay a 5min timeframe on a 1min chart; which is why MTF Halftrend scripts are not recommended.

Hope this helps
 
Last edited:
The forum "tries" to ensure that no backtesting scripts for repainters are posted. The results are just too false.
So if you see "AddOrder" in the script like at the bottom of the first post It should not be a repainter.
Also, the script itself will tell you if it repaints.
Read more here: https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-57833

No, the script in the 1st post does not repaint.
This indicator is a take-off on the popular 3-bar studies which are responsive to price action, so they are favored by scalpers.
This study makes an effort to weed out false reversals. It waits to confirm trend, so there is a lag.
It enters later than other scalping indicators and exits later. For this reason, it is contraindicated on timeframes > 30min at which point the lag is too much.

FYI, the discussion of repainting in this thread, pertains to the MTF studies that have been submitted further down in this thread.
The problem with multiple time frames with this script is: between the repainting of the MTF and the lag, you will be waiting at least 10 candles to get a true signal if you were to overlay a 5min timeframe on a 1min chart; which is why MTF Halftrend scripts are not recommended.

Hope this helps
MerryDay, thank you for this thorough clarification. I checked out the links you've shared and it was very helpful. Much appreciated.
 
Half Trend is a scalping indicator for ThinkorSwim converted by developer Mobius. This is my first time hearing about the script, but Half Trend seems to be quite popular among Forex traders. Also, it was only available for other platforms such as MT4. Now you can use it on ThinkorSwim :)



A quick search on Google will allow you to learn more about the Half Trend indicator, potential setups, and usage.

View attachment 7555

thinkScript Code

Code:
# PRC_HalfTrend | indicator
# 10.03.2017
# Ported by Mobius Apr 2020
# Arrows added by @shortyuk (https://usethinkscript.com/threads/half-trend-scalper-indicator-for-thinkorswim.3305/post-30413)

input Amplitude = 3;

def lowpricei;
def highpricei;
def lowma;
def highma;
def barindex = barNumber();
def nexttrend;
def maxlowprice;
def trend;
def minhighprice;
def up;
def down;

plot halftrend;

lowpricei = Lowest(low, Amplitude);
highpricei = Highest(high, Amplitude);
lowma = average(low, Amplitude);
highma = average(high, Amplitude);
if barindex > Amplitude and
          nexttrend[1] == 1
    {
     maxlowprice = Max(lowpricei, maxlowprice[1]);
     trend = if highma < maxlowprice[1] and close < low[1]
             then 1
             else trend[1];
     nexttrend = if highma < maxlowprice[1] and close < low[1]
                 then 0
                 else nexttrend[1];
     minhighprice = if highma < maxlowprice[1] and close < low[1]
                    then highpricei
                    else minhighprice[1];
    }
else if nexttrend[1] == 0
    {
     minhighprice = Min(highpricei, minhighprice[1]);
     trend = if lowma > minhighprice[1] and close > high[1]
             then 0
             else trend[1];
     nexttrend = if lowma > minhighprice[1] and close > high[1]
                 then 1
                 else nexttrend[1];
     maxlowprice = if lowma > minhighprice[1] and close > high[1]
                   then lowpricei
                   else maxlowprice[1];
    }
else
    {
     maxlowprice = maxlowprice[1];
     trend = trend[1];
     nexttrend = nexttrend[1];
     minhighprice = minhighprice[1];
    }
if trend == 0
    {
     up = if trend[1] <> 0
          then down[1]
          else Max(maxlowprice[1], up[1]);
    down = 0;
    }
else if trend[1] <> 1
    {
     down = up[1];
     up = 0;# up[1] este era el error
    }
else if trend == 1
    {
     down = Min(minhighprice, down[1]);
     up = up[1];
    }
else
    {
     up =up[1];
     down = down[1];
    }
if up > 0
    {
     halftrend = up;
    }
else
    {
    halftrend = down;
    }
halftrend.SetStyle(Curve.Firm);
halftrend.AssignValueColor(if up > 0 then color.cyan else color.red);
halftrend.SetLineWeight(2);

plot UpSignal = if up[1]<1 and up>0 then low else Double.NaN;
plot DownSignal = if down[1]<1 and down>0 then high else Double.NaN;
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
UpSignal.SetDefaultColor(Color.Cyan);
DownSignal.SetDefaultColor(Color.Red);
UpSignal.SetLineWeight(3);
DownSignal.SetLineWeight(3);
# End Code

Backtesting Snippet

Add the following to your existing script, then add the entire indicator as a new strategy:

Code:
AddOrder(OrderType.BUY_TO_OPEN, condition = UpSignal, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Long");
AddOrder(OrderType.SELL_TO_CLOSE, condition = DownSignal, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Cover");

You can find the scanner for this indicator here. Credit to @john5788
Is it possible to add Long and Short instead of arrows please.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
407 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