| SID Name | Description | Rating | Updated |  | 649 TopBottom | An example showing how to create a list of the top winners and losers from a portfolio of stocks using the filter, rank and set functionality. | Not Approved | 2008-03-08 |
 | Notes for this Trading Account: |
 | Rules for this Trading Account: |
 | Notes for this Trading System: |
 | Rules for this Trading System: |
 | Bar event logic: |
#See the End event for the code
 | End event logic: |
#The number of symbols we'll include in the top and bottom
my $number = 5;
#The path to save the HTML file
my $path='C:\Developement\TopBottom.html';
if (FirstNewBar) {
#create the base set - we use the percentage change as the base for ranking.
my $set= Filter { Percent(Close); };
#we now create our top and bottom sets
my $topfive = $set > $number;
my $bottomfive = $set < $number;
#Our HTML output string
my $output = "<b>The top $number<b>".'<p><table border=1><tr><td>Symbol</td><td>Closing Price</td><td>Change</td><td>RSI</td></tr>';
#we now run our filter on the top Set
Filter { $output.='<tr><td>'.Symbol.'</td><td>'.Now(Close).
'</td><td>'.Round(Now(Percent(Close)),2).
'%</td><td>'.Round(Now(RSI(14)),2).'</td></tr>'; } $topfive;
$output.='</table>';
$output.= "<p><b>The bottom $number<b>".'<p><table border=1><tr><td>Symbol</td><td>Closing Price</td><td>Change</td><td>RSI</td></tr>';
#we now run our filter on the bottom Set
Filter { $output.='<tr><td>'.Symbol.'</td><td>'.Now(Close).
'</td><td>'.Round(Now(Percent(Close)),2).
'%</td><td>'.Round(Now(RSI(14)),2).'</td></tr>'; } $bottomfive;
#finish the HTML
$output.='</table>';
#save the HTML - open a file
open (OUTPUT, "> $path") or die "can't open file $path";
#print the output to the file
print OUTPUT $output;
close OUTPUT;
}
|