Gamestudio Links
Zorro Links
Newest Posts
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 (AndrewAMD), 1,213 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Using a TMF to enter and exit at seconds and getting seconds==0 #447312
12/04/14 04:22
12/04/14 04:22
Joined: Nov 2013
Posts: 123
Mithrandir77 Offline OP
Member
Mithrandir77  Offline OP
Member

Joined: Nov 2013
Posts: 123
I made the following code by modifying workshop 4 so that it enters a trade after it receives confirmation that the trend is continuing, the problem is that inside the TMF tradeAtSeconds() I do printf("%d",seconds()) and it always prints 0 , if the barperiod is 1 shouldn't it be printing different seconds corresponding to the ocurrences of ticks inside 1 minute bars? Thanks for your help!

Code:
// Workshop 4: Trend Trading ///////////////////
#include <profile.c>

#define initialPrice TradeVar[0]
#define seconds TradeVar[1]

int tradeAtSeconds()
{
	seconds = second();
	printf("\nseg: %d\n",seconds);
	if (seconds > 50){	
	   printf("\nTrade %d exited cuz out of time at: %d/%d/%d %d:%d:%d\n",TradeID,day(),month(),year(),hour(),minute(),second());
		return 1;
	}
	if (TradeIsLong){		
		if (TradeIsNewBar)//first tick of a new 60 seconds-bar, I set the Entry Limit to 12 pips above initialPrice		
			TradeEntryLimit = initialPrice + 12 * PIP;			
		else
			if (!TradeIsOpen)
				if (TradePriceOpen >= TradeEntryLimit){
					printf("\nLong %d entered at: %d/%d/%d %d:%d:%d\n",TradeID,day(),month(),year(),hour(),minute(),second());			
					return 2+4;}
			else
				if (TradeProfit/TradeUnits/PIP >= 27){//close the trade at this very second
					printf("\nLong %d exited at: %d/%d/%d %d:%d:%d\n",TradeID,day(),month(),year(),hour(),minute(),second());
					return 1;
				}								
	}
	else{
		if (TradeIsNewBar)//first tick of a new 60 seconds-bar, I set the Entry Limit to 12 pips below initialPrice
			TradeEntryLimit = initialPrice - 12 * PIP;			
		else
			if (!TradeIsOpen)
				if (TradePriceOpen <= TradeEntryLimit){
					printf("\nShort %d entered at: %d/%d/%d %d:%d:%d\n",TradeID,day(),month(),year(),hour(),minute(),second());		
					return 2+4;}
			else
				if (TradeProfit/TradeUnits/PIP >= 27){//close the trade at this very second
					printf("\nShort %d exited at: %d/%d/%d %d:%d:%d\n",TradeID,day(),month(),year(),hour(),minute(),second());
					return 1;
				}	
	}
	return 4;
}

function run()
{
	BarPeriod = 1;
	set(TICKS);
	StartDate = 20140606;
	EndDate = 20140624;
	vars Price = series(price());
	vars Trend = series(LowPass(Price,500));
	
	Stop = 4*ATR(100);
	initialPrice = priceClose();
	seconds = 0;
	if(valley(Trend))
		enterLong(tradeAtSeconds());
	else if(peak(Trend))
		enterShort(tradeAtSeconds());

 //zoom in a certain date
//	PlotDate = 20140606;
//	PlotBars = 300;
//	ColorEquity = ColorDD = 0;
//	ColorUp = ColorDn = 0x00AAAAAA;
//	plot("Trend",Trend[0],0,BLACK);
//	set(PLOTNOW);
	

	PlotWidth = 800;
	PlotHeight1 = 300;
//	ColorWin = ColorLoss = 0;
//	plotTradeProfile(-50); // plot the trade profit distribution
	set(LOGFILE); // log all trades
}


Last edited by Mithrandir77; 12/04/14 04:23.
Re: Using a TMF to enter and exit at seconds and getting seconds==0 [Re: Mithrandir77] #447315
12/04/14 08:48
12/04/14 08:48
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
I don't know if this is the reason, but you're not printing "seconds" correctly. TradeVar is a var, not an int, so you must print it with %f, not %d.

Re: Using a TMF to enter and exit at seconds and getting seconds==0 [Re: jcl] #447324
12/04/14 15:53
12/04/14 15:53
Joined: Nov 2013
Posts: 123
Mithrandir77 Offline OP
Member
Mithrandir77  Offline OP
Member

Joined: Nov 2013
Posts: 123
Originally Posted By: jcl
I don't know if this is the reason, but you're not printing "seconds" correctly. TradeVar is a var, not an int, so you must print it with %f, not %d.


Thanks for your response jcl. Indeed I changed the printf, now it is

seconds = second();
printf("\nseg: %f\n",seconds);

but it prints "seg: 0.000000" moreover look at what it prints when i invoke

printf("\nLong %d entered at: %d/%d/%d %d:%d:%d\n",TradeID,day(),month(),year(),hour(),minute(),second());

second() returns an int but it is always returning 0 so I think the problem is that second is bugged or the tmf is not being called every tick. Is the code of second() available to check?


Re: Using a TMF to enter and exit at seconds and getting seconds==0 [Re: Mithrandir77] #447326
12/04/14 16:12
12/04/14 16:12
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Did you trade your script at all? Or was it only a test?

The included files contain M1 data, that's minutes, no seconds. There are no tick data included.

Re: Using a TMF to enter and exit at seconds and getting seconds==0 [Re: jcl] #447334
12/04/14 19:35
12/04/14 19:35
Joined: Nov 2013
Posts: 123
Mithrandir77 Offline OP
Member
Mithrandir77  Offline OP
Member

Joined: Nov 2013
Posts: 123
Originally Posted By: jcl
Did you trade your script at all? Or was it only a test?

The included files contain M1 data, that's minutes, no seconds. There are no tick data included.


Oh, my bad you are right. I was testing. So I would have to try with histdata tick data. But the file from histadata comes in the format yyyyMMdd hhmmmiliseconds bid ask (volume?):

20141102 170007143 1.25058 1.25098 0
20141102 170008393 1.25057 1.25097 0
20141102 170018143 1.2506 1.251 0

so should I use the average of bid and ask for the open,high,low and close of the tick struct?

Re: Using a TMF to enter and exit at seconds and getting seconds==0 [Re: Mithrandir77] #447338
12/05/14 09:00
12/05/14 09:00
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
No, use the ask price only. Zorro generally uses the ask price for all its calculations. - Using tick data for backtests is tricky due to the high data amount that will quickly exceed the memory on your PC. That's why a special data structure, with a cache, is normally required for this and is also on our list for future Zorro features.

Re: Using a TMF to enter and exit at seconds and getting seconds==0 [Re: jcl] #447344
12/05/14 13:51
12/05/14 13:51
Joined: Nov 2013
Posts: 123
Mithrandir77 Offline OP
Member
Mithrandir77  Offline OP
Member

Joined: Nov 2013
Posts: 123
Originally Posted By: jcl
No, use the ask price only. Zorro generally uses the ask price for all its calculations. - Using tick data for backtests is tricky due to the high data amount that will quickly exceed the memory on your PC. That's why a special data structure, with a cache, is normally required for this and is also on our list for future Zorro features.


Ok, thanks for the clarification. One more question, according to http://zorro-trader.com/manual/en/bar.htm

Quote:
Zorro's trading is normally based on bar periods. The strategy script is run at the end of every bar, and buy or sell commands are executed at the price of the begin of the next bar. By extending the candle time frame so that it covers several bars, trades can be placed in the middle of a candle. The bar period plays no role in trade mangement functions that evaluate entry or exit conditions and run on any tick. A tick is the arrival of a new asset price quote, which can happen several times per second. A bar period contains many, many ticks.


and

http://zorro-trader.com/manual/en/trade.htm

Quote:
TMF return values:
0 - check the trade's Entry, Stop, TakeProfit, and Trail parameters, and exit or enter accordingly.
1 - if the trade is still open or pending, exit it now.
2 - if the trade is still pending, enter it now.


So according to this, If a tmf returns 2, Zorro enters immediately (at a precision of a second at least). Is this right? Or does Zorro always enter trades at the begin of the next bar? Thanks!

Re: Using a TMF to enter and exit at seconds and getting seconds==0 [Re: Mithrandir77] #447392
12/09/14 09:19
12/09/14 09:19
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Yes, it enters immediately. TMFs run at any tick, not only at the end of a bar.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1