SetStopLoss Confilct with two systems applied to one chart.  [SOLVED]

Questions about MultiCharts and user contributed studies.
no erocla
Posts: 134
Joined: 31 May 2013
Has thanked: 60 times
Been thanked: 7 times

SetStopLoss Confilct with two systems applied to one chart.

Postby no erocla » 07 Jul 2013

Hi guys, i've got a problem.


I've two systems applied to 1 chart:

System 1 : With Stop loss
System 2 : Without Stop loss

System 2 read the stop loss of System 1, going out from the market many times.
I think that it happens, because "SetStopLoss" function works if Marketposition <> 0.

Anyone have some ideas to solve this problem ?

Thank you very much in any case.

Cordially

No Erocla

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

Re: SetStopLoss Confilct with two systems applied to one cha

Postby TJ » 07 Jul 2013

Hi guys, i've got a problem.
I've two systems applied to 1 chart:
System 1 : With Stop loss
System 2 : Without Stop loss
System 2 read the stop loss of System 1, going out from the market many times.
I think that it happens, because "SetStopLoss" function works if Marketposition <> 0.
Anyone have some ideas to solve this problem ?
Thank you very much in any case.
Cordially
No Erocla
1. I would use the KISS principle... combine the systems in one strategy.

2. Please start here: viewtopic.php?f=16&t=10811

no erocla
Posts: 134
Joined: 31 May 2013
Has thanked: 60 times
Been thanked: 7 times

Re: SetStopLoss Confilct with two systems applied to one cha

Postby no erocla » 07 Jul 2013

Thank you for answer,

i would like to solve this problem without rewriting my trading system portfolio, there s some other way to do it ? Or the only 1 way is to write all in 1 code ?

Thank you again for any answer.

No Erocla

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

Re: SetStopLoss Confilct with two systems applied to one cha

Postby TJ » 07 Jul 2013

Thank you for answer,
i would like to solve this problem without rewriting my trading system portfolio, there s some other way to do it ? Or the only 1 way is to write all in 1 code ?
Thank you again for any answer.
No Erocla
Sorry... can't offer any specifics without studying the code; there are too many possibilities.

But I can repeat... use the KISS principle when it comes to dealing with money and complex systems. Because whatever you are doing right now, it is only the beginning, it will only get MORE complex with time. You will tweak your systems a thousand times between now and Christmas. If you do not have a good grip on what you are doing, I would stop and read my suggestion #2 above.

no erocla
Posts: 134
Joined: 31 May 2013
Has thanked: 60 times
Been thanked: 7 times

Re: SetStopLoss Confilct with two systems applied to one cha

Postby no erocla » 07 Jul 2013

Maybe i explains badly, my question can involve any pair of systems.

SetStopLoss works alwais if marketposition <> 0, so if you have two strategy active to one chart, stop loss (or profit target) will generate conflicts.

There's some easy way to solve this problem ?

For example i thought about put stop loss into long/short condition:

if (average(c,5)>average(c,10) then begin
buy 1 contract next bar on open;
setstoploss(100);
end;

But i found some bug doing it, stoploss does not works correctly.

Thank you again for your time.

Cordially

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

Re: SetStopLoss Confilct with two systems applied to one cha

Postby TJ » 07 Jul 2013

Maybe i explains badly, my question can involve any pair of systems.
SetStopLoss works alwais if marketposition <> 0, so if you have two strategy active to one chart, stop loss (or profit target) will generate conflicts.
There's some easy way to solve this problem ?
For example i thought about put stop loss into long/short condition:
if (average(c,5)>average(c,10) then begin
buy 1 contract next bar on open;
setstoploss(100);
end;
But i found some bug doing it, stoploss does not works correctly.
Thank you again for your time.
Cordially
a bit related and unrelated... (but important read)

Please see post #5
setstoploss
viewtopic.php?f=16&t=10811

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

Re: SetStopLoss Confilct with two systems applied to one cha

Postby TJ » 07 Jul 2013

ps.
[FAQ] How to Post Codes (that people can read)
viewtopic.php?f=16&t=11713

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: SetStopLoss Confilct with two systems applied to one cha

Postby Henry MultiСharts » 11 Jul 2013

if (average(c,5)>average(c,10) then begin
buy 1 contract next bar on open;
setstoploss(100);
end;

But i found some bug doing it, stoploss does not works correctly.
That is not a bug, that is expected behavior.
If SetStopLoss is not under condition - it is automatically sent intra bar on the next tick after the code knows there is an open position.
If it is under condition-the order is generated only when the condition is met (either intrabar or on bar close). The orders are valid at the broker while they are generated by your strategy.
SetStopLoss works alwais if marketposition <> 0, so if you have two strategy active to one chart, stop loss (or profit target) will generate conflicts.
Multiple signals applied to one chart form a single strategy. If you want your signals to manage separate positions-use them on separate charts.
If you do not want your stop loss interfere with your other trading signal-you need to put it under condition that will generate the order only when you need it.

User avatar
t-rader
Posts: 139
Joined: 02 Feb 2011
Location: Australia
Has thanked: 11 times
Been thanked: 27 times

Re: SetStopLoss Confilct with two systems applied to one cha

Postby t-rader » 12 Jul 2013

That is not a bug, that is expected behavior.
If SetStopLoss is not under condition - it is automatically sent intra bar on the next tick after the code knows there is an open position.
If it is under condition-the order is generated only when the condition is met (either intrabar or on bar close). The orders are valid at the broker while they are generated by your strategy.

Multiple signals applied to one chart form a single strategy. If you want your signals to manage separate positions-use them on separate charts.
If you do not want your stop loss interfere with your other trading signal-you need to put it under condition that will generate the order only when you need it.
Just to confirm, Henry you are saying that you can actually use SetStopLoss within a condition? As I was under the belief you couldn't as this goes against TJ's post
Please see post #5
setstoploss
viewtopic.php?f=16&t=10811
http://www.multicharts.com/discussion/v ... 811#p53386

"The following keywords are Global Exits; they should not be placed inside a condition:
SetBreakEven
SetDollarTrailing
SetPercentTrailing
SetProfitTarget
SetStopLoss"

TJ's post is from almost 12 months ago so maybe things have changed since...

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

Re: SetStopLoss Confilct with two systems applied to one cha

Postby TJ » 12 Jul 2013

That is not a bug, that is expected behavior.
If SetStopLoss is not under condition - it is automatically sent intra bar on the next tick after the code knows there is an open position.
If it is under condition-the order is generated only when the condition is met (either intrabar or on bar close). The orders are valid at the broker while they are generated by your strategy.

Multiple signals applied to one chart form a single strategy. If you want your signals to manage separate positions-use them on separate charts.
If you do not want your stop loss interfere with your other trading signal-you need to put it under condition that will generate the order only when you need it.
Just to confirm, Henry you are saying that you can actually use SetStopLoss within a condition? As I was under the belief you couldn't as this goes against TJ's post
Please see post #5
setstoploss
viewtopic.php?f=16&t=10811
http://www.multicharts.com/discussion/v ... 811#p53386

"The following keywords are Global Exits; they should not be placed inside a condition:
SetBreakEven
SetDollarTrailing
SetPercentTrailing
SetProfitTarget
SetStopLoss"

TJ's post is from almost 12 months ago so maybe things have changed since...
There is no conflict.
Please note that I did not say you "couldn't",
I said you shouldn't.

Please read attached code for context.

User avatar
t-rader
Posts: 139
Joined: 02 Feb 2011
Location: Australia
Has thanked: 11 times
Been thanked: 27 times

Re: SetStopLoss Confilct with two systems applied to one cha

Postby t-rader » 14 Jul 2013

There is no conflict.
Please note that I did not say you "couldn't",
I said you shouldn't.

Please read attached code for context.
TJ thanks for the clarification (and sorry for misreading you original post), I appreciate your response. I briefly read your previous post before you edited, are you able to repost what you wrote originally wrote or maybe pm me it? as this is directly related to the situation I'm in at the moment.

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

Re: SetStopLoss Confilct with two systems applied to one cha

Postby TJ » 14 Jul 2013

There is no conflict.
Please note that I did not say you "couldn't",
I said you shouldn't.

Please read attached code for context.
TJ thanks for the clarification (and sorry for misreading you original post), I appreciate your response. I briefly read your previous post before you edited, are you able to repost what you wrote originally wrote or maybe pm me it? as this is directly related to the situation I'm in at the moment.
Sorry I deleted the post; if I do not get any response (either a post or clicked "Thanks"), it means my writing was incomprehensible... and I would try to simplify it.

Short advice -- do not put the Global Exits in a condition.

no erocla
Posts: 134
Joined: 31 May 2013
Has thanked: 60 times
Been thanked: 7 times

Re: SetStopLoss Confilct with two systems applied to one cha  [SOLVED]

Postby no erocla » 14 Jul 2013

Thanks all for answers,

anyway i solved it doing a unique code like tj said:

Code: Select all

if ( system1 ) then begin
input1;
input2;
stop = 100;
profit = 100;
end;

if ( system2 ) then begin
input1;
input2;
stop = 50;
profit = 50;
end;

setstoploss(stop);
setprofittarget(profit);


Return to “MultiCharts”