Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
ATR Trailing Stop: Convert Thinkscript to Easylanguage
Hi, I'm new to easylanguage and having a really rough time changing over from ToS to Multicharts. I dont use any complex strategies and have never had to program in thinkscript so I'm generally new to programming as well.
I was hoping someone could please please help me convert this Thinkscript code for an ATR trailing stop to Easylanguage for multicharts.
I am specifically looking for an Indicator that will plot the ATR stops on my chart regardless of whether or not I have an actual market position (For instance, ToS assumes I have a hypothetical long when starting the plot and this is fine; i.e. no need for an actual position). I am not looking for a signal as these are already programmed into multicharts but for some reason dont plot.
Alternatively, since the below code has customization for modified ATR stops aswell which I'm not interested in, if anyone has their own version of a standard ATR Trailing stop indicator I would really appreciate that as well!
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);
}
def state = {default init, long, short};
def 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;
}
}
I am trying to find the same thing. I have looked everywhere for ATR trailing stop indicator for tradestation, and can only find a strategy, not an indicator.
It's NOT my code so my "Guess" would be that TS stands for "Trailing Stop"...
Here is a simple conversion from the stop indicator to a basic system...(untested and not my code).
Inputs: Price(Close),atrPeriod(14),atrMult(1.75);
Vars:
atr(0), ts(0), shstp(0), lgstp(0), trend(0), TriggerPrice(0), dir(0);
atr = AvgTrueRange(AtrPeriod);
lgstp = Price - atr * atrMult;
shstp = Price + atr * atrMult;
TriggerPrice = close;
if TriggerPrice >= ts[1] then
trend = 1
else if TriggerPrice < ts[1] then
trend = -1;
if trend > 0 then
if trend[1] < 0 then ts=lgstp[0]
else if lgstp >= ts[1] then ts=lgstp[0]
else ts=ts[1];
if trend < 0 then
if trend[1] > 0 then ts=shstp[0]
else if shstp <= ts[1] then ts=shstp[0]
else ts=ts[1];
if trend[1] < 0 and trend >= 0 then buy next bar at market;
if trend[1] > 0 and trend < 0 then sellshort next bar at market;