Highest value

Posted By: Anonymous

Highest value - 02/02/14 09:27

Are there math functions in zorro that returns the highest or minimum values in a series of values?
Posted By: DdlV

Re: Highest value - 02/02/14 16:51

You mean like MaxVal and MinVal? They're on the Signal Processing page in the manual...
Posted By: Anonymous

Re: Highest value - 02/02/14 19:18

Ok so this is what I am trying to do.
Code:
function run()
{
//	set(PARAMETERS);
	BarPeriod = 240; // 4 Hour bars
	StartDate = 2009;
//	EndDate =  2012;
	LookBack = 2880;
	Hedge = 0;
	
	//First Pig
	vars Price = series(price());
	vars SMAW = series(SMA(Price,1650)); // Weekly Trend (SMA 55)
	
	//Second Pig
	vars SMAD = series(SMA(Price,126));  // Daily Trend (SMA 21)
	
	//Third Duck
	vars SMA4H = series(SMA(Price,34));  // 4 Hour Trend (SMA 34)
	
	vars StopCal = series(ATR(14),14);
	var HighATR = MaxVal(StopCal,0);
	var LowATR =	MinVal(StopCal,0);
				
	Stop = ((HighATR-LowATR)*.25)+((abs(SMA4H[0]-Price[0]))*PIP);
	Trail = ((HighATR-LowATR)*.25)+((abs(SMA4H[0]-Price[0]))*PIP);
	
	
	if(Price[0]>SMAW[0] && Price[0]>SMAD[0] && Price[0]>SMA4H[0]){
		enterLong();
	} 
	else if(Price[0]<SMAW[0] && Price[0]<SMAD[0] && Price[0]<SMA4H[0]){
		enterShort();
	}
}



So any ideas on how I can get the stop to work?
The original strategy can be found here. Here
Posted By: DdlV

Re: Highest value - 02/03/14 07:10

Well, I've never tried TimePeriod=0 in MaxVal or MinVal, and don't see that there's any default in the manual. With TimePeriod=0, won't HighATR and LowATR always be 0? Have you tried any debug printf's to see what's going on?

Do you want the Max and Min over the 14? So it should be HighATR=MaxVal(StopCal,14) and similarly for LowATR?
Posted By: Anonymous

Re: Highest value - 02/03/14 12:03

I wanted to get the max and min of the 14 values in the StopCal series.
Posted By: Jeff_Raven

Re: Highest value - 02/03/14 18:10

As DdIV said,

Code:
HighATR=MaxVal(StopCal,14);
LowATR=MinVal(StopCal,14);



will give you what you want. I just tried it with another indicator I was working on and it works fine.

And thanks for asking the question, liftoff, and also thanks to you DdIV for answering. I was looking for this exact function over the weekend and couldn't find it. laugh
Posted By: swingtraderkk

Re: Highest value - 02/03/14 18:18

Code:
vars StopCal = series(ATR(14));
var HighATR = MaxVal(StopCal,14);
var LowATR =	MinVal(StopCal,14);



but why add .25 of the difference between high and low atr values to the gap between price and sma:

(HighATR-LowATR)*.25

Not sure what this adds to your stop & trail, it's likely to be a very small % of ATR.
Posted By: Anonymous

Re: Highest value - 02/03/14 20:56

thanks...was just working on idea from a forum. thanks for the input
© 2024 lite-C Forums