| 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 | 
	
	|  
  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
 | 
	
	| Registered User Joined: 5/7/2011
 Posts: 13
 
 | 
	awesome! thanks Bruce!! | 
	
	| 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 | 
	
	|  
  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
 |