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
1 registered members (AndrewAMD), 642 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Indicators oddities and maybe some bugs #468060
09/15/17 08:51
09/15/17 08:51
Joined: Aug 2017
Posts: 40
J
johnnyp Offline OP
Newbie
johnnyp  Offline OP
Newbie
J

Joined: Aug 2017
Posts: 40
I have been porting various indicators to MetaTrader 4.

Question: indicators.c has the following line in many places SETSERIES(Data,Period); what does it do?

Here are some curiosities that I have found during my testing on EURUSD 1 minute bars. For reference, I include my test script below.

Most of this is moot because I should respect a lookback period before using the indicators for actual trading.

ATR(7) returns some garbage value on Bar 0.
ATR(7) returns 0.00014 for the next 40 or so bars, even though TrueRange() varies from bar to bar. After that ATR works as expected. This only happens when I set StartDate to a year. If I set StartDate to 20170101 then Zorro will start a few bars before the end of 2016 and the ATR values vary from the first bar on, whereas if I set StartDate to 2017 then Zorro will start at the first bar of 2017 and the ATR values stay fixed for ~48 bars. Weird.

I also tried ATR(150) which stays stuck on 0.00016 for ~200 bars.

If the test starts at first bar of a history file, then the first two bars in the history file seem to be ignored. If you do vars Close = series(priceClose()); then the first non-zero value that appears in Close is the close of the third bar in the history file.

On Bar 0, Close[0] is 0, but SMA(Close, 10), ATR(7) and TrueRange() all return the same garbage value. This value changes if you close and reopen Zorro, then rerun the script. It doesn't seem to affect the subsequent values at all.

After running BBands(Close, 10, 2, 2, MAType_SMA); rRealUpperBand and rRealLowerBand are often set to the same value as rRealMiddleBand. This happens throughout the dataset. I suspect the implementation of BBands is buggy, especially for short periods. However this implementation seems to have good predictive power, so I'd like to find out how to imitate the bugs properly.

Code:
// Click [Test] for exporting price data to a .csv file in the Data folder

char filename[1000];
int period = 50; //lookback for calculating normalized/standardized values
char line[5000];
char header[5000];

function add(string column_header, var value)
{
	if(is(INITRUN)) strcat(header, strf(",%s",column_header));
	strcat(line, strf(",%.5f", 
		value
		));
}

function add(string column_header, vars data)
{
	add(column_header, data[0]);
}

function record()
{	
	if(is(INITRUN)) sprintf(header, "YYYY.MM.DD HH:MM");
	sprintf(line,"%02i.%02i.%02i %02i:%02i", year(),month(),day(),hour(),minute());
	
	vars Close = series(priceClose());
	
	add("bar", Bar);
	add("close", Close[0]);
	add("close20", Close[20]);
	add("sma10", SMA(Close, 10));
	add("tr", TrueRange());
	add("atr7", ATR(7));
	add("atr150", ATR(150));
	
	
	BBands(Close, 10, 2, 2, MAType_SMA);
	add("BBandsL", rRealLowerBand);
	add("BBandsM", rRealMiddleBand);
	add("BBandsU", rRealUpperBand);
	add("BBandsDist", rRealUpperBand-rRealLowerBand);
	add("4xStdDev", 4.*sqrt(Moment(Close, 10, 2)));
	
	
	if(is(INITRUN)) {
	   file_delete(filename);
		strcat(header,"n");
		file_append(filename, header);
		printf("nWriting header: %s", header);
	}
	strcat(line,"n");
	file_append(filename,line);
}

function run(){
	BarPeriod = 1;
	StartDate = 2017;
	EndDate = 20170104;
	LookBack = 1000;
	
	if(is(INITRUN))
	{
		sprintf(filename, "Data\Test.csv");
		printf("nWriting to %s", filename);
	}
	
	record();
}


Re: Indicators oddities and maybe some bugs [Re: johnnyp] #468095
09/18/17 11:11
09/18/17 11:11
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
SETSERIES is a macro for testing purposes and can be ignored. I don't know how TA-LIB indicators behave when the prices are zero - that probably depends on the indicator. But I do not think that they return anything useful in that case.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1