ATR Trailing Stop: Convert Thinkscript to Easylanguage - MultiCharts | futures.io
futures.io futures trading


ATR Trailing Stop: Convert Thinkscript to Easylanguage
Started: by kamisyed Views / Replies:2,300 / 6
Last Reply: Attachments:0

Welcome to futures.io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike

Reply
 
Thread Tools Search this Thread
 

ATR Trailing Stop: Convert Thinkscript to Easylanguage

  #1 (permalink)
Trading Apprentice
Abu Dhabi + United Arab Emirates
 
Futures Experience: Intermediate
Platform: think or swim
Favorite Futures: Options
 
Posts: 2 since Oct 2013
Thanks: 0 given, 0 received

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!

Please help!


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);
}

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;
}
}

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")


Last edited by kamisyed; July 4th, 2014 at 10:12 AM.
Reply With Quote
 
  #2 (permalink)
Trading Apprentice
jupiter + florida/United States
 
Futures Experience: Master
Platform: tradestation
Favorite Futures: options
 
Posts: 1 since Aug 2014
Thanks: 1 given, 0 received

help with ATR stop

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.

Reply With Quote
 
  #3 (permalink)
Elite Member
Colorado
 
Futures Experience: Advanced
Platform: MultiCharts
Broker/Data: IB & Iqfeed
Favorite Futures: ES , CL
 
sptrader's Avatar
 
Posts: 520 since Apr 2010
Thanks: 1,045 given, 646 received


Here is a basic ATR stop indicator.. for multicharts (not tested in TS), not sure who the author is either...

 
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];

Plot1(ts,"Long Stop");
Plot2(ts,"Short Stop");
Plot3(ts,"ATR Stop",iff(trend = 1,GetPlotColor(1),GetPlotColor(2)));

Reply With Quote
The following 3 users say Thank You to sptrader for this post:
 
  #4 (permalink)
Elite Member
Sydney
 
Futures Experience: Intermediate
Platform: Multichart
Favorite Futures: Gold
 
Posts: 26 since Aug 2016
Thanks: 22 given, 4 received

Code for turning into system

How do I turn code below into system so it buys/sells when it changes direction?

And what does ts in the code mean?

Many thanxx

Loop















sptrader View Post
Here is a basic ATR stop indicator.. for multicharts (not tested in TS), not sure who the author is either...

 
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];

Plot1(ts,"Long Stop");
Plot2(ts,"Short Stop");
Plot3(ts,"ATR Stop",iff(trend = 1,GetPlotColor(1),GetPlotColor(2)));


Reply With Quote
 
  #5 (permalink)
Elite Member
Colorado
 
Futures Experience: Advanced
Platform: MultiCharts
Broker/Data: IB & Iqfeed
Favorite Futures: ES , CL
 
sptrader's Avatar
 
Posts: 520 since Apr 2010
Thanks: 1,045 given, 646 received

Futures Edge on FIO
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).

 
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;

Reply With Quote
The following user says Thank You to sptrader for this post:
 
  #6 (permalink)
Elite Member
Sydney
 
Futures Experience: Intermediate
Platform: Multichart
Favorite Futures: Gold
 
Posts: 26 since Aug 2016
Thanks: 22 given, 4 received

Code for turning into system

Thank you!!!

Do you know where I can find more code like this?

Reply With Quote
 
  #7 (permalink)
 Vendor: abctradinggroup.com 
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,186 since Apr 2013
Thanks: 198 given, 679 received

Loop,

you can find a lot via google for example. Multicharts also has a lot build in and a knowledge-base with code on their website as well as the forum.

Besides that the elite section here on futures.io offers tools for Multicharts for download, too.

Regards,

ABCTG


Loop View Post
Thank you!!!

Do you know where I can find more code like this?


Reply With Quote

Reply



futures.io > > > > ATR Trailing Stop: Convert Thinkscript to Easylanguage

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

2016 True Edge Awards: Voting is open until Jan 21!

Now
 

Anthony Drager: Pulling the trigger with confidence

Elite only
 

Leo Murphy: The Art and Science of Technical Analysis

Elite only
 

FuturesTrader71: Ask Me Anything

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Easy Language code into Thinkscript sboarder13 ThinkOrSwim 20 November 22nd, 2016 01:47 AM
[help] Still unable to convert this MQ4 indicator to Thinkscript Ardian1899 ThinkOrSwim Programming 0 July 3rd, 2014 06:10 AM
multicharts- ATR trailing stop expert adviser? Ryan Scobby MultiCharts 1 December 7th, 2012 12:31 PM
ATR Trailing Stop Parameter Optimization tbmuc Elite Automated Trading 2 November 29th, 2012 04:52 PM
Free stock charts with ATR Trailing stop peglegtrading Traders Hideout 1 December 1st, 2011 02:48 PM


All times are GMT -4. The time now is 05:42 PM.

no new posts
Page generated 2017-01-21 in 0.13 seconds with 19 queries on phoenix via your IP 54.159.187.17