Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (7th_zorro), 793 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
NumOpenLong / NumOpenShort working for phantom? #437725
02/24/14 16:25
02/24/14 16:25
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
I'm checking for changes in NumOpenLong and NumOpenShort, and it seems that they are not changing with phantom-trade changes.

Is it possible that this is a glitch? I do see them changing for real trades, just not for phantom.

Thanks

Re: NumOpenLong / NumOpenShort working for phantom? [Re: dusktrader] #437728
02/24/14 17:09
02/24/14 17:09
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
Actually now I'm not sure... I just watched both a live trade and phantom trade not trigger my logic here. Prior to using NumOpenLong+NumOpenShort I was using NumOpenTotal and the same logic was working for real trades. I wanted to expand that to work also for phantom trades.

Can you spot any reason why the else if section would not be triggering:
Code:
function continueStats(string filename)
{
	if(!is(TRADEMODE)) return; //only load/save state info when live trading	
	static int numOpenLastCheck; //track changes in trade open/closes
	char path[100]; //full path to parameter .ini file

	if(is(INITRUN)) //load previously saved trade stats (if any) upon Zorro start
	{
		numOpenLastCheck=0;
		char param[30]; //asset-labeled parameter .ini file
		char fcontent[2500]; //file content from parameter .ini file
		sprintf(path,"Strategy\\%s",filename);
		if(!file_date(path)) msg("#>>WARNING<< no stats file found!\nThis is normal if this is the very first run of a new strategy");
		string fcontent = file_content(path);
		
		//load from disk current state info for each asset
		ASSETLOOP
		{
			sprintf(param,"%s_NumWinLong",Asset);
			NumWinLong = strvar(fcontent,param);
	
			sprintf(param,"%s_NumWinShort",Asset);
			NumWinShort = strvar(fcontent,param);	
	
			sprintf(param,"%s_NumLossLong",Asset);
			NumLossLong = strvar(fcontent,param);

			sprintf(param,"%s_NumLossShort",Asset);
			NumLossShort = strvar(fcontent,param);
		
			sprintf(param,"%s_WinLong",Asset);
			WinLong = strvar(fcontent,param);

			sprintf(param,"%s_WinShort",Asset);
			WinShort = strvar(fcontent,param);

			sprintf(param,"%s_LossLong",Asset);
			LossLong = strvar(fcontent,param);

			sprintf(param,"%s_LossShort",Asset);
			LossShort = strvar(fcontent,param);
		}
		printf("\nRead trade stats from disk");
	}

	else if((NumOpenLong+NumOpenShort) != numOpenLastCheck) //save stats to disk upon trade count changes
	{
		FILE *out;
		char line[2500], tmp[2500]; //line of data for .ini file
		sprintf(path,"Strategy\\%s",filename);

		if (!(out = fopen(path, "w")))
		{
			printf("\nERROR trying to open file for write:\n%s\n",path);
			return;
		}

		//store to disk current state info for each asset
		ASSETLOOP
		{
			sprintf(line,"%s_NumWinLong = %i\n",Asset,NumWinLong);
			sprintf(tmp,"%s_NumWinShort = %i\n",Asset,NumWinShort);
			strcat(line,tmp);
			sprintf(tmp,"%s_NumLossLong = %i\n",Asset,NumLossLong);
			strcat(line,tmp);
			sprintf(tmp,"%s_NumLossShort = %i\n",Asset,NumLossShort);
			strcat(line,tmp);
			sprintf(tmp,"%s_WinLong = %f\n",Asset,WinLong);
			strcat(line,tmp);
			sprintf(tmp,"%s_WinShort = %f\n",Asset,WinShort);
			strcat(line,tmp);
			sprintf(tmp,"%s_LossLong = %f\n",Asset,LossLong);
			strcat(line,tmp);
			sprintf(tmp,"%s_LossShort = %f\n",Asset,LossShort);
			strcat(line,tmp);
		
			if (!fwrite(line, sizeof(char), strlen(line), out))
			{
				printf("\nWRITE ERROR:\n%s\n",path);
				fclose(out);
				return;
			}
			else printf("\nSaved trade stats to disk");
		}

		fclose(out);
		numOpenLastCheck = NumOpenLong+NumOpenShort; //track changes in real and phantom trades
	}
}



PS: is it possible that NumOpenLong+NumOpenShort is a var, whereas NumOpenTotal would be an int?

PPS: just now I observed the logic work correctly. So I think the issue could be that both a trade opened and a trade closed at once, canceling the count. I should check for changes in both Long and Short separately I think. I'll try that next...

Last edited by dusktrader; 02/24/14 19:30.
Re: NumOpenLong / NumOpenShort working for phantom? [Re: dusktrader] #437782
02/26/14 07:13
02/26/14 07:13
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The variables beginning with "Num" are int, as they are used to count something. Variables ending with -Long / -Short include phantom trades, variables ending with -Total do not.

Your script contains a mistake:

numOpenLastCheck = NumOpenLong+NumOpenShort

This is wrong. Correct would be:

numOpenLastCheck = 0; // before the loop
...
numOpenLastCheck += NumOpenLong+NumOpenShort; // inside the loop

and the else-if logic must be likewise corrected.

Re: NumOpenLong / NumOpenShort working for phantom? [Re: jcl] #437868
02/27/14 16:53
02/27/14 16:53
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
There is definitely something weird going on, although I can't quite put my finger on it yet. It very-likely is my fault in bad coding... but it seems that Zorro should not do any of the following:

* return 0 for NumOpenLong, NumOpenShort or NumOpenTotal when any trades are actually open
* return a non-agreeing figure between NumOpenLong/NumOpenShort and NumOpenTotal (for example, NumOpenLong=1 but NumOpenTotal=0)

I'm trying to create a repeatable/simplified example for you to see the issue I'm seeing.

Re: NumOpenLong / NumOpenShort working for phantom? [Re: dusktrader] #437871
02/27/14 18:54
02/27/14 18:54
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Hi dusktrader. Please see jcl's reply above. Phantom trades are in Long & Short, but not Total. FWIW, I agree that Long, Short, & Total should all be consistent and either all include or all exclude Phantoms - there should be other variables that do the reverse (exclude/include Phantoms)...

(This bit me once before also... Unless you're seeing a different problem?)

Re: NumOpenLong / NumOpenShort working for phantom? [Re: DdlV] #437872
02/27/14 19:23
02/27/14 19:23
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
Oh yes, I knew that about phantom trades but I had forgotten in trying to track down this issue.

There is definitely some issue, but perhaps then only the first bullet point above: returning 0 for NumOpenLong, NumOpenShort, NumOpenTotal when in fact there are live trades open.

I'm having trouble assembling a simplified example to demonstrate the problem, but I'm sure I'll get one soon. (Either that, or I'll figure out what I'm doing wrong to cause the issue!!)


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1