How to add a trailing stop using GeneratePercentTrailing()  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
EdL
Posts: 39
Joined: 18 Feb 2013
Has thanked: 22 times
Been thanked: 11 times

How to add a trailing stop using GeneratePercentTrailing()

Postby EdL » 13 Mar 2013

Hi,

I'm having trouble using the GeneratePercentTrailing(double profit, double percent) method to create a trailing stop.

I'm using the GenerateStopLoss(lossAmount) method to add an initial stop and this works fine.
When my close price goes beyond a certain level though, I'd like to add a trailing stop.

I've checked the sample Percent_Trailing strategy, but its still not clear.

The "percent" parameter is supplied as a whole number e.g. 5 for 5 % rather than 0.05.
But how should I add the "profit" parameter?

Do I use the price that I want the minimum profit to be?

Code: Select all

if (CrossesUnder(PriceSeries1, PriceSeries2))
{
_profitPrice = Bars.Close[0];
_profitPriceReached = true;
}

...

if(_profitPriceReached)
{
// 5 % Trailing stop after the profit price is hit
GeneratePercentTrailing(_profitPrice, 0.05);
}
Or should I calculate an actual profit amount in currency?

Code: Select all

if(_profitPriceReached)
{
_profitAmount = (_profitPrice - this.EntryPrice()) * Bars.Info.BigPointValue;
GeneratePercentTrailing(_profitAmount, 0.05);
}
Neither approach seems to work. Both just exit via a "Trailing Stop" (it says that on the chart) but it doesn't seem to trail, it just exits on the bar that the profit amount I provided as a parameter. So at present it is behaving the same as exiting via a market order at the target profit price.

The way I would expect it to work - as per trailing stops in general - is that either:

a) you provide a floor price and a percentage. Then when the price moves below your floor price it will close out the trade, or if the price moves in your favour, the stop will trail (by the given percentage) behind it.

b) you provide a price and a percentage. The price may drop below your provided price by the percentage amount, but will close out beyond that. Again, if the price moves in your favour, the stop will trail (by the given percentage) behind it.

Any help to understand how this should work in MC.NET is much appreciated. Again, some proper documentation on this would help!

Thanks,

Ed

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

Re: How to add a trailing stop using GeneratePercentTrailing  [SOLVED]

Postby Henry MultiСharts » 14 Mar 2013

The "percent" parameter is supplied as a whole number e.g. 5 for 5 % rather than 0.05.
But how should I add the "profit" parameter?

Ed
Hello Ed,

Profit - a numerical expression, specifying the currency value of the profit that must be reached first.
Percentage - a numerical expression, specifying the maximum loss of profit in percent (e.g. 50 for 50 % rather than 0.5).

For example, if the specified profit is $100 and the specified percentage is 50, and the profit has reached the maximum of $120, the position will be closed once the profit falls back to $60.

Generate an exit order for the entire position if 50 percent of maximum position profit is lost after the profit has reached $25:

Code: Select all

CurSpecOrdersMode = ESpecOrdersMode.PerPosition;
GeneratePercentTrailing(25,50)
Generate an exit order for the entry if 25 percent of maximum per share profit is lost after the profit has reached $5:

Code: Select all

CurSpecOrdersMode = ESpecOrdersMode.PerContract;
GeneratePercentTrailing(5,25);


Return to “MultiCharts .NET”