How work stoploss and breakeven?

Questions about MultiCharts and user contributed studies.
TomSchroeder
Posts: 2
Joined: 31 Aug 2015

How work stoploss and breakeven?

Postby TomSchroeder » 31 Aug 2015

Hello,

I want to use the stoploss function in trading strategies.
In MC Wiki I read that the stoploss function is evaluated intrabar.
In reality (paper trading with automated strategy) the stoploss is not executed intrabar but at the open of the next bar. Breakeven works same.
What is the reason for this?
What can I do that stoploss is working intrabar?

Thank you in advance
Best Regards
Tom

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

Re: How work stoploss and breakeven?

Postby tony » 31 Aug 2015

Are you sure you are using it correctly? You should have setstoploss and setbreakeven in your signal. Those are designed to send a market order (buy or sell) when the pre-set value is met, regardless of where in "the bar" you are at that time. If you are not using those by trying something else then your code is likely wrong.

sptrader
Posts: 742
Joined: 09 Apr 2010
Location: Texas
Has thanked: 483 times
Been thanked: 274 times
Contact:

Re: How work stoploss and breakeven?

Postby sptrader » 31 Aug 2015

The stoploss etc, must be outside of any strategy conditions...

TomSchroeder
Posts: 2
Joined: 31 Aug 2015

Re: How work stoploss and breakeven?

Postby TomSchroeder » 01 Sep 2015

Are you sure you are using it correctly? You should have setstoploss and setbreakeven in your signal. Those are designed to send a market order (buy or sell) when the pre-set value is met, regardless of where in "the bar" you are at that time. If you are not using those by trying something else then your code is likely wrong.
Hi Tony,

this is a part of the code; I think it is correct.

Code: Select all

//Ausstieg mit Trailingstop

Input: AmountL (50),
AmountS (50),
PositionBasis( true );

If PositionBasis then
SetStopPosition
Else
SetStopShare;

SetBreakEven (12.5);
SetStopLoss (100);

If MarketPosition = 1 then
SetDollarTrailing (AmountL);

If MarketPosition = -1 then
SetDollarTrailing (AmountS);
And now please look at the screenshot 1 of my e-mini chart. On the first 5 candles the trailing stop works correct. Beginning in the middle of the image (red candle with long tail) the stoploss works not correct. The loss between the red and the green candle is 500 $ and the loss between the next two green candles is 1,000 $. But the stoploss is set to 100 $.
And on screenshot 2 the stoploss seems to work correct.
What is the reason?

Tom
Attachments
TomSchroeder-1.JPG
(52.91 KiB) Downloaded 673 times
TomSchroeder-2.JPG
(50.77 KiB) Downloaded 663 times

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

Re: How work stoploss and breakeven?

Postby TJ » 01 Sep 2015

::
this is a part of the code; I think it is correct.
(My post is only a coding observation, it is not a direct answer to the problem you are encountering.)

You should modify the following code:

Code: Select all

//Ausstieg mit Trailingstop
If MarketPosition = 1 then
SetDollarTrailing (AmountL);

If MarketPosition = -1 then
SetDollarTrailing (AmountS);
to

Code: Select all

//Ausstieg mit Trailingstop

var: Trailing.Amount(0);

If MarketPosition = 1 then
Trailing.Amount = AmountL
else
If MarketPosition = -1 then
Trailing.Amount = AmountS;

SetDollarTrailing ( Trailing.Amount );

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

Re: How work stoploss and breakeven?

Postby tony » 01 Sep 2015

You use reserved words I don't normally use, so without spending much time researching here are a few thoughts for you.

1: Looks like per MC, setstopposition is not necessarily needed, as the default is to go flat the entire position. So perhaps remove that.

2: You have your exit logic before you specify market position which may or may not be a problem but it seems a little disorganized way to read a script.

3: Not sure what backtest resolution you have (i.e. every tick) which can cause some of these variations you notice.

4: I would write your signal something more like this. Please note, I didn't test to see if it works.

Code: Select all

Input:

AmountL(50),
AmountS(50),

If marketposition=1

then

setdollartrailing(AmountL);

If marketposition=-1

then

setdollartrailing(AmountS);

setbreakeven(12.5);
setstoploss(100);



Return to “MultiCharts”