I have a problem which might be connected to deselecting the contract.

I have a script which sales options. There is always only one option contract opened.

When I trade only options, the log file looks like this:
Code:
[1002: Fri 15-01-02 20:50] (206.38)
[SPY::SP0201] Write 1 Put 20150220 207.0 100@5.2200  at 20:50:00

[1003: Mon 15-01-05 20:50] +0 -2 0/1  (204.17)
[1004: Tue 15-01-06 20:50] +0 -209 0/1  (202.09)
[1005: Wed 15-01-07 20:50] +0 -365 0/1  (201.42)
[1006: Thu 15-01-08 20:50] +0 -179 0/1  (204.01)
[1007: Fri 15-01-09 20:50] +0 +41 1/0  (206.40)
[1008: Mon 15-01-12 20:50] +0 -61 0/1  (204.41)
[1009: Tue 15-01-13 20:50] +0 -141 0/1  (204.12)
[1010: Wed 15-01-14 20:50] +0 -193 0/1  (199.6500)
[1011: Thu 15-01-15 20:50] +0 -249 0/1  (201.63)
[1012: Fri 15-01-16 20:50] +0 -395 0/1  (198.7700)
[1013: Tue 15-01-20 20:50] +0 -208 0/1  (202.40)
[1014: Wed 15-01-21 20:50] +0 -155 0/1  (201.50)
[1015: Thu 15-01-22 20:50] +0 -69 0/1  (203.99)
[1016: Fri 15-01-23 20:50] +0 +131 1/0  (205.79)
[1017: Mon 15-01-26 20:50] +0 +79 1/0  (204.71)
[1018: Tue 15-01-27 20:50] +0 +165 1/0  (202.97)
[1019: Wed 15-01-28 20:50] +0 -3 0/1  (204.17)
[1020: Thu 15-01-29 20:50] +0 -308 0/1  (200.38)
[1021: Fri 15-01-30 20:50] +0 -75 0/1  (200.57)
[1022: Mon 15-02-02 20:50] +0 -306 0/1  (200.05)
[1023: Tue 15-02-03 20:50] +0 -65 0/1  (203.00)
[1024: Wed 15-02-04 20:50] +0 +124 1/0  (203.92)
[1025: Thu 15-02-05 20:50] +0 +40 1/0  (204.86)
[1026: Fri 15-02-06 20:50] +0 +216 1/0  (206.56)
[1027: Mon 15-02-09 20:50] +0 +214 1/0  (204.77)
[1028: Tue 15-02-10 20:50] +0 +154 1/0  (205.88)
[1029: Wed 15-02-11 20:50] +0 +295 1/0  (206.61)
[1030: Thu 15-02-12 20:50] +0 +328 1/0  (207.89)
[1031: Fri 15-02-13 20:50] +0 +425 1/0  (209.07)
[1032: Tue 15-02-17 20:50] +0 +457 1/0  (209.40)
[1033: Wed 15-02-18 20:50] +0 +471 1/0  (209.66)
[1034: Thu 15-02-19 20:50] +0 +485 1/0  (209.41)
[SPY::SP0201] Cover 1 Put 20150219 207.0 100@0.08000: +491$ at 20:50:00

[1035: Fri 15-02-20 20:50] +491 +0 1/0  (209.48)
[SPY::SP3502] Write 1 Put 20150320 211.0 100@3.1000  at 20:50:00

[1036: Mon 15-02-23 20:50] +491 -2 1/1  (210.94)
[1037: Tue 15-02-24 20:50] +491 +12 2/0  (211.12)
[1038: Wed 15-02-25 20:50] +491 +63 2/0  (211.66)
[1039: Thu 15-02-26 20:50] +491 +55 2/0  (211.52)
[1040: Fri 15-02-27 20:50] +491 +54 2/0  (211.26)


And that's correct.

The problem starts when I try to trade also with the underlying.

When I add these simple lines of code at the end of the script:
Code:
g->contract = 0;
	enterLong(1);


The log file looks like this:
Code:
[1002: Fri 15-01-02 20:50] (206.38)
[SPY::SP0201] Write 1 Put 20150220 207.0 100@5.2200  at 20:50:00
[SPY::SP0201] Cover 1 Put 20150102 207.0 100@5.2200: -2.00 at 20:50:00
[SPY::L0202] Long 1@205.38  at 20:50:00

[1003: Mon 15-01-05 20:50] -2 -4 0/2  (204.17)
[SPY::SP0303] Write 1 Put 20150220 202.0 100@4.6900  at 20:50:00
[SPY::SP0303] Cover 1 Put 20150105 202.0 100@4.6900: -2.00 at 20:50:00
[SPY::L0304] Long 1@201.67  at 20:50:00

[1004: Tue 15-01-06 20:50] -4 -7 0/4  (202.09)
[SPY::SP0405] Write 1 Put 20150220 200.0 100@4.9200  at 20:50:00
[SPY::SP0405] Cover 1 Put 20150106 200.0 100@4.9200: -2.00 at 20:50:00
[SPY::L0406] Long 1@199.8421  at 20:50:00


And that's wrong. Apparently, Zorro closes the option trade by Cover every time Long trade is made with the underlying. But it shouldn't.

When I change the trade with the underlying to enterShort, the result is right. Option trades stay the same, but every day one underlying stock is sold. Log file looks like this:
Code:
[1002: Fri 15-01-02 20:50] (206.38)
[SPY::SP0201] Write 1 Put 20150220 207.0 100@5.2200  at 20:50:00
[SPY::S0202] Short 1@205.38  at 20:50:00

[1003: Mon 15-01-05 20:50] +0 +2 1/1  (204.17)
[SPY::S0303] Short 1@201.67  at 20:50:00

[1004: Tue 15-01-06 20:50] +0 -202 2/1  (202.09)
[SPY::S0404] Short 1@199.8421  at 20:50:00

[1005: Wed 15-01-07 20:50] +0 -365 1/3  (201.42)
[SPY::S0505] Short 1@202.35  at 20:50:00


As you can see, one option contract is opened and one underlying stock is sold, the trades are separate as they should be.

But why doesn't the same thing happen with enterLong?

And there is more... I can turn it around and when I buy PUTs and then buy underlying, it works right. But when I buy option + sell underlying, it doesn't work.