Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (Nymphodora, AndrewAMD, TipmyPip, Quad, Imhotep), 847 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 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: 204
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 204
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: 204
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 204
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: 204
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 204
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