Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
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
0 registered members (), 716 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
combining workshop 5+7 #431903
10/25/13 19:34
10/25/13 19:34
Joined: May 2013
Posts: 627
Bonn
Sundance Offline OP
User
Sundance  Offline OP
User

Joined: May 2013
Posts: 627
Bonn
Hi,

i just wrote a script which combines a higher timeframe advice function with a lower timeframe valley/peak LowPass trend filter.

Code:
// 2Step Pattern Pelley ////////////////////////////
//
//	V: 0.1
//	start date: 2013-10-25 
//
// Strategy:
//
//		two steps
//
//		step one:	find the long termed trend using the advise function
// 					with three D1 bars in a row like in WorkShop 7
//
//		step two:	find the short termed trend using the valley/peak
//						function using the LowPass series on H1
//
//
//	taken trades will be managed with a trailing stop los
// SL depends on an ATR calculation



#include <profile.c>

#define H1 (60/BarPeriod)
#define D1 (1440/BarPeriod)

int TrailingStop(); // TMF prototype

function run()
{
	if(is(INITRUN)) {

		StartDate = 2009;
		BarPeriod = 60; // 60 minutes
		TimeFrame = 1; // 1 bar
		Weekend = 1;      // don't merge Friday and Sunday bars
		LookBack = 1000;
		NumWFOCycles = 5;	
		set(RULES+TESTNOW);
		
	}
		
// variable definitions
	
	// set higher timeframe price vars
	TimeFrame = D1;
	vars HTF_priceHigh	= series(priceHigh());
	vars HTF_priceLow		= series(priceLow());
	vars HTF_priceClose	= series(priceClose());
	
	// set short timeframe LowPass series
	TimeFrame = H1;
	vars Price = series(price());
	vars LTF_Trend = series(LowPass(Price,1000));
	
	
	if(Train) {
		Hedge = 2; 			// train long + short		
		TimeFrame	= D1;
		TimeExit		= 1;  // one day
	}
	else {
		Stop 			= 100*PIP;   // set exit limits
		TimeFrame 	= H1;
	}

// get trend on higher timeframe but check it every new bar in
// the lower timeframe (don't if we are in Train-Mode cause TimeFrame is D1)
if(adviseLong(PATTERN+2,0,
		HTF_priceHigh[2],HTF_priceLow[2],HTF_priceClose[2],
		HTF_priceHigh[1],HTF_priceLow[1],HTF_priceClose[1],
		HTF_priceHigh[1],HTF_priceLow[1],HTF_priceClose[1],
		HTF_priceHigh[0],HTF_priceLow[0],HTF_priceClose[0]) > 50) {

	if(Train) {

		enterLong();
		
	}
	else {
		
		// higher timeframe long trend
		// Now look for the lower timeframe trend
		if(valley(LTF_Trend)) {

			// lower timeframe long trend
			// now we enter a trade
				enterLong(TrailingStop);

		}
	}
}
if(adviseShort() > 50) {

	if(Train) {

		enterShort();
		
	}
	else {
		
		// higher timeframe short trend
		// Now look for the lower timeframe trend
		if(peak(LTF_Trend)) {

			// lower timeframe short trend
			// now we enter a trade
				enterShort(TrailingStop);

		}
	}	
}

} // run()

// TMF that adjusts the stop in a special way 
int TrailingStop()
{
// adjust the stop only when the trade is in profit
  if(TradeResult > 0)
  	if(TradeIsLong)
   {  
		// place the stop at the lowest bottom of the previous 3 H1 candles
		 TimeFrame = H1;
	    TradeStopLimit = max(TradeStopLimit,LL(3));
	}
	else if(TradeIsShort)
	{
		// place the stop at the highest top of the previous 3 H1 candles
		 TimeFrame = H1;
	    TradeStopLimit = min(TradeStopLimit,HH(3));	
	}
// plot a line to make the stop limit visible in the chart
     plot("Stop",TradeStopLimit,MINV,BLACK);
// return 0 for checking the limits
     return 0;
}


Last edited by Sundance; 10/26/13 22:39.
Re: combining workshop 5+7 [Re: Sundance] #431911
10/26/13 03:27
10/26/13 03:27
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Hi Sundance. I added LookBack=1000 and the script ran without error. (But it also doesn't enter any trades. laugh )

Using TimeFrame (and in other situations) Zorro can't accurately set LookBack on its own...

HTH.

Re: combining workshop 5+7 [Re: DdlV] #431947
10/26/13 20:39
10/26/13 20:39
Joined: May 2013
Posts: 627
Bonn
Sundance Offline OP
User
Sundance  Offline OP
User

Joined: May 2013
Posts: 627
Bonn
Hi HTH,

ups. The script did ran and I really couldn't remember what I did change to make it giving an error. As I read your post, I knew what it was :-)

Now I must look why there are no profitable patterns.

Thanks for the help HTH!

Re: combining workshop 5+7 [Re: Sundance] #431950
10/26/13 22:27
10/26/13 22:27
Joined: May 2013
Posts: 627
Bonn
Sundance Offline OP
User
Sundance  Offline OP
User

Joined: May 2013
Posts: 627
Bonn
I updated the script in post one. I really don't know why it won't find any profitable pattern. The main part when in training mode is the same as in workshop 7.
I think there must be a problem with the HTF price series in combination with the TimeFrame variable...

Anyone a hint?

PS: Plotting the HTF values confirms that th values are okay...

Last edited by Sundance; 10/27/13 14:08. Reason: Plotting HTF values
Re: combining workshop 5+7 [Re: Sundance] #432006
10/28/13 13:58
10/28/13 13:58
Joined: May 2013
Posts: 627
Bonn
Sundance Offline OP
User
Sundance  Offline OP
User

Joined: May 2013
Posts: 627
Bonn
I changed the TimeExit value to 24 and the TimeFrame value right before to 24. I thought it would be the same as setting TimeFrame to D1 and TimeExit to 1...

Now the script finds profitable patterns...

Re: combining workshop 5+7 [Re: Sundance] #432007
10/28/13 13:58
10/28/13 13:58
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
I see some problems with this approach. At first, your 24-bar frame is not aligned to a trading day, which makes the patterns more random and unpredictive. There's an example on the "BarPeriod" page how to align a time frame to midnight.

Second, you're using an additional valley condition for entering a trade. It is probably rare that a profitable pattern and a valley occur at the same time. When you use pattern detection anyway, you could include the LTF_Trend of the last 3 bars as a separate pattern.

Re: combining workshop 5+7 [Re: jcl] #432008
10/28/13 14:25
10/28/13 14:25
Joined: May 2013
Posts: 627
Bonn
Sundance Offline OP
User
Sundance  Offline OP
User

Joined: May 2013
Posts: 627
Bonn
Thanks for the hint's jcl! Hope to make some progress. Will post if it seems a possible profitable system...


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