When Wall Street decides to celebrate the gains of 1987, investors and traders will probably go out and paint the town blue.

Blue,as in blue-chip stocks, clearly has been the dominant theme of this market. When the third quarter ended Wednesday, the 30 stocks in the Dow Jones industrial average, the bluest of the blue chips, continued to lead all others.

The Dow was up 36.9 percent for the first nine months of this year. Close behind was the exclusive Standard & Poor's 500, which gained 32.9 percent. The American Stock Exchange index, after a volatile performance, did even better than the S&P by rising 35.4 percent. The AMEX is home to many oil stocks that did well in the last quarter.

To be sure, most of these impressive gains came during a blizzard of buying in January and February. The action slowed in the spring but picked up again in the summer and fall.

The Dow, for instance, rose 21.6 percent in the first quarter but only 4.9 percent in the second quarter. However, the third quarter was better, with the Dow moving up 7.4 percent during July, August and September.

The third quarter also saw the brass-chips, or secondary stocks, doing a better job of keeping up with the blue chips.

Blue-chip stocks get the heaviest play because they offer cash-rich institutional investors, such as pension funds, the safety associated with widely known, dividend-paying stocks that are easy to buy and sell in large blocks. Foreign investors like them for the same reason.

The inevitable drawback to a blue-chip rally is that it contains the seeds of a blue-chip sell-off. The 8 percent correction in late August and early September demonstrated how fast even the blue chips can fall.

Washington area stocks generally trailed the Dow, S&P 500 and other major averages. The Johnston, Lemon & Co. index of 30 local blue chips rose 25.4 percent for the nine months, with most of the gain coming in the first quarter. In the second quarter, the Johnston, Lemon index eked out only a 2.4 percent advance, but an improving market gave the index a 5.3 percent gain in the third quarter.

The Growth Fund of Washington, operated by Johnston, Lemon, was up 25.8 percent for the year. Its rise of 6.23 percent for the third quarter put it ahead of the S&P 500, which gained 5.9 percent.

Prabha Carpenter, an officer at Geico Investment Services, which manages the Growth Fund portfolio, noted that the fund had good gains in three core holdings: Giant Food, Bell Atlantic and The Washington Post.

The Southeastern Growth Fund, run by Wheat, First Securities was up 20.5 percent for the nine months, gaining 4.7 percent in the third quarter. Theodore W. Price, fund president, said his fund lagged the broad averages, in part because he has about 17 percent of his money invested in bank stocks. Price said he expects eventually to see a "major explosion" in those stocks.

Similarly, Joseph A. Clorety III, manager of The Calvert Group's Washington Area Growth Fund, said his fund's performance was dragged down by his emphasis on financial stocks, especially thrifts.

"I've chosen to go after value in the financial services area ... which will benefit the fund in the long-term, even though I know that in the short-term it will be painful," he said. The Washington Area Growth Fund gained 18.3 percent for the nine months, with a 3.3 percent rise in the third quarter.

Meanwhile, here are the winners and losers among area stocks for the first nine months of the year, with Sept. 30 prices and the percentage of gain or loss since Jan. 1.

The winners:

1. A.H. Robins of Richmond ($27, up 243 percent). Shares of Robins, a drug manufacturer, slid when the company sought protection in bankruptcy from the claims of Dalkon Shield users. Under a pending merger agreement with Rorer Group Inc., Robins shareholders would get about $35 worth of Rorer stock for each Robins share.

2. Reynolds Metals of Richmond ($59, up 195 percent) has benefitted from a heavier demand for aluminum and other Reynolds products.

3. QuesTech of McLean ($15, up 186 percent) is a turnaround situation in which new managers have improved the firm's government contracting business.

4. Entre Computer Centers of Vienna ($7, up 173 percent) is recuperating from the shakeout in the computer industry and from troubles with its franchisees.

5. Danaher Corp. of Washington ($15.88, up 157 percent) is the vehicle that brothers Steven and Mitchell Rales have used to acquire a group of old industrial companies.

6. Strategic Planning Associates of Washington ($28.25, up 130 percent). A management consultant firm, SPA saw its stock soar in recent days on a favorable report by Dillon, Read & Co., the firm that took SPA public.

7. Iverson Technology of McLean ($21.50, up 130 percent) specializes in the Tempest technology that makes computers secure from electronic eavesdropping.

8. Media General of Richmond ($42.38, up 99 percent), the newspaper and broadcasting company, has been helped by rising profits and heavy attention on media stocks.

9. American Management Systems of Arlington ($18.88, up 96 percent) supplies business computer systems and has a history of steadily improving earnings.

10. Biotech Research Labs of Rockville ($10.63, up 85 percent) has moved up on the strength of its involvement in AIDS testing.

11. Comnet Corp. of Washington ($14.50, up 81 percent) has recorded strong showings by its computer and pharmaceutical divisions.

12. Avemco of Frederick ($23.50, up 79 percent), a writer of private airplane insurance, has seen its profits take off again.

13. Washington Homes of Waldorf ($14.13, up 77 percent) has been moving higher on efforts by investors to acquire part or all of the company.

14. Cadmus Communications of Richmond ($24.75, up 72 percent) is a rapidly expanding printing company.

15. The Washington Post ($263, up 69 percent) has benefitted from a strong market niche and expanding business prospects.

Here are the largest losers:

1. MBI Business Centers of Rockville (50 cents, down 91 percent) declined after financial difficulties forced the computer service firm to file for bankruptcy.

2. TVI Corp. of Beltsville (34 cents, down 76 percent). A maker of military practice targets and computerized medical equipment, TVI was forced to make accounting changes that changed a profit to a loss for the six months ending June 30.

3. Stanwick Corp. of Washington (50 cents, down 60 percent) is in liquidation.

4. Insituform East of Landover ($7.13, down 48 percent), which repairs sewer pipes without digging them up, has problems with profitability.

5. Sporting Life of Alexandria ($2.88, down 48 percent). A mail-order catalogue firm selling women's apparel, Sporting Life has seen sales rise, but profits have lagged.

6. Cerberonics of Baileys Crossroads ($4.75, down 47 percent), a defense services firm, has been diversifying by taking a major position in Insituform East stock and by acquiring a copying machine dealership.

7. Universal Security Instruments of Owings Mills ($2.69, down 46 percent) is a manufacturer of security systems and communications equipment.

8. Dominion Federal Savings & Loan of Tysons Corner ($9, down 43 percent) has been hurt by a $129 million judgment in a court case brought by Penthouse magazine.

9. NV Ryan L.P. of McLean ($6.25, down 35 percent) has felt the impact of rising interest rates, which soften the market for new homes.

10. Preston Corp. of Preston, Md., ($15.50, down 34 percent) has been hurt by falling freight rates in the trucking industry.

11. Energy Capital Development of Rosslyn ($1.75, down 30 percent) is in the oil and gas business in West Virginia and Ohio.

12. Polk Audio of Baltimore ($7.88, down 28 percent) has lost ground because of earnings disappointments.

13. Old Dominion Systems of Germantown ($3, down 25 percent). A professional services firm, Old Dominion has seen profits lag despite rising sales.

14. VM Software of Reston ($15.25, down 24 percent), provides software for IBM mainframe computers. After a long climb, VM stock retreated on faltering earnings.

15. General Kinetics of Rockville ($4.06, down 23 percent) provides equipment used aboard Navy ships.