#!/usr/bin/tclsh package require csv package require RBTree # This is our standard interpretation of a CSV file. It's an array matching a pair of strings to a string. The top row is the list of column headers. The left column is the list of row headers. The rest of the grid is the data which can be indexed by row and column. The empty string is always the default for missing data. The value in the top left corner is returned in the list of column headers, but is not used anywhere else. # This is implemented as an RBTree mapping row headers to rows. Each row is an RBTree matching column headers to data items. proc read_from_csv_file {filename matrix_var {rows_var {}} {cols_var {}}} { upvar $matrix_var matrix set matrix [tree::create] if {$rows_var != {}} { upvar $rows_var rows } set rows {} set handle [open $filename RDONLY] if {$cols_var != {}} { upvar $cols_var headers } set headers [::csv::split [gets $handle]] while {![eof $handle]} { set line [gets $handle] if {$line == {}} { continue } set line [::csv::split $line] set row [::tree::create] foreach item $line col_header $headers { if {($col_header != {}) && ($item != {})} { tree::map insert row $col_header $item } } set row_header [lindex $line 0] tree::map insert matrix $row_header $row lappend rows $row_header } close $handle llength $rows } proc get_from_csv {csv row_header col_header {default {}}} { set row [tree::map value csv $row_header {}] tree::map value row $col_header $default } read_from_csv_file F_OvernightData.csv f_data symbols read_from_csv_file OvernightData.csv o_data read_from_csv_file TC_OvernightData.csv tc_data # symbols may have dups because of the way we build that file. We copy from # several sources and blindly append them all together. Some symbols, like # QQQQ, are tracked on multiple servers. set symbols [lsort -unique $symbols] ############################################################################### # Weston ############################################################################### set handle [open weston_exclude_list.txt {RDONLY}] while {![eof $handle]} { set symbol [string trim [gets $handle]] if {$symbol != ""} { set weston_exclude_set($symbol) $symbol } } close $handle proc add_weston_symbols {symbols} { set symbols [lsort -unique [concat $symbols {BGU TNA UPRO SVXY UVXY NUGT}]] set result {} global weston_exclude_set foreach symbol $symbols { if {![info exists weston_exclude_set($symbol)]} { lappend result $symbol } } set result } set to_track {} foreach symbol $symbols { set exchange [get_from_csv $f_data $symbol {Listed Exchange}] set vol [get_from_csv $o_data $symbol {Avg Daily Volume}] if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX")) && ($vol >= 300000)} { lappend to_track $symbol } } set to_track [add_weston_symbols $to_track] set handle [open weston_symbols.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle #set to_track {} #foreach symbol $symbols { # set exchange [get_from_csv $f_data $symbol {Listed Exchange}] # set vol [get_from_csv $o_data $symbol {Avg Daily Volume}] # set price [get_from_csv $o_data $symbol {Last Price}] # if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX")) && ($vol >= 300000) && ($price >= 1)} { # lappend to_track $symbol # } #} #set to_track [add_weston_symbols $to_track] #set handle [open weston_symbols_hilo.txt {WRONLY CREAT TRUNC}] #foreach symbol $to_track { # puts $handle $symbol #} #close $handle set to_track {} foreach symbol $symbols { set exchange [get_from_csv $f_data $symbol {Listed Exchange}] if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX"))} { lappend to_track $symbol } } set to_track [add_weston_symbols $to_track] set handle [open weston_symbols_more.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle set to_track {} foreach symbol $symbols { set exchange [get_from_csv $f_data $symbol {Listed Exchange}] set price [get_from_csv $o_data $symbol {Last Price}] if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX")) && ($price >= 1)} { lappend to_track $symbol } } set to_track [add_weston_symbols $to_track] set handle [open weston_symbols_more_hilo.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle set to_track {} foreach symbol $symbols { set exchange [get_from_csv $f_data $symbol {Listed Exchange}] set price [get_from_csv $o_data $symbol {Last Price}] if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX")) && ($price >= 10)} { lappend to_track $symbol } } set to_track [add_weston_symbols $to_track] set handle [open weston_symbols_345.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle ############################################################################### # TI Pro Server ############################################################################### set to_track {} foreach symbol $symbols { set vol [get_from_csv $o_data $symbol {Avg Daily Volume}] if {$vol >= 300000} { lappend to_track $symbol } } set handle [open ../../data/Symbols.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle ############################################################################### # Consolidation set. Jamie, Boensch, etc. ############################################################################### set to_track {} foreach symbol $symbols { set exchange [get_from_csv $f_data $symbol {Listed Exchange}] set vol [get_from_csv $o_data $symbol {Avg Daily Volume}] set price [get_from_csv $o_data $symbol {Last Price}] if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX")) && ($vol >= 200000) && ($price >= 0.50) && ($price <= 200.0)} { lappend to_track $symbol } } set handle [open ConsolidationSet_symbols.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle ############################################################################### # Arthur Ilyayev ############################################################################### set to_track {} foreach symbol $symbols { set exchange [get_from_csv $f_data $symbol {Listed Exchange}] set vol [get_from_csv $o_data $symbol {Avg Daily Volume}] set price [get_from_csv $o_data $symbol {Last Price}] if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX")) && ($vol >= 20000) && ($price >= 10.00) && ($price <= 150.00)} { lappend to_track $symbol } } set handle [open ArthurIlyayev_symbols.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle ############################################################################### # Vito Garfi ############################################################################### set to_track {} foreach symbol $symbols { set exchange [get_from_csv $f_data $symbol {Listed Exchange}] set vol [get_from_csv $o_data $symbol {Avg Daily Volume}] set price [get_from_csv $o_data $symbol {Last Price}] if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX") || ($exchange == "ARCA")) && ($vol >= 50000) && ($price >= 5.00) && ($price <= 1000.00)} { lappend to_track $symbol } } set handle [open VitoGarfi_symbols.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle set to_track {} foreach symbol $symbols { set exchange [get_from_csv $f_data $symbol {Listed Exchange}] set vol [get_from_csv $o_data $symbol {Avg Daily Volume}] set price [get_from_csv $o_data $symbol {Last Price}] if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX") || ($exchange == "ARCA")) && ($vol >= 50000) && ($price >= 2.00)} { lappend to_track $symbol } } set handle [open VitoGarfi_bb_symbols.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle ############################################################################### # Chris Pavelic ############################################################################### set to_track {} foreach symbol $symbols { set exchange [get_from_csv $f_data $symbol {Listed Exchange}] set vol [get_from_csv $o_data $symbol {Avg Daily Volume}] set price [get_from_csv $o_data $symbol {Last Price}] if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX") || ($exchange == "ARCA")) && ($price >= 5.00) && ($price <= 500.00)} { lappend to_track $symbol } } set handle [open ChrisPavelic_symbols.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle ############################################################################### # Koyote ############################################################################### set to_track {} set to_track_1 {} foreach symbol $symbols { set exchange [get_from_csv $f_data $symbol {Listed Exchange}] set vol [get_from_csv $o_data $symbol {Avg Daily Volume}] set price [get_from_csv $o_data $symbol {Last Price}] if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX")) && ($vol >= 300000) && ($price > 2.0) && [regexp {^[A-Z]+$} $symbol]} { lappend to_track $symbol } if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX")) && ($vol >= 150000) && ($price > 2.0) && [regexp {^[A-Z]+$} $symbol]} { lappend to_track_1 $symbol } } set handle [open koyote_symbols.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle set handle [open koyote_symbols_150k.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track_1 { puts $handle $symbol } close $handle ############################################################################### # Shane Bird ############################################################################### set to_track {} foreach symbol $symbols { set exchange [get_from_csv $f_data $symbol {Listed Exchange}] set vol [get_from_csv $o_data $symbol {Avg Daily Volume}] set price [get_from_csv $o_data $symbol {Last Price}] if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX")) && ($vol >= 1000000) && ($price >= 10.00) && ($price <= 300.0)} { lappend to_track $symbol } } set handle [open ShaneBird_symbols.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle ############################################################################### # SMB ############################################################################### array set smb_etfs {} set handle [open smb_etf_symbols.txt RDONLY] while {![eof $handle]} { set line [gets $handle] set smb_etfs($line) 1 } close $handle set to_track {} set to_track_more {} foreach symbol $symbols { set exchange [get_from_csv $f_data $symbol {Listed Exchange}] set vol [get_from_csv $o_data $symbol {Avg Daily Volume 60}] set price [get_from_csv $o_data $symbol {Last Price}] # We use the 20 day ATR here and the quarterly ATR in the real-time # code. set atr [get_from_csv $f_data $symbol {ATR 20}] if {$atr == {}} { # This will cause the test to fail. set atr 0 } set sma20 [get_from_csv $tc_data $symbol {20 Day SMA}] if {$sma20 == {}} { # The requirement is that we can look at a stock after 3 days of # trading history. vol and price work after at least 1 day, and # atr works after at least 3 days. SMA 20 would take 20 days to fill. # So, if we don't have a 20 day SMA, we just ignore that test. set sma20 0 } if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX")) && ($vol >= 800000) && ($price >= 10.00) && ($price <= 500.0) && ($atr >= 0.75) && ($atr >= $sma20 * 0.01) && (![info exists smb_etfs($symbol)])} { lappend to_track $symbol } if {(($exchange == "NYSE") || ($exchange == "NASD")) && ($vol >= 250000) && ($price <= 500.0) && ($atr >= $sma20 * 0.01) && (![info exists smb_etfs($symbol)])} { lappend to_track_more $symbol } } set handle [open smb_normal_symbols.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle set handle [open smb_more_symbols.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track_more { puts $handle $symbol } close $handle ############################################################################### # Joe Favaloro ############################################################################### set to_track {} foreach symbol $symbols { set exchange [get_from_csv $f_data $symbol {Listed Exchange}] set vol [get_from_csv $o_data $symbol {Avg Daily Volume}] set price [get_from_csv $o_data $symbol {Last Price}] if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX") || ($exchange == "ARCA")) && ($vol >= 100000) && ($price >= 2.00)} { lappend to_track $symbol } } set handle [open JoeFavaloro_symbols.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle ############################################################################### # Big Bear ############################################################################### set to_track {} foreach symbol $symbols { set exchange [get_from_csv $f_data $symbol {Listed Exchange}] set vol [get_from_csv $o_data $symbol {Avg Daily Volume}] set price [get_from_csv $o_data $symbol {Last Price}] if {(($exchange == "NYSE") || ($exchange == "NASD") || ($exchange == "AMEX") || ($exchange == "ARCA")) && ($vol >= 300000)} { lappend to_track $symbol } } set handle [open BigBear_symbols.txt {WRONLY CREAT TRUNC}] foreach symbol $to_track { puts $handle $symbol } close $handle