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
How work stoploss and breakeven?
Re: How work stoploss and breakeven?
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.
-
- Posts: 742
- Joined: 09 Apr 2010
- Location: Texas
- Has thanked: 483 times
- Been thanked: 274 times
- Contact:
Re: How work stoploss and breakeven?
The stoploss etc, must be outside of any strategy conditions...
-
- Posts: 2
- Joined: 31 Aug 2015
Re: How work stoploss and breakeven?
Hi Tony,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.
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 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
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: How work stoploss and breakeven?
(My post is only a coding observation, it is not a direct answer to the problem you are encountering.)::
this is a part of the code; I think it is correct.
You should modify the following code:
Code: Select all
//Ausstieg mit Trailingstop
If MarketPosition = 1 then
SetDollarTrailing (AmountL);
If MarketPosition = -1 then
SetDollarTrailing (AmountS);
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 );
Re: How work stoploss and breakeven?
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.
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);