### How do you calculate the "Spread"?

Fr example we trade XAUUSD vs XAGUSD,

i - bar number
Spread = ClosePrice(XAUUSD, on i) - ClosePrice(XAGUSD, on i)

### How do you calculate the "SpreadMA"?

Moving average of the spread using how many past observations?

observations number of this EA is defined by this EA parm

### How do you calculate the STD? Standard deviation of Spread using how many past observations?

Where can we find that plot with the signal lines in the Statistical Arbitrage software?

- run Stat EA
- run needed Stat EA indicator iSpread that delivered together with EA

after that indicator will plot all signal lines something like that

How is it decided which of the two assets in a pair should be bought and which should be sold?

Spread is calculated as letf_symbol - right_symbol, so

if Spread line crossed PlusSTD line from low to high buy letf_symbol and sell right_symbol
if Spread line crossed Minus STD line from high to low sell letf_symbol and buy right_symbol

so Stat arbitrage theory says

How can we understand from a "Arbitrage detected" log entry what the exact conditions were to trigger the opening of trades?

In the "arbitrage detected" line for gold, there seem to be missing the typical entries for SpreadMinusSTD_1, SpreadMinusSTD_2. Further, there seem to be some additional values like the bid-ask spreads of both traded instruments of a pair. There seem to be some values for bid1 of 21697 -> What is this value? Doesn't seem to be gold or silver price. Why is the second price after bid 1 a price related to gold, but the first price is unrelated to both assets? Following the keyword "Ask" instead, there are two prices of gold and silver. Seems inconsistent/unclear what is what and how the various numbers are being calculated.

Trade condition is tested on each new Bar opening

- Buy LeftSymbol and Sell Right Symbol
if Spread2 < PlusSTD 2 And Spread1 > Plus STD 1 i.e Spread crossed PlusSTD line from down to up

- Sell LeftSymbol and Buy Right Symbol
if Spread2 > MinusSTD 2 And Spread1 < MinusSTD 1 i.e Spread crossed MinusSTD line from up to down

### How exactly is the correlation calculated? Which time series are used as input and how many observations are being used?

Correlation is calculated on Close Price series,
n is defined by EA parameter
input int pi_CorPeriod = 50;//correlation period