Trailing stop signal based on indicator (not price)
Author: kbellare
Creation Date: 5/8/2013 10:09 PM
profile picture

kbellare

#1
How do i code a Sell signal based on a Trail on a moving average indicator?
- The logic is - if the moving avg drops by 10% off its nearest High, issue a Sell signal?
- A variation would be to make the X% a function of the ATR of the moving avg indicator.

Are there indicators/functions that can help with trailing the High?

I'm using an indicator vs price to smoothen the price trend and avoid whipsaws

thanks
Kiran
profile picture

Eugene

#2
Take ExitAtTrailingStop and SellAtTrailingStop in the QuickRef as an example. They illustrate it with a similar concept: exiting on a Chandelier exit (X ATRs from a nearby highest high). Pass your moving average to the Highest.Series instead of the Bars.High by default.
profile picture

kbellare

#3
The challenge is that even though the exit level represents the exit level of the Moving Average (not the price level), the function ExitAtTrailingStop function will compare the Level to the nearest highest Price and exit based on comparing current Price (which is noisy with intra-day swings) not the Current moving average (see sample code given in Quick Ref Guide).

How do i make the ExitAtTrailingStop code compare the Level to the nearest Highest Moving Average peak and to the current Moving Average to generate a close signal?
profile picture

Eugene

#4
There appears to be a misconception. The function ExitAtTrailingStop function will compare the level with whatever you instruct it to compare from a preceding "if" condition, when programming your rules in code.

CODE:
Please log in to see this code.
profile picture

kbellare

#5
In the code above, the hh (Highest point) is calculated with a fixed lookback of 5 bars.
How can i write code so it returns the highest point since the position was entered? The trailing stop should be using this highest point.
Pl advise

thanks
Kiran
profile picture

Eugene

#6
CODE:
Please log in to see this code.


You'll find description of EntryBar in the QuickRef.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).