How to add a trailing stop using GeneratePercentTrailing()
Posted: Mar 13 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?
Or should I calculate an actual profit amount in currency?
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
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);
}
Code: Select all
if(_profitPriceReached)
{
_profitAmount = (_profitPrice - this.EntryPrice()) * Bars.Info.BigPointValue;
GeneratePercentTrailing(_profitAmount, 0.05);
}
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