Gamestudio Links
Zorro Links
Newest Posts
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
Data from CSV not parsed correctly
by jcl. 04/20/24 08:32
Zorro FIX plugin - Experimental
by jcl. 04/20/24 08:30
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (7th_zorro, Aku_Aku, 1 invisible), 579 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
This is my fault-tolerant ATR indicator for you #477095
05/16/19 12:20
05/16/19 12:20
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
Why you need it: Price Data can sometimes be crappy, like price not being updated for days (like the Dukascopy Forex Dataset). This will cause the normal ATR indicator to trend towards Zero or even reach Zero - really bad if you divide by ATR!

So my fault-tolerant ATR works like this: If the newest price bar is completely flat (High = Open = Close = Low), it's probably fake/missing data and will be ignored. This is the case when TrueRange is Zero. The ATR value will only update again if new price data arrives.


Code:
function ftATR(ATRPeriod)
{
 vars tr = series(0, -ATRPeriod); // create a static series
 if(TrueRange() != 0)
 {
 shift(tr, TrueRange(), ATRPeriod);
 }
 if(tr[ATRPeriod-1] == 0)
 { 
  ATRPeriod = 1;
  while(tr[ATRPeriod] != 0) ATRPeriod++;
 }
	
 var myATR = Sum(tr, ATRPeriod) / ATRPeriod;

 return(myATR);
}



usage:

(put the function code before the run function)

Code:
ftATR(int TimePeriod): var



example:

Code:
var my_atr = ftATR(30);


Re: This is my fault-tolerant ATR indicator for you [Re: Smon] #477118
05/18/19 14:35
05/18/19 14:35
Joined: Aug 2018
Posts: 98
O
OptimusPrime Offline
Junior Member
OptimusPrime  Offline
Junior Member
O

Joined: Aug 2018
Posts: 98
Thank you!


Thanks so much,

OptimusPrime

Re: This is my fault-tolerant ATR indicator for you [Re: OptimusPrime] #477164
05/26/19 12:54
05/26/19 12:54
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
I just found an error that wasn't detected by the compiler. I mixed some R syntax in. It's

Code:
var ftATR(int ATRPeriod)



not

Code:
function ftATR(ATRPeriod)


Re: This is my fault-tolerant ATR indicator for you [Re: Smon] #482019
12/06/20 19:50
12/06/20 19:50
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
And now without internal series (internal series just suck):

Code
var ftATR2(int ATRPeriod)
{
	var* tr = zalloc(ATRPeriod*sizeof(var));
	int i = 0;
	int ElementIDX = 0;
	var MyTrueRange;
	
	while(ElementIDX < ATRPeriod)
	{
		MyTrueRange = max(priceHigh(0+i),priceClose(1+i))-min(priceLow(0+i),priceClose(1+i));
		if (MyTrueRange != 0)
		{
			tr[ElementIDX] = MyTrueRange;
			ElementIDX++;
		}
		i++;
		if(i > 10*ATRPeriod) break;
	}
	
	var myATR = Sum(tr, ElementIDX) / ElementIDX;
	if(!Init && !is(LOOKBACK) && myATR == 0) printf("\nftATR is zero! This shouldn't happen!");
	return(myATR);
}

Last edited by Smon; 12/06/20 19:51.

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1