SetStopLoss

Questions about MultiCharts and user contributed studies.
HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

SetStopLoss

Postby HummerH1 » 05 Oct 2011

Hello,

What is the difference between using SetStopLoss
or adding code like:

Code: Select all

condition1 =  CurrentPrice <= EntryPrice  - StopLoss;

if MarketPosition > 0 and condition1       
       then begin
      sell this  bar  ;
end;

and what's the better thing to use?

User avatar
TJ
Posts: 6551
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 966 times
Been thanked: 1892 times

Re: SetStopLoss

Postby TJ » 05 Oct 2011

HummerH1 wrote:Hello,

What is the difference between using SetStopLoss
or adding code like:

Code: Select all

condition1 =  CurrentPrice <= EntryPrice  - StopLoss;

if MarketPosition > 0 and condition1       
       then begin
      sell this  bar  ;
end;

and what's the better thing to use?


SetStopLoss is a Global Exit order.

see post #3 for more information
viewtopic.php?f=16&t=6929

User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 154 times
Been thanked: 215 times

Re: SetStopLoss

Postby furytrader » 06 Oct 2011

If you're not using intrabar order generation with that system, the system will wait until the end of the current price bar to enter that market order, which means that the market may have gotten far away from your stop level depending on how frequent your bar interval is.

So, let's imagine that you're using a chart with 15 minute bars. You get filled and immediately, the market turns around and goes against you by more than your stop level level. You'd have to wait until the current 15 minute bar ends before your order will be placed - by that time, the bottom may have fallen out of the market and you get filled many many points away from your stop level.

In terms of automated trading, the best way to do it is to place a stop order as soon as your order is filled.
These users thanked the author furytrader for the post (total 2):
TJHenry MultiСharts

HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

Re: SetStopLoss

Postby HummerH1 » 06 Oct 2011

And what if I have Intrabarordergeneration enabled?
What will be better to use then?

What about adding the signal SetStopLoss to the strategy?
What the difference between that or just adding SetStopLoss into my signal?

User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 154 times
Been thanked: 215 times

Re: SetStopLoss

Postby furytrader » 06 Oct 2011

If I was programming this, I would use the code that specifically sets the stop order (using a designated price level) vs. the SetStopLevel code, because then I have a greater insight into how the order is being calculated and placed.
These users thanked the author furytrader for the post:
JoshM

HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

Re: SetStopLoss

Postby HummerH1 » 08 Oct 2011

I did not really understand.
You meant using the SetStopLoss function into my code is better than
1. using the SetStoploss signal into my startegy
2. coding the stop in the code like I paste in my first msg
?

HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

Re: SetStopLoss

Postby HummerH1 » 09 Oct 2011

An other question about the SetStopLoos function.

When calling the function, does it applies to all positions in my strategies?

If i have 2 different signals into my chart, and each one has a different StopLoss.
Is that Ok?

User avatar
JoshM
Posts: 2080
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1483 times
Contact:

Re: SetStopLoss

Postby JoshM » 09 Oct 2011

furytrader wrote:If I was programming this, I would use the code that specifically sets the stop order (using a designated price level) vs. the SetStopLevel code, because then I have a greater insight into how the order is being calculated and placed.

HummerH1 wrote:I did not really understand.
You meant using the SetStopLoss function into my code is better than
1. using the SetStoploss signal into my startegy
2. coding the stop in the code like I paste in my first msg
?

As I read it, FuryTrader means that he uses the "submit stop orders"-code instead of using the build in SetStopLoss (which is also what I do, because of the same reasons FuryTrader mentions).

So, for example...

Setting stoplosses with SetStopLoss():

Code: Select all

Variables: maFast(0), maSlow(0);

maFast = XAverage(Close, 5);
maSlow = XAverage(Close, 15);

SetStopPosition;

if maFast crosses over maSlow then begin
   Buy("LE") 1 contract next bar at market;
end;

if maFast crosses under maSlow then begin
   SellShort("SE") 1 contract next bar at market;
end;

SetStopLoss(500);   // Exit the trade is total loss is 500 dollar or more.

or using the code to specify the exit level:

Code: Select all

Variables: maFast(0), maSlow(0), maxLoss(0);

maFast = XAverage(Close, 5);
maSlow = XAverage(Close, 15);

maxLoss = 500 / BigPointValue;

// Enter long
if maFast crosses over maSlow then begin
   Buy("LE") 1 contract next bar at market;
end;

// Submit stop orders for long position
if MarketPosition = 1 then begin
   Sell("StopXL") next bar at (EntryPrice(0) - maxLoss) stop;
end;

// Enter short
if maFast crosses under maSlow then begin
   SellShort("SE") 1 contract next bar at market;
end;

// Submit stop orders for short position
if MarketPosition = -1 then begin
   BuyToCover("StopXS") next bar at (EntryPrice(0) + maxLoss) stop;
end;


In this code example above, you can specify the stop loss price, which gives more flexibility.

(Btw, bonus points if you noticed that :): the first example uses the stop based on the position loss, while the second example uses the stop based on a contract/share basis. In these examples there's no actual difference, since both examples have a position size of 1.)

HummerH1 wrote:An other question about the SetStopLoos function.

When calling the function, does it applies to all positions in my strategies?

As far as I know, yes - but only the positions on that chart. Btw, the build in stop loss signals ("Stop Loss LX" and "Stop Loss SX") do exactly that (see the code of these signals to see how they work).

HummerH1 wrote:If i have 2 different signals into my chart, and each one has a different StopLoss.
Is that Ok?

I don't know how that might work out. :)

Regards,
Josh
These users thanked the author JoshM for the post (total 2):
HummerH1furytrader

HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

Re: SetStopLoss

Postby HummerH1 » 09 Oct 2011

Thanks Josh

I thought FuryTrader said that using the function was better that self code. So I changed my code to check it.
But if it has to be the same limit for all my signals it wont't be good enough for me.
I ll change it back.

escamillo
Posts: 197
Joined: 25 Mar 2011
Has thanked: 22 times
Been thanked: 55 times

Re: SetStopLoss

Postby escamillo » 10 Oct 2011

HummerH1 wrote:Thanks Josh

I thought FuryTrader said that using the function was better that self code. So I changed my code to check it.
But if it has to be the same limit for all my signals it wont't be good enough for me.
I ll change it back.


The difference is that SetStopLoss, etc. are managed by the MC internal trading engine; your own code is managed by the MC program making passes of your code. In general, if you can use SetStopLoss, SetBreakEven, etc., it is better to use them. But if you want to calculate something like rachet stops, then use the word STOP, which will execute an exit prior to end of bar when your stop conditions are met. Caveat: at some brokers, if the stop does not reside on their server, then it is possible that, particularly in a fast market if your computer lags, if the market has moved to below your stop price before your stop order is received at the exchange, then your stop order will be rejected by the exchange and you do not have a stop order after all. That would be about the only reason I can think of to use IntraBarOrderGeneration and a MARKET order as a stop (which I had to do briefly in past).
These users thanked the author escamillo for the post:
JoshM

HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

Re: SetStopLoss

Postby HummerH1 » 11 Oct 2011

Thanks escamillo.

You said:

if you can use SetStopLoss, SetBreakEven, etc., it is better to use them

If I can't - If I need different stoploss for different signal in my chart, is it a good reason?

then use the word STOP

You meant

Code: Select all

Buy/sell market at Stop
?

Can I use SetBreakEven with this to change my stop after a certain profit?

escamillo
Posts: 197
Joined: 25 Mar 2011
Has thanked: 22 times
Been thanked: 55 times

Re: SetStopLoss

Postby escamillo » 11 Oct 2011

Do whatever you need to do to make your stops work for you the way you want them to work. And in some months or years, you may find that there is another way to accomplish what you are doing.

The syntax for using the word STOP is:

Code: Select all

If MarketPosition = 1 then
begin
Sell ("LX Hard") CurrentContracts Contracts next bar YourDefinedStop STOP ;
end ;

where YourDefinedStop is a variable that you have declared and calculated.

You can use SetBreakEven as follows:

Code: Select all

Inputs:BE_Profit_Points(2) ;
Var:   ProfitFloorAmt(BE_Profit_Points * BigPointValue),
if MarketPosition <> 0 then SetBreakEven(ProfitFloorAmt);

You could create a variable for use in place of the above input BE_Profit_Points.

HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

Re: SetStopLoss

Postby HummerH1 » 11 Oct 2011

- Do whatever I need...
If i knew what I need to do, i wouldn't be here asking for explanation...
And Im asking exactly not to find out in some months or years that I should have done it another way.
It's easy to find syntaxes of different things in the tutorials. What's missing is some more explanation about everything.


- In this post it's said not to use setbreakeven into a condition
http://www.multicharts.com/discussion/viewtopic.php?f=16&t=6929&hilit=setbreakeven


- When using Market at STOP, the order is at the broker server.
The SetBreakEven is handled by MC.
That's why I asked if using them at the same time will not do mess in real trading.

User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 154 times
Been thanked: 215 times

Re: SetStopLoss

Postby furytrader » 11 Oct 2011

The reason I had recommended using the "STOP" keyword, as in:

SELL NEXT BAR AT ENTRYPRICE - 10 STOP;


is that it gives you greater flexibility when programming.

So, for example, if you want to change the stop from "EntryPrice - 10" to "Low - 10", it's really easy to do. When you use "SetStopLoss", you don't have that flexibility since it's always based off of your entry price.

Also, the fact that SetStopLoss is based on your position loss means that you could end up getting very different market outcomes depending on whether you're trading 10 contracts or 20 - you'd be exiting the market at very different price levels. I'd rather not have to think about that when I'm programming a model.

Also, I would not mix these two approaches in a model. Pick one and stick with it.

Are there any other questions?
These users thanked the author furytrader for the post:
JoshM

escamillo
Posts: 197
Joined: 25 Mar 2011
Has thanked: 22 times
Been thanked: 55 times

Re: SetStopLoss

Postby escamillo » 23 Jan 2012

escamillo wrote:The difference is that SetStopLoss, etc. are managed by the MC internal trading engine; your own code is managed by the MC program making passes of your code. In general, if you can use SetStopLoss, SetBreakEven, etc., it is better to use them. But if you want to calculate something like rachet stops, then use the word STOP, which will execute an exit prior to end of bar when your stop conditions are met. Caveat: at some brokers, if the stop does not reside on their server, then it is possible that, particularly in a fast market if your computer lags, if the market has moved to below your stop price before your stop order is received at the exchange, then your stop order will be rejected by the exchange and you do not have a stop order after all. That would be about the only reason I can think of to use IntraBarOrderGeneration and a MARKET order as a stop (which I had to do briefly in past).


Based on uncertainty surrounding how how SetStopLoss actually works in MultiCharts discussed in this thread:

viewtopic.php?f=1&t=9715

I WITHDRAW my comment regarding MultiCharts stops words SetStopLoss, etc. that: "...if you can use SetStopLoss, SetBreakEven, etc., it is better to use them."

SetStopLoss does not work on an Entry bar for me without code being set to [IntraBarOrderGeneration = True], which is a big handicap and renders using SetStopLoss the same as using the word "STOP".

User avatar
TJ
Posts: 6551
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 966 times
Been thanked: 1892 times

Re: SetStopLoss

Postby TJ » 23 Jan 2012

escamillo wrote:
escamillo wrote:The difference is that SetStopLoss, etc. are managed by the MC internal trading engine; your own code is managed by the MC program making passes of your code. In general, if you can use SetStopLoss, SetBreakEven, etc., it is better to use them. But if you want to calculate something like rachet stops, then use the word STOP, which will execute an exit prior to end of bar when your stop conditions are met. Caveat: at some brokers, if the stop does not reside on their server, then it is possible that, particularly in a fast market if your computer lags, if the market has moved to below your stop price before your stop order is received at the exchange, then your stop order will be rejected by the exchange and you do not have a stop order after all. That would be about the only reason I can think of to use IntraBarOrderGeneration and a MARKET order as a stop (which I had to do briefly in past).


Based on uncertainty surrounding how how SetStopLoss actually works in MultiCharts discussed in this thread:

viewtopic.php?f=1&t=9715

I WITHDRAW my comment regarding MultiCharts stops words SetStopLoss, etc. that: "...if you can use SetStopLoss, SetBreakEven, etc., it is better to use them."

SetStopLoss does not work on an Entry bar for me without code being set to [IntraBarOrderGeneration = True], which is a big handicap and renders using SetStopLoss the same as using the word "STOP".

Without seeing your code, the problem is still undetermined.

escamillo
Posts: 197
Joined: 25 Mar 2011
Has thanked: 22 times
Been thanked: 55 times

Re: SetStopLoss

Postby escamillo » 23 Jan 2012

Without seeing your code, the problem is still undetermined.

It is posted in the thread which I referenced:
viewtopic.php?f=1&t=9715
where I asked the original question. The code referenced is:

Code: Select all

SetStopContract ;
SetStopLoss(200) ;

This thread I am just backing off of my prior statement that it is preferable to use SetStopLoss, etc. - I ask MultiCharts to issue a clarification to my original question in the other thread.


Return to “MultiCharts”