{
ѧԺͶʿγϵаԴ
ѧԺȨ
ڽѧĿģϽתӯĿģΥ߱ؾ
C) Plouto-Quants All Rights Reserved

ѧԺ΢ţniuxiaomi3
}

Inputs:
	data_series1(Close of data1), data_series2(Close of data2),
	upper_threshold(-10), lower_threshold(-300);

Variables:
	diff(0), slo(0);

diff = data_series1 - data_series2;
slo = lower_threshold + (upper_threshold-lower_threshold)/2;

// Plot1(diff, "spread_diff");
// Plot2(upper_threshold, "upper_th");
// Plot3(lower_threshold, "lower_th");

if marketposition = 0 then begin
	if diff > upper_threshold then
		sellshort next bar at market;
	if diff < lower_threshold then
		buy next bar at market;
end;

if marketposition = 1 then begin
	if diff cross over slo then
		sell next bar at market;
end;

if marketposition = -1 then begin
	if diff cross under slo then
		buytocover next bar at market;
end;
