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.