Help coding 3/8 Trap Easy Scan from TC2K

S

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.
Thanks a ton for helping out.
Sam
 
S

samerjb

New member
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 again for helping out.

Sam
 
T

TurDal

New member
Code:
LOW <= ExpAverage(CLOSE, 8) and
CLOSE > ExpAverage(CLOSE, 8) and
(CLOSE < ExpAverage(CLOSE, 3)[1]) OR (CLOSE < ExpAverage(CLOSE, 3)[2]) OR (CLOSE < ExpAverage(CLOSE, 3)[3])
Here is a shareable link for the scanner: https://tos.mx/bdAeIXr
 
Last edited by a moderator:
M

mn88

New member
VIP
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:
J

john3

Active member
2019 Donor
I believe the 3/8 Trap uses 3/8 EMA cross.
 
M

mn88

New member
VIP
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);
 
J

john3

Active member
2019 Donor
@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
 
M

mn88

New member
VIP
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.
 
J

john3

Active member
2019 Donor
@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:
M

mn88

New member
VIP
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);
 
J

john3

Active member
2019 Donor
@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.
 
M

mn88

New member
VIP
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.
 
J

john3

Active member
2019 Donor
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.
Performs better on what time frame?
 

Similar threads

Top