# Live Trailing Stop

Questions about MultiCharts and user contributed studies.
duration
Posts: 175
Joined: 20 Dec 2005

### Live Trailing Stop

Hello,

I am using a trailing stop of 5 points, with a trailing percentage of 10.

It looks like it works on backtesting, but not live.

The screenshot is a trade from the backtest: it enters long 1 contract at 1.5121, then exit at 1.5131.

But the same trade live is totally different: it still enters long at 1.5121, but then generates two trailing stop orders at 1.5124, exit with one, but go short with the other!

1. why did the trailing stop not exit at 1.5131 like in the backtest version?

2. why did it generate two orders?

They are programmed as follow:

Code: Select all

inputs: profitgt(50),pctrl(10), stopls(300),stoptype(1);

if stoptype = 1 then
begin
setstopposition;
setpercenttrailing(profitgt,pctrl);
setstoploss(stopls);
end;
if stoptype = 2 then
begin setstopcontract;
setpercenttrailing(profitgt,pctrl);
setstoploss(stopls);
end;
Attachments
trailing stop.png (8.45 KiB) Viewed 609 times

ct3232
Posts: 16
Joined: 25 Nov 2010
Has thanked: 1 time

### Re: Live Trailing Stop

I am having the same problem. I'm using "setpercenttrailing" and "setstoploss" and when applying the strategy to the MC charts, all entries and exits are calculated and shown correctly.

"inputs: Num(1),AvgLen(5),Threshold(250),PerCentTrail(10),StopAmt(700);

vars: MP(0);

Condition1 = ......................;
Condition2 = .......................;

If Condition1 and MP < 1 Then
Buy ("LE") Num contracts next bar at market;
If Condition2 and MP = 1 Then
Sell ("LX") Num contracts next bar at market;

setstopposition;
if MP <> 0 then
setpercenttrailing(Threshold,PerCentTrail);
setstoploss(StopAmt);"

However, in auto-trading with IB, I find the entries are occuring correctly, however the trailing stop does not even seem to be sent to IB. Funnily enough, the "setstoploss" order is sent.

The setstoploss order is obviously entered at the time the buy or sell signal is activated, whereas the setpercenttrailing order would only be entered when the trade has a certain accumulated profit.

Is there a setting I need to fix on the strategy properties, to allow for this subsequent trail order to be sent to IB. What am I missing? Any help would be much appreciated.

bomberone1
Posts: 189
Joined: 02 Nov 2010
Has thanked: 14 times
Been thanked: 12 times

### Re: Live Trailing Stop

I use two data set to avoid this.
data1 where order are sent at 1 minute
data2 where i do calculation at 60 minite.
Hope that this could help.

ct3232
Posts: 16
Joined: 25 Nov 2010
Has thanked: 1 time

### Re: Live Trailing Stop

Thanks Bomber - I worked around it by inserting specific sell and buytocover orders in my code - i cannot use setpercenttrailing.

TJ
Posts: 6873
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 984 times
Been thanked: 1976 times

### Re: Live Trailing Stop

note:

EasyLanguage Essentials Programmers Guide
Built-in Stops.......... pg. 90

Built-in Stops
EasyLanguage includes built-in exit commands that may be included directly in your strategies. These special commands will be active even on the bar of entry; that is, they are evaluated on each tick (regardless of any setting for Intrabar Order Generation on the Calculation tab of the Format Strategy dialog). These stops are not written in EasyLanguage, but are part of the strategy engine.

The built-in stop commands are:

SetBreakEven - sets an exit stop at the entry price, after a minimum profit is achieved.
SetDollarTrailing - sets an exit stop a fixed number of dollars away from the peak profit.
SetPercentTrailing - sets an exit stop a fixed percent of the peak profit away from the peak profit, after a minimum profit is achieved.
SetProfitTarget - sets an exit order at a fixed dollar profit target.
SetStopLoss - sets a stop loss order at a fixed dollar risk from entry.

ct3232
Posts: 16
Joined: 25 Nov 2010
Has thanked: 1 time

### Re: Live Trailing Stop

TJ

Thanks - but as far as I can see, I've coded the trailing stop correctly. As you can see above, I have a relatively simple strategy, that does display 100% correctly on the MC chart.

However, IB seems to be the problem. They do get the initial entry orders processed quickly and the setstoploss order is entered. But the setpercenttrail stop is never sent to IB, or if it is, it is never entered as an order on the IB interface.

Its really becoming annoying; I am autotrading on the 24hr currency futures and I need to be sure that the trailing stop is working.

Another odd thing is that although my simple strategy calls for one contract to be entered, IB always enters two. Has anyone else had this problem.