Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

ATR Trailing Stop Topic Rating:
Previous Topic · Next Topic Watch this topic · Print this topic ·
ccsjeba
Posted : Wednesday, March 13, 2013 5:25:30 PM
Registered User
Joined: 5/7/2011
Posts: 13

Hello,

I am using the below in ThinkorSwim to plot the ATR Trailing Stop. Is there anyway I can convert this to StockFinder?

 

___________________________________
input trailType = {default modified, unmodified};
input ATRPeriod = 5;
input ATRFactor = 3.5;
input firstTrade = {default long, short};
 
assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);
 
def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
    then high - close[1]
    else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
    then close[1] - low
    else (close[1] - low) - 0.5 * (low[1] - high);
def ATRMod = ExpAverage(Max(HiLo, Max(HRef, LRef)), 2 * ATRPeriod - 1);
 
def loss;
switch (trailType) {
case modified:
    loss = ATRFactor * ATRMod;
case unmodified:
    loss = ATRFactor * AvgTrueRange(high, close, low, ATRPeriod);
}
 
rec state = {default init, long, short};
rec trail;
switch (state[1]) {
case init:
    if (!IsNaN(loss)) {
        switch (firstTrade) {
        case long:
            state = state.long;
            trail =  close - loss;
        case short:
            state = state.short;
            trail = close + loss;
        }
    } else {
        state = state.init;
        trail = Double.NaN;
    }
case long:
    if (close > trail[1]) {
        state = state.long;
        trail = Max(trail[1], close - loss);
    }
    else {
        state = state.short;
        trail = close + loss;
    }
case short:
    if (close < trail[1]) {
        state = state.short;
        trail = Min(trail[1], close + loss);
    }
    else {
        state = state.long;
        trail =  close - loss;
    }
}
 
def BuySignal = Crosses(state == state.long, 0, CrossingDirection.Above);
def SellSignal = Crosses(state == state.short, 0, CrossingDirection.Above);
 
plot TrailingStop = trail;
 
TrailingStop.SetPaintingStrategy(PaintingStrategy.POINTS);
TrailingStop.DefineColor("Buy", GetColor(0));
TrailingStop.DefineColor("Sell", GetColor(1));
TrailingStop.AssignValueColor(if state == state.long
    then TrailingStop.color("Sell")
    else TrailingStop.color("Buy"));
 
____________________
 
Thanks,
Charles
Bruce_L
Posted : Thursday, March 14, 2013 8:46:23 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

- Select Share | Browse other users shared items.
- Select the Charts tab (it should be selected by default).
- Type June Traders Tips in the search bar.
- Select Search.
- Select Craig_S' June Traders Tips from 4/10/2009 12:28:13 PM.
- Select Open.

You can type something less than the complete phrase June Traders Tips in the search, but if you do so, please make sure you select the June Traders Tips created by Craig_S.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
ccsjeba
Posted : Friday, March 15, 2013 1:30:37 AM
Registered User
Joined: 5/7/2011
Posts: 13

awesome! thanks Bruce!!

magu00
Posted : Sunday, May 29, 2016 4:46:33 PM
Registered User
Joined: 5/28/2016
Posts: 2

Hi ,is this te procedure to use it in TC2000?

I am using ATR Trailing Stop in ThinkorSwim and I want to use in TC2000 now. I am new, kinf of lost here.

Thanks for youe help

Marina

Bruce_L
Posted : Tuesday, May 31, 2016 10:51:50 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

The Volatility Stop indicator in TC2000 is based on Average True Range.

How to add an indicator to a chart template



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.