Gamestudio Links
Zorro Links
Newest Posts
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
Release 2.68 replacement of the .par format
by Martin_HH. 09/23/25 20:48
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 17,605 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 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: 101
O
OptimusPrime Offline
Member
OptimusPrime  Offline
Member
O

Joined: Aug 2018
Posts: 101
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 | 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