Half Trend Scalper Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
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 :)

18:57 Mobius: Here's a code that was dropped in my lap earlier to port to TOS. The folks that gave it to me didn't think it could be done in ThinkScript. You know how I love a challenge. No restrictions on sharing and I thought it was a nice take on trend following. I've no information about the original coder other than what's in the header.

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



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
 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@TosTrd I don't believe so, but if you see otherwise, please let us know.
 
H

HighBredCloud

Well-known member
VIP
This looks very similar to Trend Magic indicator...I like those as it appears that such indicators are not lagging especially when you can trade ABOVE or BELOW the moving average...Anyone want to give a try on an MTF version of this?
 
S

shortyuk

New member
VIP
@BenTen Can we add up / down arrows to it?

Paste this at the bottom of the code to add arrows.

Code:
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);
 
BenTen

BenTen

Administrative
Staff
VIP
@shortyuk Well done, thanks for the snippet. Updated the first post.
 
spicytrader

spicytrader

New member
VIP
Just remove the first two lines and add this to show the arrows:

Code:
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);
 
MerryDay

MerryDay

Active member
VIP
I gave this indicator a run. The end of the trend overshoots resulting in a significant profit being given back or resulting in a loss.
I changed the sell_criteria to sell before the downturn which created better scenarios.
But I won't be using this because it climbs every mountain even those that are not profitable.
I am posting my chart if someone wants to come along and add a squeeze or other criteria to make this more discerning.



Strategy Link: http://tos.mx/g5DoTqf
 
Last edited:
S

sheldonxp

New member
VIP
@MerryDay Wow, the results look too good to be true...am I missing something between the backtest and reality? Why do you say you won't be using this anymore?

Also, I am trying to also add the opposite orders in your strategy, with short selling. Would you mind explaining how I could do that?
 
Last edited:
K

krsheath

New member
VIP
This is a very good script - can some one make this like this. I wish I can code

 
K

krsheath

New member
VIP
This indicator - Works perfect on /ES & /NQ and all future trades.. Very Good Job.
 
  • Like
Reactions: DPM
E

ext99k

Member
It looks too good to be true on the dailies... what does repaint mean? @TosTrd

As of today's Daily SPY, it has turned flat red, indicating possibly "repainting"? as it might go back and continue to green uptrend? I'm guessing that's why it is too good to be true, because when used it gives false signals then you're unsure what to do, similar to the ZigZag indicator, though this might be more efficient with longer aggregation bars like Daily
 
BenTen

BenTen

Administrative
Staff
VIP
@ext99k Repainting = if the signal is wrong, it will disappear. You can learn more about that here.

However, I don't think the Half Trend indicator will repaint. I'm sure there are enough people that use it at this point. If it does repaint, we would have received comments about it. When using any indicators on the daily chart, you must let the current candle close for confirmation.

@sbwcws What you posted is essentially the same. I suspect just different settings, and I also notice an MTF version.
 
E

ext99k

Member
What other trend indicators do you all work with? I use GannHighLow, Concativity, williams fix fix, LBR_SmartADX... likely will add the Half Trend indicator as well
 

Similar threads

Top