Help coding 3/8 Trap Easy Scan from TC2K

samerjb

New member
Dear friends: Happy new year :)

I started following the pop out of the box (Darvas Box) strategy & found the best teachings are those of Doug Campbell's from Right Way Options.
He uses TC2000 to scan for the 3/8 Trap. I would be grateful if anybody can reverse engineer his scan for ToS.
L <= XAVGC8 and C > XAVGC8 and (C < XAVGC3.1) or (C < XAVGC3.2) or (C < XAVGC3.3)

I searched for a day but found nothing floating in the public think scripts.

Here is some decoding to make things easier:

L = Today's low price
C = Closing price today
XAVGC = Exponential Moving Average of Close/Last Price
Parentheses will force an operation to perform earlier in the order.

Thanks a ton for helping out.
Sam
 

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

I'm trying to learn thinkscript better so when I see posts like this I try to write a script to make an indicator for practice. This one seemed easy enough to take a crack at it. I used TMO 1-hour / 1-day charts and came up with this. I'm using adaptive ema because I prefer it, but you can message me and I can switch it if you prefer. For a downtrend or rangebound stock, it doesn't work (its not meant for that) and should only be used in a good uptrend. On the chart I was looking at it seemed to do pretty good, except at the top of the trend when it is reversing :)

Maybe someone here could add to it to add some trend direction detection to it to prevent that, otherwise you would have to use additional technical analysis and should definitely backtest it since I'm just doing this for practice and am not experienced at this lol.

Indicator:
https://tos.mx/nty3u9T
Scan:
https://tos.mx/ZKbQ8dR
Code:

# three_eight_trap
def aema3 = adaptiveEMA(HLC3,3,9);
def aema8 = adaptiveEMA(HLC3,8,9);

Def s = if (aema3[1] - aema8[1]) >= .40 and (aema3 - aema8) <= .39 and (aema3 - aema8) >= .01
then 1 else 0;
plot signal = s within 1 bars;
signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal.SetLineWeight(1);
 
Last edited:
I believe the 3/8 Trap uses 3/8 EMA cross.

I was not familiar with this indicator and googled it earlier when I saw this post and from what I saw people were using EMA. But I do not see a plain EMA when I search for it in think or swim. But I added multiple EMA's to the code, just remove the # from the two you want to use and make sure the rest of them all have # in front of them and you can test the different EMA's out. I also reversed the signal for a short signal. I have been looking at the original one I have posted and it is pretty good on a trend increasing at more than a 25-degree angle (I use a hand-drawn line to check this because I am not sure how to script that in yet.) And of course, it fails at the end of the trend still trying to figure out a way to counter that also.

Code:
# three_eight_trap

#def amea3 = adaptiveEMA(HLC3,3,9);
#def amea8 = adaptiveEMA(HLC3,8,9);

#def ema3 = DEMA(close,3);
#def ema8 = DEMA(close,8);

#def ema3 = TEMA(close,3);
#def ema8 = TEMA(close,8);

def ema3 = LegacyEMA(close,3);
def ema8 = LegacyEMA(close,8);

Def s1 = if (ema3[1] - ema8[1]) >= .40 and (ema3 - ema8) <= .39 and (ema3 - ema8) >= -.30
then 1 else 0;
plot signal1 = s1 within 1 bars;
signal1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal1.SetLineWeight(2);

Def s2 = if (ema8[1] - ema3[1]) >= .40 and (ema8 - ema3) <= .39 and (ema8 - ema3) >= -.30
then 1 else 0;
plot signal2 = s2 within 1 bars;
signal2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signal2.SetLineWeight(2);
 
@mn88

Code:
# Slope of a Moving Average
# Mobius©
# 12.15.2015

# Since price charts are not Cartesian this study is pretty useless but here
# it is none the less. A better measure of price direction is a two fold
# measure.
#
#     First   Trend - is trend positive or negative
#     Second  Distance from the mean.
#
# A third valuable note - What state is the equity in? Is the equity mean
# reverting, trending or random?
#
# The length of a mean calculation should always be tied to your preferred
# trading duration. I use mean reversion trades on a daily charts at the
# very minimum. If you are looking for intraday trading your wasting your
# time looking at any moving average trading
#
# If you prefer an EMA rather than a SMA, replace the MA definition with
#
#    def avg = ExpAverage(close, length);
#
# To run a scan that determines an angle of > 20 degrees, replace the addLabel
# statement with the following scan:
#
#    plot scan = Angle_deg > 20;

input length = 8;
def avg = Average(close, length);
def height = avg - avg[length];
def Angle_deg = ATan(height/length) * 180 / Double.Pi;
addLabel(1, "Angle Deg " + Angle_deg, Color.WHITE);

# End Study
 
Thank you John3 and Horserider. I'll try to add both in this evening after work.

Also as far as how to trade this one video I found said to draw a line at the top of the bar that is indicated. Then enter on the first bar that opens above that. I will see if I can find a link and post it also.
 
@mn88 Don't know if this is useful for the degree angle plot you would like to make but seems relevant.

Code:
# Angle of Rise
# Mobius
# [EMAIL][email protected][/EMAIL]
declare lower;
input n = 38; # n  =  run
  def o = open;
  def h = high;
  def l = low;
  def c = close;
  def LRC = Inertia(c, n);
  def rise = hlc3 - hlc3[n];
  def hypotenuse = sqrt( sqr(n) + sqr(rise) );
  def run = n;
  def slope = rise / run;
plot "Angle, deg" = Asin(rise/hypotenuse) * 180 / Double.Pi;
      "Angle, deg".SetDefaultColor(GetColor(1));


# End Code

P.S. For some reason it changes "(n)" to a thumb down, it should be just n inside of (...)
 
Last edited:
First Video I found for the three eight trap

@john3 I spent the last hour testing and messing with the scan and "Angle Of Rise" study you shared however neither accurately outputs the true angle of the uptrend. I looked for other ideas, but in the end, I decided it would be easier to just rethink how it's coded. So below is the new code, which I am happier with and it is probably as good as I can get it right now until I gain more experience. I have added the EMA but also still have the adaptiveEMA in there just hashed out. I hope you try both, personally I still prefer the adaptiveEMA

Indicator: https://tos.mx/OruWO5l

Scan for Long Entry: https://tos.mx/SzJ4Zz2

Scan for Short Entry: https://tos.mx/PxdCYzp


Code:
#three_eight_trap

#def ema3 = adaptiveEMA(HLC3,3,9);
#def ema8 = adaptiveEMA(HLC3,8,9);
#def ema20 = adaptiveEMA(HLC3,20,9);

def ema3 = ExpAverage(close,3);
def ema8 = ExpAverage(close,8);
def ema20 = ExpAverage(close,20);


def b1 = if (close[2] / open[1]) >= .975 then 1 else 0;
def b2 = if (close[3] / open[2]) >= .95 then 1 else 0;


Def s1 = if ema3[3] < ema3[2] and ema3[2] < ema3[1] and ema3[1] >= ema3 and ema8[3] < ema8[2] and ema8[2] < ema8[1] and ema8[3] > ema20[3] and ema8[2] > ema20[2] and ema8[1] > ema20[1] and ema8 > ema20 and b1 >= 1 and b2 >= 1
then 1 else 0;
plot signal1 = s1 within 1 bars;
signal1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal1.SetLineWeight(2);

Def s2 = if ema3[3] > ema3[2] and ema3[2] > ema3[1] and ema3[1] <= ema3 and ema8[3] > ema8[2] and ema8[2] > ema8[1] and ema8[3] < ema20[3] and ema8[2] < ema20[2] and ema8[1] < ema20[1] and ema8 < ema20 and b1 >= 1 and b2 >= 1
then 1 else 0;
plot signal2 = s2 within 1 bars;
signal2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signal2.SetLineWeight(2);
 
@mn88 I actually not sure what you're trying to make. I was just trying to help out with what I thought you might find useful. The 3 or 2 MAs cross is already available in TOS and on this site. I like using simple MAs as a "base," so I use SMA for 20, 50, 200. I think it makes sense to use EMAs for 3 and 8 but I don't think it makes a huge difference. It also depends on the time frame. I like 8 minutes and 15 minutes.

I don't think an angle makes a difference. Price doesn't retrace or change direction because of an angle.
 
That's cool I appreciate it, for this particular indicator it does seem to perform a bit better depending on the angle so I was just trying to capture that to eliminate some of the false signals.
 
I was wondering if there was any way to convert this to think or swim for a scan. Itsa scan from tc2000.
Any help would be appreciated

TC2000 3/8 Trap Easy Scan CodeL <= XAVGC8 and C > XAVGC8 and (C < XAVGC3.1) or (C < XAVGC3.2) or (C < XAVGC3.3)
 
First Video I found for the three eight trap

@john3 I spent the last hour testing and messing with the scan and "Angle Of Rise" study you shared however neither accurately outputs the true angle of the uptrend. I looked for other ideas, but in the end, I decided it would be easier to just rethink how it's coded. So below is the new code, which I am happier with and it is probably as good as I can get it right now until I gain more experience. I have added the EMA but also still have the adaptiveEMA in there just hashed out. I hope you try both, personally I still prefer the adaptiveEMA

Indicator: https://tos.mx/OruWO5l

Scan for Long Entry: https://tos.mx/SzJ4Zz2

Scan for Short Entry: https://tos.mx/PxdCYzp


Code:
#three_eight_trap

#def ema3 = adaptiveEMA(HLC3,3,9);
#def ema8 = adaptiveEMA(HLC3,8,9);
#def ema20 = adaptiveEMA(HLC3,20,9);

def ema3 = ExpAverage(close,3);
def ema8 = ExpAverage(close,8);
def ema20 = ExpAverage(close,20);


def b1 = if (close[2] / open[1]) >= .975 then 1 else 0;
def b2 = if (close[3] / open[2]) >= .95 then 1 else 0;


Def s1 = if ema3[3] < ema3[2] and ema3[2] < ema3[1] and ema3[1] >= ema3 and ema8[3] < ema8[2] and ema8[2] < ema8[1] and ema8[3] > ema20[3] and ema8[2] > ema20[2] and ema8[1] > ema20[1] and ema8 > ema20 and b1 >= 1 and b2 >= 1
then 1 else 0;
plot signal1 = s1 within 1 bars;
signal1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal1.SetLineWeight(2);

Def s2 = if ema3[3] > ema3[2] and ema3[2] > ema3[1] and ema3[1] <= ema3 and ema8[3] > ema8[2] and ema8[2] > ema8[1] and ema8[3] < ema20[3] and ema8[2] < ema20[2] and ema8[1] < ema20[1] and ema8 < ema20 and b1 >= 1 and b2 >= 1
then 1 else 0;
plot signal2 = s2 within 1 bars;
signal2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signal2.SetLineWeight(2);
Hello,
I am still new to thinkscript and learning. What is the difference between Code for Indicator and Scan code for Long or Short ? If i am looking for Long entry then which one should be used ? I also follow 3/8 Trap from Doug. Pls help.
 
First Video I found for the three eight trap

@john3 I spent the last hour testing and messing with the scan and "Angle Of Rise" study you shared however neither accurately outputs the true angle of the uptrend. I looked for other ideas, but in the end, I decided it would be easier to just rethink how it's coded. So below is the new code, which I am happier with and it is probably as good as I can get it right now until I gain more experience. I have added the EMA but also still have the adaptiveEMA in there just hashed out. I hope you try both, personally I still prefer the adaptiveEMA

Indicator: https://tos.mx/OruWO5l

Scan for Long Entry: https://tos.mx/SzJ4Zz2

Scan for Short Entry: https://tos.mx/PxdCYzp


Code:
#three_eight_trap

#def ema3 = adaptiveEMA(HLC3,3,9);
#def ema8 = adaptiveEMA(HLC3,8,9);
#def ema20 = adaptiveEMA(HLC3,20,9);

def ema3 = ExpAverage(close,3);
def ema8 = ExpAverage(close,8);
def ema20 = ExpAverage(close,20);


def b1 = if (close[2] / open[1]) >= .975 then 1 else 0;
def b2 = if (close[3] / open[2]) >= .95 then 1 else 0;


Def s1 = if ema3[3] < ema3[2] and ema3[2] < ema3[1] and ema3[1] >= ema3 and ema8[3] < ema8[2] and ema8[2] < ema8[1] and ema8[3] > ema20[3] and ema8[2] > ema20[2] and ema8[1] > ema20[1] and ema8 > ema20 and b1 >= 1 and b2 >= 1
then 1 else 0;
plot signal1 = s1 within 1 bars;
signal1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal1.SetLineWeight(2);

Def s2 = if ema3[3] > ema3[2] and ema3[2] > ema3[1] and ema3[1] <= ema3 and ema8[3] > ema8[2] and ema8[2] > ema8[1] and ema8[3] < ema20[3] and ema8[2] < ema20[2] and ema8[1] < ema20[1] and ema8 < ema20 and b1 >= 1 and b2 >= 1
then 1 else 0;
plot signal2 = s2 within 1 bars;
signal2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
signal2.SetLineWeight(2);
Hi , I tried to scan Long Entry scan code you provided. For some reason just see 3/8 trap that already occured 3-4 bars prior. How can i get that is currently trapped ? Any thoughts ? I am using on daily charts. Thanks !
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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