Powerful computers can wreak havoc on U.S. stock markets, creating hair-raising volatility and eroding investor confidence in the lightning-fast search for profit.

But far more powerful computers, such as a supercomputer run by Berkeley scientists, could help save it.

High-speed trading now dominates U.S. stock markets, buying and selling in a fraction of the time that it takes to blink. Computers detecting rapid swings in prices and instantly reacting builds volatility and more trades, generating a sea of chaotic data and a vicious feedback loop that can lead to nightmares far worse than May 2010’s infamous “flash crash.”

Faster still is “Edison,” a supercomputer tended by Lawrence Berkeley Laboratory scientists in a former Wells Fargo Bank building in downtown Oakland. Edison-like computers could track ultrafast trading across the nation’s many markets, detecting precursors to a crash — and sounding early warnings for regulators seeking to avert a gruesome economic wreck.

It would be like a NASCAR race yellow flag warning drivers to slow down, scientists say.

“If improved monitoring and regulation can build some greater trust in the market, everyone benefits,” said David H. Bailey, director of the lab’s new Center for Innovative Financial Technology, which is building a bridge that links computational science and financial market communities.

Edison loves big data. Its idea of an average day is simulating a supernova explosion, measuring the expanding universe’s rate of acceleration. Or modeling 150 years of Earth’s future climate change — in three dimensions.

When fully deployed later this year, Edison will perform as many as 2 quadrillion operations a second. How big is that number? Two quadrillion cups of water would fill Lake Tahoe twice.

Tracking every trade, in real time, on every U.S. stock exchange? No big deal.

“That data size — we routinely do 10 times that much. Easily. It’s a trivial matter,” said Bailey, a leading figure in both high-performance scientific computing and computational mathematics.

Not so long ago, life was simpler. U.S. stock markets moved at a human pace, simply matching buyers with sellers. But now many exchanges take place. And more than half of all trading is done by high-speed computer “traders” that live their electronic lives in server parks.

Most agree that computer trading is good for the average investor because it’s inexpensive. But it also triggers unpredictably large price swings — causing widespread Maalox moments. It’s breeding distrust in the market.

The “flash crash” of 2010 was triggered by a single firm using algorithms to rapidly sell 75,000 futures contracts. In moments, the Dow Jones industrial average fell more than 700 points, or almost 10 percent, and quickly recovered.

How crazy was it? Apple briefly traded for $10,000 a share. Within seconds, Accenture traded at $40 and then 1 cent.

Since then, numerous mini-flash crashes and other anomalies have slapped around stock values and investor confidence.

“Electronic markets … seem capable of impressively flaky behavior,” said Lawrence Berkeley Lab’s David Leinweber, a computer scientist, former investment manager and algorithmic trading specialist.

“We are lost in the jungle when it comes to our ability to understand ever-faster markets well enough to keep them safe, stable and secure,” he said.

Regulators with weak and incompatible computer systems have set safeguards. One uses shutdown switches — “circuit breakers” — to halt all trading. A second, “Limit Up, Limit Down,” cancels trades outside a normal price range.

But these, asserted Leinweber, are like applying the rules of the road to aircraft. Slowing, rather than suddenly halting, markets is less traumatic.

In early 2011, using the lab’s Cray XE6 “Hopper” supercomputer, Leinweber’s team found that a supercomputer could use a recently identified measure to warn of a looming flash crash.

Called Volume-synchronized Probability of INformed trading, or VPIN, it detects an imbalance between buy and sell orders, and growing volatility, about 45 minutes before a crash. It reveals “flow toxicity,” that is, when high-tech traders’ computers generate so many buy or sell orders that it becomes all but impossible to match orders. Amid this volatility, one side will stop trading to stem its losses, causing a sudden drop of prices that triggers an avalanche of similar withdrawals called a “flash crash.”

A second measure of market instability, the Herfindahl-Hirshman Index, or HHI, also rose sharply for some stocks, although not for others.

These two signals of instability — and that uneasy feeling that someone else has more information than you — do not give a clear direction of specific trades, said the lab’s John Wu. So they are not likely to be exploited by someone hoping to jump in and profit.

But they might be useful “for regulators to impose some rules that might slow down the market so we don’t get into a sort of feeding frenzy,” he wrote in an email.

Market experts said they saw promise in the idea. Leinweber “is well situated to speak to the role that machine learning and artificial intelligence can play for detecting patterns in markets,” said David Andre of San Francisco’s Cerebellum Capital.

A venture firm leader sees Leinweber’s work in the forefront of understanding market complexities. “Leveraging ‘smart’ machines to parse and extract signals from massive quantities of textual data is hard, and David’s work has put him at the vanguard of the next wave of the alpha generation,” said Roger Ehrenberg of the New York City-based venture firm IA Ventures.

Bryan Harkins, chief operating officer at Direct Edge, the fourth-largest stock exchange, was more cautious: “It is great that the academic community has chimed in — not that we choose any specific winning idea, but these different ideas and themes are woven into what we are seeing as we look to improve the market.”

The Securities and Exchange Commission, which went before Congress to ask for a 2013 budget increase of $245 million to “strengthen oversight of market stability and expand the agency’s information technology systems,” has not commented on the lab’s research.

U.S. Commodity Futures Trading Commission Commissioner Scott O’Malia supports their work, writing in response to publication of their paper: “I am certain that our national labs can improve our market surveillance capabilities and open our eyes to new and innovative means to improve our real-time oversight of market.”

The scientists say they don’t want Edison to do the SEC’s work — the computer belongs to the U.S. Department of Energy.

But they hope to study the possibilities more, marking the path to the next generation of market surveillance.

“We have got to find a way to make the system work and monitor it,” he said. “If this science is better understood, perhaps another flash crash can be averted.”

Contact Lisa M. Krieger at 650-492-4098.