Support for pair trading

If I have two instrument, contract A and contract B.



Based on the spread of A and B, buy A and sellshort B, or sellshort A and buy B at the same time.


IN the MC, it could be implemented by global variables.  



[Strategy Pair_1] var:var1(0),var2(0),P(0); var1=close of data1; var2=close of data2; P=var1-var2; condition1=P>=1 and P<2 and EntriesToday(date)<1 and marketposition=0; if condition1 then begin buy("P1") next bar at market; pmm_set_global_named_num("PAIR",1); end; condition2=P>=2 and P<3 and EntriesToday(date)<1; if condition2 then begin buy("P2") next bar at market; pmm_set_global_named_num("PAIR",2); end; condition3=P>=3 and P<4 and EntriesToday(date)<1; if condition3 then begin Sell("Sell P1") from entry("P1") next bar at market; pmm_set_global_named_num("PAIR",3); end; condition3=P>=3 and P<4 and EntriesToday(date)<1; if condition3 then begin Sell("Sell P1") from entry("P1") next bar at market; pmm_set_global_named_num("PAIR",3); end; condition4=P>=4 and P<5 and EntriesToday(date)<1; if condition3 then begin Sell("Sell P2") from entry("P2") next bar at market; pmm_set_global_named_num("PAIR",4); end;  [Strategy Pair_2] var:vMode(0); vMode=pmm_get_global_named_num("PAIR"); switch vMode begin case 1: sellshort("P1") next bar at market; case 2:Sellshort("P2") next bar at market; case 3:buytocover("Buytocover P1") from entry("P1") next bar at market; case 4:buytocover("Buytocover P2") from entry("P2") next bar at market; end;








Attachments
No attachments
  • Votes +1
  • Project StrategyQuant X
  • Type Feature
  • Status Duplicate
  • Priority Normal
  • Assignee Mark Fric
  • Milestone Build 129

History

e
#1

eastpeace

11.12.2018 13:01

Task created

Rr
#2

Partizanas

11.12.2018 16:20
Voted for this task.
KL
#3

kainc301

11.12.2018 20:40

Many threads about this. Anytime this gets mentioned, I will link my posts to ideas regarding this topic 


https://roadmap.strategyquant.com/tasks/sqp_0027


https://roadmap.strategyquant.com/tasks/sq4_2829


MF
#4

Mark Fric

13.05.2020 13:19

Assignee changed from Mark Fric to Mark Fric

Status changed from New to Duplicate

Milestone changed from None to Build 129


Votes: +1

Drop files to upload

or

choose files

Max size: 5MB

Not allowed: exe, msi, application, reg, php, js, htaccess, htpasswd, gitignore

...
Wait please