Convert TC2000 code for 3/8 trap to Thinkorswim


Category:
0
0

I came across the youtube video posted by the Right Way option about the 3/8 trap.  He provided the script for TC2000 for the scan to find the 3/8 trap scanner, which is :

L <= XAVGC8 and C > XAVGC8 and (C < XAVGC3.1) or (C < XAVGC3.2) or (C < XAVGC3.3), Can anyone help to convert this code to TnS platform.

Thank you.

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on June 13, 2021 1:44 am
824 views
0
Private answer

I had to update the title of your question. You need to provide more details than "translate TC200o to Thinkorswim". Imagine if everyone posted that as their question title. We would have dozens of solutions with the exact same title and no one would be able to search for a specific solution. So when you have a request to translate code from one platform to another, the title of the question must include some sort of description about the type of signal being requested. This will enable the rest of our viewers to search for specific solutions and find them.

The translation for this particular code is pretty straight foward except for one detail I will explain later. Here is the code that I believe captures the way it should work in TC2000. (I really have zero experience with the TC2000 platform so I have to apply some guesswork here.

input maLengthOne = 3;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
input maLengthTwo = 8;
input maTypeTwo = AverageType.EXPONENTIAL;
input maPriceTwo = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
def maTwo = MovingAverage(maTypeTwo, maPriceTwo, maLengthTwo);
plot scan = low <= maTwo and close > maTwo and (close < maOne[1] or close < maOne[2] or close < maOne[3]);

Now let's look at that last line of code. I enclosed the last 3 checks for close being less than a previous value of the 3 period ema within parentheses. Notice those last three elements have the keyword "or" inserted between them. On Thinkorswim, if we do not enclose all three of those elements within brackets the scan would pick up any stocks in which any of those three conditions are true.

The way I have it written above, Thinkorswim will find stocks where the low is less than or equal to the 8 period ema AND the close is greater than the 8 period ema AND either of the following conditions are true:

  1. close < 3 period ema from one bar ago OR
  2. close < 3 period ema from 2 bars ago OR
  3. close < 3 period ema from 3 bars ago

If we write that last line of code to exactly match the logic from the TC2000 code we end up with the following scan statement:

plot scan = low <= maTwo and close > maTwo and (close < maOne[1]) or (close < maOne[2]) or (close < maOne[3]);

If you were to use this line of code instead of the one I included above the scan will include all stocks in which elements 2 and 3 (listed above) are true while none of the other elements are true. I cannot imagine why anyone would intentionally create it this way (perhaps TC2000 handles the AND and OR keywords in a different way than Thinkorswim?). But since it is the most literal interpretation of the TC2000 code I decided its best to provide this alternative along with the explanation.

It will be helpful if you can run this scan using both and post a comment below this answer to let the rest of our viewers know which one matches the results from the TC2000 platform.

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on June 13, 2021 2:59 pm