Simultaneous long and short signals

Questions about MultiCharts and user contributed studies.
Joe1001
Posts: 16
Joined: 24 Oct 2012
Has thanked: 1 time
Been thanked: 1 time

Simultaneous long and short signals

Postby Joe1001 » 11 May 2015

How to get rid off simultaneous long/short signals on the same bar (at open or close)? These should normally cancel out. is there a setting or should it be done with code? My strategy generates occasionally both long and short at the same time. Thanks in advance.

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: Simultaneous long and short signals

Postby tony » 11 May 2015

Are you saying you are generating a long and a short at the same time? You'll need to use marketposition = 0 ahead of long conditional statements and the short conditional statements. This way a long can only generate if MP = 0 and the same with a short. For example if you are long one lot then MP = 1 and a short would not be able to generate as the first statement MP=0 is false.

You can also check the box to only allow one entry per bar either for the strategy or all strategies (something like that).

Joe1001
Posts: 16
Joined: 24 Oct 2012
Has thanked: 1 time
Been thanked: 1 time

Re: Simultaneous long and short signals

Postby Joe1001 » 11 May 2015

Thanks but this is also happening when the system is flat, MP=0. Then I get both a short and a long at the same time. I would like to get rid off those redundant signals from backtest.

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: Simultaneous long and short signals

Postby tony » 11 May 2015

Your code is likely wrong. If you post it here, we can give more guidance. You should precede your long and short conditionals with IF MP=0 then begin

hughesfleming
Posts: 275
Joined: 22 Apr 2014
Has thanked: 70 times
Been thanked: 72 times

Re: Simultaneous long and short signals

Postby hughesfleming » 12 May 2015

I have it setup like this to avoid two entry signals.

Code: Select all


if GoLong and GoShort = true then GoLong = False;
if GoLong and GoShort = true then Goshort= False;

if GoLong then
Buy ( "Long" ) positionsize contracts next bar market;
if GoShort then
SellShort ( "Short" ) positionsize contracts next bar market ;


tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: Simultaneous long and short signals

Postby tony » 12 May 2015

Without trying it in a script here are a few thoughts.

My preference would be to use market position as noted above, but if you prefer your method I would try the following:

Notice how you say two different times if golong and goshort = true then in one instance golong=false and with the same conditional being true that goshort=false

You should write something like

if golong=true AND goshort=true then golong=false

this would say that if both are ever true to take a short position, or if your preference is a long, then change to

if golong=true AND goshort=true then goshort=false

Another thing. Notice where you have the conditional to actually buy or sell short. You should say if golong=true then and if goshort=true then

I haven't tried these so I don't know what will work, but there are a few things for you to test out.

Joe1001
Posts: 16
Joined: 24 Oct 2012
Has thanked: 1 time
Been thanked: 1 time

Re: Simultaneous long and short signals

Postby Joe1001 » 12 May 2015

Thanks guys. I tried market position and it doesn't works. I also tried something along the lines suggested by Hughes and it seems to work:

Code: Select all

If golong and Not goshort then buy next bar market

If goshort and Not golong then sell short next bar market

hughesfleming
Posts: 275
Joined: 22 Apr 2014
Has thanked: 70 times
Been thanked: 72 times

Re: Simultaneous long and short signals

Postby hughesfleming » 13 May 2015

I am glad you got it sorted out.

Alex


Return to “MultiCharts”