NexusFi: Find Your Edge


Home Menu

 





Need Help cleaning up a Thinkscript


Discussion in ThinkOrSwim

Updated
    1. trending_up 5,561 views
    2. thumb_up 2 thanks given
    3. group 1 followers
    1. forum 5 posts
    2. attach_file 2 attachments




 
Search this Thread

Need Help cleaning up a Thinkscript

  #1 (permalink)
esc952
mansfield oh/usa
 
Posts: 4 since Jan 2015
Thanks Given: 2
Thanks Received: 0

Folks,
I apologize in advance if I'm stepping over any lines, but I need a hand and don't have the right tools to do what I want to accomplish. The long and short of it is my Dad asked me to write a TOS scan script for him. All well and fine except he's 1000 miles away and I don't use TOS. I won't say no to him, but I hate the idea of having to open/fund a TOS account to test one freakin scan.

The basic idea is to look for a pullback after a breakout above a specific very narrow Boll Band. The breakout has to have closed above the Top Boll Band at least 5 times and the last 5 of those have to include the pullback.

Anyway, I got the scan written in 2 other platforms to verify the results match and are what he wants. Then I tried to do the translation to TOS. I've written a script and believe the logic is sound. However, my coding of the logic lost something in TOS translation.

Anyone see where I went awry? He tells me the error highlights everything after the first Plot statement (first post-define statement) but gives a typical programming error message. (Might as well say "It don't work...try again!")

Here's the code:

def O = open;
def C = close;
def H = high;
def L = low;
def AVGC50 = Average(close, 50);
def AvgC20 = Average(close, 20);
def MyStDev = 0.382 * StDev(close, 20);
def TopBB = AvgC20 + MyStDev;
def TopBB1 = AvgC20[1] + MyStDev[1];
def TopBB2 = AvgC20[2] + MyStDev[2];
def TopBB3 = AvgC20[3] + MyStDev[3];
def TopBB4 = AvgC20[4] + MyStDev[4];
def MINL7 = Lowest(low, 7);
def MINL8 = Lowest(low, 8);
def MINL9 = Lowest(low, 9);
def MINL10 = Lowest(low, 10);
def MAXH5 = Highest(high, 5);
def MAXH8 = Highest(high, 8);

Plot ThreeAScan = (
C > AVGC50 and
C > TopBB and
C[1] > TopBB1 and
C[2] > TopBB2 and
C[3] > TopBB3 and
C[4] > TopBB4 and
((H < H[1] and H[1] > H[2] AND H[2] > H[3] AND H[3] > H[4]) OR
(H < H[1] and H[1] < H[2] AND H[2] > H[3] AND H[3] > H[4]) OR
(H < H[1] and H[1] < H[2] AND H[2] < H[3] AND H[3] > H[4]) OR
(H < H[1] and H[1] < H[2] AND H[2] < H[3] AND H[3] < H[4])) and
((L[5] = MINL7) OR
(L[6] = MINL8) OR
(L[7] = MINL9) OR
(L[8] = MINL10))
);

Plot ThreeAEntry = (MAXH5 + 0.01);
Plot ThreeAStop = (MINL8 - 0.02);
Plot ThreeATarget = ((MAXH8 - MINL8) + MAXH8);
Plot ThreeAFarTarget = ( (2 * (MAXH8 - MINL8)) + MAXH8 );


Thanks in advance and all suggestions are greatly appreciated.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Better Renko Gaps
The Elite Circle
MC PL editor upgrade
MultiCharts
Exit Strategy
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (permalink)
 
rmejia's Avatar
 rmejia 
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: Options
Posts: 379 since Oct 2010
Thanks Given: 3,614
Thanks Received: 441

The problem is in this part:
((L[5] = MINL7) OR
(L[6] = MINL8) OR
(L[7] = MINL9) OR
(L[8] = MINL10))

the = gives an error. Can it be > or < instead ? or >= ?
(l[5] >= minl7)
(l[5] > minl7)

Reply With Quote
Thanked by:
  #3 (permalink)
esc952
mansfield oh/usa
 
Posts: 4 since Jan 2015
Thanks Given: 2
Thanks Received: 0


I'll have to think on it...but thanks for pointing me straight. I'll change if it doesn't screw up the logic, send it to my Dad and let him run it up the flagpole to see who salutes.

Thanks again. I'll let you know how it goes.

Reply With Quote
  #4 (permalink)
esc952
mansfield oh/usa
 
Posts: 4 since Jan 2015
Thanks Given: 2
Thanks Received: 0

Well, that at least changed the error message. I simplified it a little bit to help figure things out. However, it now doesn't seem to recognize one of my "define" statements.

Simplified code:

def O = open;
def C = close;
def H = high;
def L = low;
def AVGC50 = Average(close, 50);
def AvgC20 = Average(close, 20);
def MyStDev = 0.382 * StDev(close, 20);
def TopBB = AvgC20 + MyStDev;
def TopBB1 = AvgC20[1] + MyStDev[1];
def TopBB2 = AvgC20[2] + MyStDev[2];
def TopBB3 = AvgC20[3] + MyStDev[3];
def TopBB4 = AvgC20[4] + MyStDev[4];
def MINL7 = Lowest(low, 7);
def MINL8 = Lowest(low, 8);
def MINL9 = Lowest(low, 9);
def MINL10 = Lowest(low, 10);
def MAXH5 = Highest(high, 5);
def MAXH8 = Highest(high, 8);

Plot ThreeAScan = (

C > AVGC50 and
C > TopBB and
C[1] > TopBB1 and
C[2] > TopBB2 and
C[3] > TopBB3 and
C[4] > TopBB4 and
((H < H[1] and H[1] > H[2] AND H[2] > H[3] AND H[3] > H[4]) OR
(H < H[1] and H[1] < H[2] AND H[2] > H[3] AND H[3] > H[4]) OR
(H < H[1] and H[1] < H[2] AND H[2] < H[3] AND H[3] > H[4]) OR
(H < H[1] and H[1] < H[2] AND H[2] < H[3] AND H[3] < H[4])) and
((L[5] <= MINL7) OR
(L[6] <= MINL8) OR
(L[7] <= MINL9) OR
(L[8] <= MINL10))
);

Error now generated:

Expected double
No such variable: C at 20:1
No such variable: C at 21:1
No such variable: C at 22:1
No such variable: C at 23:1
No such variable: C at 24:1
No such variable: C at 25:1
No such variable: C at 20:1
No such variable: C at 21:1
No such variable: C at 22:1
No such variable: C at 23:1
No such variable: C at 24:1
No such variable: C at 25:1

Any ideas why it doesn't recognize the "def C = close;" statement ?

Reply With Quote
  #5 (permalink)
 
rmejia's Avatar
 rmejia 
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: Options
Posts: 379 since Oct 2010
Thanks Given: 3,614
Thanks Received: 441

I tried it and got no error, attached images.

Attached Thumbnails
Click image for larger version

Name:	Scan.png
Views:	620
Size:	41.6 KB
ID:	174606   Click image for larger version

Name:	scan1.png
Views:	256
Size:	101.5 KB
ID:	174607  
Reply With Quote
Thanked by:
  #6 (permalink)
esc952
mansfield oh/usa
 
Posts: 4 since Jan 2015
Thanks Given: 2
Thanks Received: 0

Man I really appreciate it. Good to know.

I guess I need to have my dad try it again. (At 80 he's not uber-computer savvy, but he does pick it up quick when shown.)

Again...many thanks!

Reply With Quote




Last Updated on February 11, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts