Profile Picture

Trailing stops based on ATR

Posted By Yuri55 2 Years Ago
Message
Posted Thursday May 14 2015
Hi,
I am new to RE and trying to implement the following trailing stop for any open position:
- Long position closed when price moved 3 ATR units down from highest closing price since position opened
- Short position closed when price moved 3 ATR units up from lowest closing price since position opened

I am using the below code (.NET) when opening a long position but it doesn't seem to work for setting this type of trailing stop. oATR is an AverageTrueRange object based on 100 days lookback. Could someone help me figure out how to implement the above rule? Tx!

                        oPosSet= New PositionSettings()
                        With oPosSet
                        .PositionType = PositionType.Long
                        .OrderType = OrderType.MarketOnOpen
                        .Size = lNumberofContracts
                        .TrailingStopType= TargetPriceType.AbsolutePrice
                        .TrailingStop = -3 * oATR.Current
                        .ProfitTargetType=TargetPriceType.None
                        .StopLossType=TargetPriceType.None
                        .BarCountExit=100000
                        End With
                       
                        OpenPosition(oPosSet)


Posted Thursday May 14 2015
The trailing stop value should be a positive number.  So try changing "-3" to "3" and let us know if that helps.

Thanks,
Daniel
Posted Thursday May 14 2015
Yes! Thanks very much.
I also had to change the TrailingStopType  to "TargetPriceType.RelativePrice" as I noticed afterwards that AbsolutePrice is not accepted for trailing stops in RE. I am presuming that this RelativePrice setting considers the trailing stop in price terms and not % terms (as the word "relative" may imply)?
Posted Thursday May 14 2015
The TargetPriceType enumeration can apply to profit targets, stop losses, and trailing stops.  RelativePrice and RelativeRatio are the only ones supported for trailing stops by the paper broker.  AbsolutePrice is valid for normal profit targets and stop losses, but the value you specify there is a fixed price which is not related to the fill price or current price of the symbol.  Since a trailing stop is inherently relative to the price this didn't seem to make sense for it.

Thanks,
Daniel


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems