// Downloaded From https://www.WiseStockTrader.com
//get the max price in any day
function getMaxPriceDuration(Value,NumberOfDay){
	pr = HHV(Ref(Value,-1),NumberOfDay);
	return pr;
};

//get the min price in any day
function getMinPriceDuration(Value,NumberOfDay){
	pr = LLV(Ref(Value,-1),NumberOfDay);
	return pr;
};

//calculate band of price
function calBandPrice(percent,period){
	priceMax = getMaxPriceDuration(C,period);
	priceMin = getMinPriceDuration(C,period);
	return priceMax < percent * priceMin; 
};

function ConditionCrossTwoMA(price,top,bottom){
	return Cross(MA(price,top),MA(price,bottom));
}

function ConditionPriceIsAboveMA(price,period){
	return price > MA(price,period);
}

function ConditionMACDAboveSign(){
	return MACD(12,26)>Signal(12,26,9) AND (MACD(12,26)>Ref(MACD(12,26),-1));
}

//function ConditionBBandExtend(){
	//return (BBandTop(C,15,2)>BBandTop(Ref(C,-1),15,2)) AND BBandBot(C,15,2)<BBandBot(Ref(C,-1),15,2);
//}

function CalBollingerBanWidth(period){
	MAveger = MA(C,period);
	BBtop = BBandTop(C,period,2);
	BBbottom = BBandBot(C,period,2);
	BBWidth = ((BBtop - BBbottom)/MAveger)*100;
	return BBWidth;
}

function CalBollingerB(period){
	MAveger = MA(C,period);
	BBtop = BBandTop(C,period,2);
	BBbottom = BBandBot(C,period,2);
	PercentB = (C-BBbottom)/(BBtop - BBbottom);
	return PercentB;
}

function ConditionADX(Limit){
	return ADX(14)> Limit;
}

function isOverBought(Limit){
	return RSI(14)>70;
}

function isOverSold(Limit){
	return RSI(14)<20;
}

function isUpperTrend(){
	return (PDI(14) > MDI(14)) 
	//AND (PDI(14)>Ref(PDI(14),-1))
	;
}

function isLowerTrend(){
	return (PDI(14) < MDI(14)) 
	//AND (PDI(14)< Ref(PDI(14),-1))
	;
}
function isSuddenVolume(scale,Vol){
	return V >= scale*Ref(V,-1) 
	AND V>Vol
	;
}

//find volume is bigger then a number
function isVolBiggerThan(number){
	return V >=number
	;
}

function isMoneyFlowBig(index){
	return MFI(14) > index;
}

//find the volume is bigger than anyday
function isVolBiggerThanSomeDay(somedays){
	return V>Sum(Ref(V,-1),somedays);
}