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;
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
Assignee changed from Mark Fric to Mark Fric
Status changed from New to Duplicate
Milestone changed from None to Build 129