-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStrat_BrokerArb.c
47 lines (40 loc) · 1.57 KB
/
Strat_BrokerArb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Broker arbitrage example ////////////////////////////
// you can compare currency or CFD prices between broker A and broker B ...
// ... and enter a long position with the cheaper broker and a short position with the other
// There is special account list and asset list
#define ASSET_A "EURUSD_A"
#define ASSET_B "EURUSD_B"
function tick()
{
asset(ASSET_A);
var SpreadA = Spread, PriceA = priceClose(),
CommissionA = Commission*LotAmount/10000*PIP/PIPCost; // convert commission to price difference
asset(ASSET_B);
var SpreadB = Spread, PriceB = priceClose(),
CommissionB = Commission*LotAmount/10000*PIP/PIPCost;
var Threshold = 1.5*(SpreadA+SpreadB+CommissionA+CommissionB); // arbitrage threshold
var Difference = PriceA - PriceB;
printf("\n[%s.%.0f] A %.5f B %.5f",
strdate(HMS,0),1000.*modf(second(),0),PriceA,PriceB);
asset(ASSET_A);
if(NumOpenShort && Difference < 0) exitShort();
else if(NumOpenLong && Difference > 0) exitLong();
else if(!NumOpenShort && Difference > Threshold) enterShort(); // go short with the expensive asset
else if(!NumOpenLong && Difference < -Threshold) enterLong(); // go long with the cheap asset
asset(ASSET_B);
if(NumOpenShort && Difference > 0) exitShort();
else if(NumOpenLong && Difference < 0) exitLong();
else if(!NumOpenShort && Difference < -Threshold) enterShort();
else if(!NumOpenLong && Difference > Threshold) enterLong();
}
function run()
{
if(!require(-2.1)) return;
StartDate = EndDate = 2018;
LookBack = 0;
set(TICKS|LOGFILE);
History = ".t1";
assetList("AssetsArb.csv");
asset(ASSET_A);
asset(ASSET_B);
}