EL help: ATR conversion - EasyLanguage Programming | futures io social day trading
futures io futures trading


EL help: ATR conversion
Updated: Views / Replies:255 / 7
Created: by mntman Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 100,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • 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.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

EL help: ATR conversion

  #1 (permalink)
Houston+TX/USA
 
Trading Experience: Intermediate
Platform: TradeStation, ThinkorSwim
Favorite Futures: ES, CL
 
mntman's Avatar
 
Posts: 4 since Jan 2019
Thanks: 1 given, 0 received

EL help: ATR conversion

could anyone help me convert this thinkorswim ATR study into easy-language please? ive gotten sorta close (see screenshot) but i think im getting hung up on defining the init/long/short "state" and "trail" portion.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).



Quoting 
input length = 14;
input trailType = {default modified, unmodified};
input ATRPeriod = 5;
input ATRFactor = 3.5;
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;

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 trueRange;
switch (trailType) {
case modified:
trueRange = Max(HiLo, Max(HRef, LRef));
case unmodified:
trueRange = TrueRange(high, close, low);
}

def loss = MovingAverage(averageType, TrueRange(high, close, low), length);

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

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


Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Miami, USA
 
Trading Experience: Advanced
Platform: MultiCharts
Favorite Futures: Forex
 
Posts: 11 since May 2017
Thanks: 1 given, 7 received

Mmm


Hi mtman... an EL guy here,

I don't want to come across as a naysayer, but I can see why this one would be a little tricky unless someone is intimately familiar with the source codes of ToS as well.

If you want someone to be able to help you, I'd recommend posting the source codes of all the functions involved as well. There are many things in this code that need to be expanded on in order to reproduce your ToS results more closely.

Another concern is - if you're looking for precisely the same results, that's going to be about 6-8 hours of debugging work for a professional, in my estimation. At least that's how long it would take me to dig in and debug stuff on a trade-by-trade basis.

a.) Although people here seem to be fairly generous with their time, I'm not sure whether it's reasonable to expect for a random person to just to do that on a thread like this,

b.) Do you really need this and is it really worth it? There are many ways you can come up with similar strategies in TS/MC without having to translate something like this over very precisely.

Just my 2 cents.

-Ben

Reply With Quote
 
  #4 (permalink)
Houston+TX/USA
 
Trading Experience: Intermediate
Platform: TradeStation, ThinkorSwim
Favorite Futures: ES, CL
 
mntman's Avatar
 
Posts: 4 since Jan 2019
Thanks: 1 given, 0 received

hey Ben... thanks for your reply and feedback. im going to reply in 2 parts


Quoting 
I'd recommend posting the source codes of all the functions involved as well

unfortunately thinkorswim doesn't have source codes for their functions. but in converting other codes i have learned that Max = MaxList and Min = MinList in EL. since EL also has its own functions for AverageTrueRange and TrueRange im not 100% sure if its the same as what is written in the TOS script.

below is my current EL script converted if anyone is curious. i have the "hangup section" part marked, as well as my "work around" section marked where i tried bypassing the switch altogether. i comment out one or the other sections to see how it plots as i con't working on it:

 
Code
{ source: thinkorswim }

Inputs:
	length(14),
	trailType.1.2(1),
	atrPeriod(5),
	atrFactor(3.5),
	firstTrade.1.2(1);

Variables:
	hilo(0),
	href(0),
	lref(0),
	trueRang2(0),
	atr(0),
	loss(0),
	state(0),
	trail(0),
	trailColor(0);
	

{ indicator }

hilo = MinList(H - L, 1.5 * Average(H - L, atrPeriod));

If L <= H[1] then
	href = H - close[1] else
	href = (H - close[1]) - 0.5 * (L - H[1]);

If H >= L[1] then
	lref = close[1] - L else
	lref = (close[1] - L) - 0.5 * (L[1] - H);
	

{ 1 = modified, 2 = unmodified }
switch(trailType.1.2) begin	
case 1:
	trueRang2 = MaxList(hilo, MaxList(href, lref));
case 2:
	trueRang2 = TrueRange;
end;

atr = AvgTrueRange(atrPeriod);
loss = atr;

{
//>>>>>>>>>> hang up begins <<<<<<<<<<<<<<<

{ 0 = init, 1 = long, -1 = short }
switch(state[1]) begin
case 0:
	switch(firstTrade.1.2) begin
		case 1:
			state = 1;
			trail = close - loss;
		case 2:
			state = -1;
			trail = close + loss;
	end;

case 1:
	If (Close > trail[1]) then begin
		state = 1;
		trail = MaxList(trail[1], close - loss);
	End
	Else begin
		state = -1;
		trail = close + loss;
	end;

case -1:
	If (Close < trail[1]) then begin
		state = -1;
		trail = MinList(trail[1], close + loss);
	End
	Else begin
		state = 1;
		trail = close - loss;
	end;
end;

//>>>>>>>>>> hang up ends <<<<<<<<<<<<<<<
}

//>>>>>>>>>> work around begins <<<<<<<<<<<<<<<

state = 1;
trail = close - loss;

{long}
If (Close > trail[1]) then begin
	state = 1;
	trail = MaxList(trail[1], close - loss);
End;

{short}
If (Close < trail[1]) then begin
	state = -1;
	trail = MinList(trail[1], close + loss);
End;

//>>>>>>>>>> work around ends <<<<<<<<<<<<<<<


{ plots }
If state = 1 then trailColor = green else if state = -1 then trailColor = red else trailColor = darkgray;

Plot1(trail, "Trail Stop", trailColor);

Reply With Quote
 
  #5 (permalink)
Houston+TX/USA
 
Trading Experience: Intermediate
Platform: TradeStation, ThinkorSwim
Favorite Futures: ES, CL
 
mntman's Avatar
 
Posts: 4 since Jan 2019
Thanks: 1 given, 0 received


Quoting 
Do you really need this and is it really worth it

to me yes i feel its worth my time because when i played with the TOS script a little more i found some interesting relations when i would have two aggregations match (both were state = long or both were state = short). even the single aggregation results i thought were interesting. so its worth it to myself to con't working on in hopes to eventually make an EL strategy out of it and backtest in tradestation to see what results i get as a simple trend following approach.

below are some screenshots in TOS of CL and ES with the bars colored when 2 aggregations matched or when using just a single aggregation which is what peaked my interest:

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Reply With Quote
 
  #6 (permalink)
Miami, USA
 
Trading Experience: Advanced
Platform: MultiCharts
Favorite Futures: Forex
 
Posts: 11 since May 2017
Thanks: 1 given, 7 received

Hi mntman,

I understand what you're saying and it looks interesting. But I'd still recommend hiring an outsourcer for this or something - if you want to do it properly, it's going to be a lot of work, and without ToS function sources it might actually not be possible that it's never going to be replicated accurately.

-Ben

Reply With Quote
 
  #7 (permalink)
Houston+TX/USA
 
Trading Experience: Intermediate
Platform: TradeStation, ThinkorSwim
Favorite Futures: ES, CL
 
mntman's Avatar
 
Posts: 4 since Jan 2019
Thanks: 1 given, 0 received

i was able to figure it out on my own... apparently tradestation's ATR is defaulted for the simple avg. so to find the wilders smoothed avg (to match TOS) i had to replace my EL ATR definition with this below:

 
Code
//original using simple avg
atr = AvgTrueRange(length);


//corrected using wilders avg
If currentBar <= length then
	Value1 = Summation(TrueRange, CurrentBar) / CurrentBar
Else
	Value1 = ((Value1 * (length - 1)) + TrueRange) / length;

atr = Value1;
now my tradestation matches with the tos finally:

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Reply With Quote
 
  #8 (permalink)
Miami, USA
 
Trading Experience: Advanced
Platform: MultiCharts
Favorite Futures: Forex
 
Posts: 11 since May 2017
Thanks: 1 given, 7 received

Ha! Good job!


mntman View Post
i was able to figure it out on my own... apparently tradestation's ATR is defaulted for the simple avg. so to find the wilders smoothed avg (to match TOS) i had to replace my EL ATR definition with this below:

 
Code
//original using simple avg
atr = AvgTrueRange(length);


//corrected using wilders avg
If currentBar <= length then
	Value1 = Summation(TrueRange, CurrentBar) / CurrentBar
Else
	Value1 = ((Value1 * (length - 1)) + TrueRange) / length;

atr = Value1;
now my tradestation matches with the tos finally:

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Reply With Quote

Reply



futures io > > > > > EL help: ATR conversion

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

futures io is celebrating 10-years w/ over $18,000 in prizes!

Right now
 

Thanks for everything -- $250 in Amazon Gift Cards ready to give away

Right now
 

Journal in July -- over $2,500 in prizes w/NinjaTrader

July
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Market Profile Type Indicator Presented as a Heat Map - Need Help with conversion. boreland NinjaTrader Programming 2 October 5th, 2018 01:20 AM
Prog. for SPY Atr vs. Atr of all stocks in tradestation Inventor TradeStation 2 November 27th, 2014 10:24 AM
TTM Squeeze Conversion to Ninja help? hector24 NinjaTrader 23 February 14th, 2014 09:33 AM
Help with Indicator Conversion mk77ch NinjaTrader Programming 3 April 26th, 2013 05:33 PM
Coding Help for Indicator Conversion syxforex NinjaTrader 5 May 15th, 2010 11:23 AM


Tags
atr, average, backtest, backtesting, buy, cl, code, easylanguage, el, feedback, hilo, indicator, indicators, loss, ma, multicharts, neoticker, people, short, strategies, strategy, switch, think or swim, thinkorswim, tos, tos script, tradestation, trend, trend following

All times are GMT -4. The time now is 03:58 PM. (this page content is cached, log in for real-time version)

Copyright © 2019 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432 WhatsApp Business, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts