Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
Scripts not found
by juergen_wue. 04/20/24 18:51
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
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, howardR), 452 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 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