how to exit only one contract for multiple contracts setting  [SOLVED]

Questions about MultiCharts and user contributed studies.
maisatomai
Posts: 83
Joined: 18 Mar 2013
Has thanked: 11 times

how to exit only one contract for multiple contracts setting

Postby maisatomai » 08 Mar 2016

Hi I allow multiple entry for my signal. let say i buy this bar at close 4 times at 4 different timing and now my net position is 4.

If I has a code saying sell this bar at close, then it will sell all 4. How do I sell 1 by 1 instead of all 4?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: how to exit only one contract for multiple contracts set

Postby TJ » 08 Mar 2016

Hi I allow multiple entry for my signal. let say i buy this bar at close 4 times at 4 different timing and now my net position is 4.

If I has a code saying sell this bar at close, then it will sell all 4. How do I sell 1 by 1 instead of all 4?

SELL 1 Contract next bar at market;

maisatomai
Posts: 83
Joined: 18 Mar 2013
Has thanked: 11 times

Re: how to exit only one contract for multiple contracts set

Postby maisatomai » 09 Mar 2016

Thanks but it don't really work.

I have your code and it don't work

Code: Select all

if (Random(10)>9.9) then begin
if (marketposition>=0) then
buy 1 Contract next bar at market
else if (marketposition<0) then
buy to cover 1 Contract next bar at market;
end;
if (Random(10)<0.1) then begin
if (marketposition>0) then
sell 1 Contract next bar at market
else if (marketposition<=0) then
sellshort 1 Contract next bar at market;
end;
The output is this.
Image


My desired output is at the 1325 bar, instead of cover 3, it should just cover 1 only

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: how to exit only one contract for multiple contracts set

Postby TJ » 09 Mar 2016

Thanks but it don't really work.

I have your code and it don't work
::
Is this all your code?

maisatomai
Posts: 83
Joined: 18 Mar 2013
Has thanked: 11 times

Re: how to exit only one contract for multiple contracts set

Postby maisatomai » 09 Mar 2016

Thanks but it don't really work.

I have your code and it don't work
::
Is this all your code?
yes you can try it on your side. and I think you will get the same result.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: how to exit only one contract for multiple contracts set  [SOLVED]

Postby JoshM » 09 Mar 2016

Hi I allow multiple entry for my signal. let say i buy this bar at close 4 times at 4 different timing and now my net position is 4.

If I has a code saying sell this bar at close, then it will sell all 4. How do I sell 1 by 1 instead of all 4?
Thanks but it don't really work.

I have your code and it don't work
::
Is this all your code?
yes you can try it on your side. and I think you will get the same result.
That's true, adding the number to an order doesn't sell a position 1 by 1. However, you can use the Total keyword for that.

For example:

Code: Select all

if (Random(10)>9.9) then begin
if (marketposition>=0) then
buy 1 Contract next bar at market
else if (marketposition<0) then
buy to cover 1 Contract total next bar at market;
end;
if (Random(10)<0.1) then begin
if (marketposition>0) then
sell 1 Contract total next bar at market
else if (marketposition<=0) then
sellshort 1 Contract next bar at market;
end;
Looks like:

Image

Now each sell order closes the oldest long contract (first in, first out). If you want more control over your orders, you can use from entry to specify which entry order should be closed by an order.
Attachments
scr.09-03-2016 09.52.15.png
(8.76 KiB) Downloaded 781 times


Return to “MultiCharts”