Chandelier Exit for TOS

M

Miket

Member
Does anyone have this for ThinkorSwim

 
Last edited:
J

john3

Active member
2019 Donor
Do you mean this one?

## START STUDY
## Chandelier_Stops
## linus, 2014-07-18, v0.2

#hint: thinkScript adaptation of Chandelier stops.

#hint n: lookback length for highest highs, lowest lows.
input n = 15;

#hint atrLength: Period length of avg. true range.
input atrLength = 5;

#hint atrMult: Multiplier of avg. true range.
input atrMult = 3.0;

#hint atrType: Moving average type of ATR.
input atrType = AverageType.SIMPLE;

#hint shift: Offsets the data this many bars.
input shift = 1;

#hint hideOppositeStop: Set to No to see the inactive stop.
input hideOppositeStop = Yes;

#hint label: Toggles P/L label.
input label = Yes;

#hint bubbles: Toggles P/L bubbles.
input bubbles = Yes;

def atr = MovingAverage(atrType, TrueRange(high, close, low)) * atrMult;

def smax = Lowest(low, n)[shift] + atr[shift];
def smin = Highest(high, n)[shift] - atr[shift];

def dir = compoundValue(1, if close > smax[1] then 1 else if close < smin[1] then -1 else dir[1], 0);

def rUB = compoundValue(1, if dir > 0 then if smax > rUB[1] then smax else rUB[1] else if dir < 0 then if smax < rUB[1] then smax else rUB[1] else rUB[1], high);

def rLB = compoundValue(1, if dir < 0 then if smin < rLB[1] then smin else rLB[1] else if dir > 0 then if smin > rLB[1] then smin else rLB[1] else rLB[1], low);

plot UB = if !hideOppositeStop or dir < 0 then rUB else Double.NaN;
plot LB = if !hideOppositeStop or dir > 0 then rLB else Double.NaN;

UB.SetDefaultColor(Color.MAGENTA);
LB.SetDefaultColor(Color.CYAN);

UB.SetLineWeight(3);
LB.SetLineWeight(3);

def orderDir = dir;

def isOrder = orderDir crosses 0;

def orderCount = compoundValue(1, if isNaN(isOrder) then 0 else if isOrder then orderCount[1] + 1 else orderCount[1], 0);

def noBar = isNaN(open[-1]);

def orderPrice = if isOrder then if noBar then close else open[-1] else orderPrice[1];
def profitLoss = if !isOrder or orderCount == 1 then 0 else if orderDir > 0 then orderPrice[1] - orderPrice else if orderDir < 0 then orderPrice - orderPrice[1] else 0;
def profitLossSum = compoundValue(1, if isNaN(isOrder) then 0 else if isOrder then profitLossSum[1] + profitLoss else profitLossSum[1], 0);

AddLabel(label, orderCount + " orders | P/L " + AsDollars((profitLossSum / tickSize()) * tickValue()), if profitLossSum > 0 then Color.GREEN else if profitLossSum < 0 then Color.RED else Color.GRAY);

AddChartBubble(bubbles and isOrder and orderDir > 0, low, profitLoss, if noBar then Color.LIGHT_GRAY else Color.GREEN, 0);
AddChartBubble(bubbles and isOrder and orderDir < 0, high, profitLoss, if noBar then Color.GRAY else Color.RED, 1);

## END STUDY
 
T

Trading51

Active member
2019 Donor
Hello inside the preference it has an input that says "Shift" what does this do?
 
horserider

horserider

Well-known member
VIP
@Trading51
#hint shift: Offsets the data this many bars.
input shift = 1;
 
Charlie.mp3

Charlie.mp3

New member
What does the order count label mean? Where do these orders come from?
 
wtf_dude

wtf_dude

Active member
Is there a tutorial on this indicator?
It's a pretty simple one. Basically, buy when the line turns blue. Sell or go short when the line turns magenta. The change over is based on the average true range and is basically the exact same as ATRtrailingstop already in TOS.
 
Top